Commit graph

20 commits

Author SHA1 Message Date
PiergiorgioZagaria
169b1e2a42
gpu: correct alignment in pointer casts; handle void Context in all callbacks (#233)
* Fixed ErrorCallback.init() alignment
* Fixed callbacks alignments
* Fixed more of the callback alignment problems
* Added checks for void Context in callback
2022-04-18 11:38:09 -07:00
Stephen Gutekanst
79d27b82be gpu: enable void callback contexts
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
9f1775aa7c gpu: correct feature storage location
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
2d04fb91bc gpu: use unnamed tests for inclusion
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
356e4102cd gpu: make requestAdapter callback-based, add waitForAdapter helper
Same rationale as 2c3e13ff4b90886d7f03adb3103abc9dee70b407

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
aab99b5474 gpu: make requestDevice callback-based, add waitForDevice helper
Previously we were attempting to turn WebGPU async functions, which are
exposed by `webgpu.h` as callbacks, into Zig async functions.

This in practice turns out harder than expected. For example, `Buffer.mapAsync`
/ `wgpuBufferMapAsync` cannot easily be exposed as a Zig async function for a few
reasons:

1. The callback is merely guaranteed to be called once the buffer's content is ready to
   be accessed via `wgpuBufferGetMappedRange` - but there is no strict guarantee about
   when that is. It could be 1-3 frames later, in theory, I believe.
2. The non-deterministic timing means that one would wish to poll "has the async function
   returned?" but this isn't trivial without our own scheduler.
3. Zig has a fair amount of async rework in the future that is coming, and I imagine it
   will be one of the later things that is fully supported by the WebAssembly backend
   (but I am speculating) - so it seems wise to punt on this until later.

Instead, we are now retaining async functions as callback-based ones, with a helper in
this case to wait for the callback to be invoked. For `wgpuBufferMapAsync` we will just
have the callback approach.

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
e9c6dcde21 gpu: remove docs TODOs (everything needs docs)
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
fd48c830e1 gpu: rename structs.zig -> data.zig
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
a463a0c7cd gpu: unify data structs in single structs.zig
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
775be75c90 gpu: remove TODO about wgpuAdapterCreateDevice
`wgpuAdapterCreateDevice` is Dawn-specific, and is just a helper for calling the
async method. We don't need it.

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
2c392bbae6 gpu: rename FeatureName -> Feature
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
bb18701609 gpu: centralize FeatureName -> enums.zig
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
39ab0105a9 gpu: improve how limits are represented
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
070126b85d gpu: add TODOs about documentation
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
4bc5411a14 gpu: implement Adapter.requestDevice
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
a1c9fe6897 gpu: implement Adapter.reference, Adapter.release
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
5581584717 gpu: implement Adapter type / backend type -> name conversion
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
f849e03443 gpu: implement Adapter properties
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
3a0b0fd83c gpu: initial pass at requestAdapter
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
414887db2a gpu: add foundation for interface
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00