-
Notifications
You must be signed in to change notification settings - Fork 45
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
Representation of GPUBindGroupEntry #403
Comments
My 2 cents: It would make sense to match the JS API (using |
Nothing really matches JS perfectly since JS has a real union and we have three values in a trenchcoat. Unlike All that said, I would probably pick |
Tentatively closing as I'd like to go with no change, but leaving the label to discuss if we want to reopen. |
Nov 21 meeting:
|
Decided it's easier to separate this out from #438. Mirroring the option numbers there: 0 - Today: struct WGPUBindGroupEntry {
WGPUChainedStruct const * nextInChain;
uint32_t binding;
WGPU_NULLABLE WGPUBuffer buffer;
uint64_t offset;
uint64_t size;
WGPU_NULLABLE WGPUSampler sampler;
WGPU_NULLABLE WGPUTextureView textureView;
};
static const WGPUSType WGPUSType_EmscriptenExternalTextureBinding = 0x00040003;
struct WGPUEmscriptenExternalTextureBinding {
WGPUChainedStruct chain; // WGPUSType_EmscriptenExternalTextureBinding
some_handle_type externalTexture;
}; 1 - Tagged union: // EDIT: Separated this from #438's WGPUBindingType because they're not 1:1.
enum WGPUBindingResourceType {
WGPUBindingResourceType_Buffer = 1,
WGPUBindingResourceType_Sampler = 2,
WGPUBindingResourceType_TextureView = 3,
};
static const WGPUBindingResourceType WGPUBindingResourceType_EmscriptenExternalTexture = 0x00040000;
struct WGPUBindGroupEntry {
WGPUChainedStruct const * nextInChain;
uint32_t binding;
WGPUBindingResourceType type;
union {
struct {
WGPU_NONNULL WGPUBuffer buffer;
uint64_t offset;
uint64_t size;
} buffer;
WGPU_NONNULL WGPUSampler sampler;
WGPU_NONNULL WGPUTextureView textureView;
// Pointer to a new thing, like a WGPUEmscriptenExternalTexture object or a new struct
WGPU_NONNULL void * other;
};
}; 2 - Use struct chaining instead of tags (verbose because we need a chained struct for each one): enum WGPUSType {
// ...
WGPUSType_BindGroupEntryBuffer = ...,
WGPUSType_BindGroupEntrySampler = ...,
WGPUSType_BindGroupEntryTextureView = ...,
};
struct WGPUBindGroupEntry {
WGPUChainedStruct const * nextInChain; // Everything goes in here now.
uint32_t binding;
};
// Each of these is chained in WGPUBindGroupEntry. The presence of one in the
// chain indicates which thing we're binding, so there must be exactly one in the chain.
struct WGPUBindGroupEntryBuffer {
WGPUChainedStruct chain; // WGPUSType_BindGroupEntryBuffer
WGPU_NONNULL WGPUBuffer buffer;
uint64_t offset;
uint64_t size;
};
struct WGPUBindGroupEntrySampler {
WGPUChainedStruct chain; // WGPUSType_BindGroupEntrySampler
WGPU_NONNULL WGPUSampler sampler;
};
struct WGPUBindGroupEntryTextureView {
WGPUChainedStruct chain; // WGPUSType_BindGroupEntryTextureView
WGPU_NONNULL WGPUTextureView textureView;
};
static const WGPUSType WGPUSType_EmscriptenBindGroupEntryExternalTexture = 0x00040004;
struct WGPUEmscriptenBindGroupEntryExternalTexture {
WGPUChainedStruct chain; // WGPUSType_EmscriptenBindGroupEntryExternalTexture
some_handle_type externalTexture;
}; 3 - Using STypes but with a union of pointers: // Same WGPUSType
struct WGPUBindGroupEntry {
WGPUChainedStruct const * nextInChain; // May not be needed
uint32_t binding;
union {
// Using the WGPUBindGroupEntry* definitions from 2. Tagged by SType,
// instead of by an outside tag. It is like a normal chained struct,
// except the first one in the chain must be one of the layout types.
WGPU_NONNULL WGPUBindGroupEntryBuffer * buffer;
WGPU_NONNULL WGPUBindGroupEntrySampler * sampler;
WGPU_NONNULL WGPUBindGroupEntryTextureView * textureView;
// A new thing, such as a WGPUEmscriptenBindGroupEntryExternalTexture
WGPU_NONNULL WGPUChainedStruct * other;
// Alternative: make the core ones all non-pointers; I couldn't figure
// out a non-messy way of making it extensible, though.
};
};
struct WGPUEmscriptenBindGroupEntryExternalTexture {
WGPUChainedStruct chain; // WGPUSType_EmscriptenBindGroupEntryExternalTexture
some_handle_Type externalTexture;
}; 3b - Use RTTI inside the types??? (more "flat" version of 3) struct WGPUBindGroupEntry {
WGPUChainedStruct const * nextInChain;
uint32_t binding;
// Instead of a tag, define that internally these objects are all distinguishable via
// "RTTI" - using an internal sType that lives at the same exact offset as struct
// sTypes (so that .otherStruct can work).
union {
struct {
WGPU_NONNULL WGPUBuffer buffer;
uint64_t offset;
uint64_t size;
} buffer;
WGPU_NONNULL WGPUSampler sampler;
WGPU_NONNULL WGPUTextureView textureView;
WGPU_NONNULL void * otherObject; // may be a WGPUEmscriptenExternalTexture
WGPU_NONNULL WGPUChainedStruct * otherStruct; // (not used yet)
};
}; |
Dec 7 meeting:
|
In
WGPUBindGroupEntry
theoffset
andsize
fields are supposed to apply only if the binding is abuffer
, but that's not really clear. We could:bufferBindingOffset
andbufferBindingSize
WGPUBufferBinding
like in JSNot sure it's actually worth the effort to change.
The text was updated successfully, but these errors were encountered: