Commit graph

46 commits

Author SHA1 Message Date
Stephen Gutekanst
6357f3a767 gpu: update example shader @stage(vertex) -> @vertex
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-08-12 00:43:43 -07:00
Stephen Gutekanst
d32c019b59 gpu: make Queue.submit API use a slice helper
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-08-12 00:43:43 -07:00
Stephen Gutekanst
f856fccb76 gpu: examples: use latest friendlier APIs
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-08-12 00:43:43 -07:00
Stephen Gutekanst
9568bff8ab gpu: update example to latest mach/gpu API
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-08-12 00:43:43 -07:00
Stephen Gutekanst
8b7d810450 gpu: correct header includes
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-08-12 00:43:43 -07:00
Stephen Gutekanst
58664afbd6 gpu/examples: zig fmt
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-04-20 23:01:52 -07:00
Stephen Gutekanst
eac7efa5d1 gpu: fix regression in example causing it not to compile
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-04-08 16:58:27 -07:00
Silver
47cd84f8ff gpu: use packed structs to wrap WebGPU's bitfield enums 2022-04-08 11:03:00 -07:00
Stephen Gutekanst
fbbb0b0ae0 gpu: use Dawn adapter creation API for now so that GPU_BACKEND selection works
`webgpu.h` does not expose a method of choosing the GPU backend (vulkan, opengl, opengles, etc.)
at present. The only way to achieve this is to use Dawn's C++ API, which we expose as C shims
under the `machDawnNative*` prefix.

For now, we will use the Dawn adapter creation API so that we can choose between Vulkan/OpenGL/OpenGLES
etc via the `GPU_BACKEND` env var.

In the future, I believe we can do something nicer here. For example, perhaps we extend our `requestAdapter`
method (after all, we do not need to strictly match `webgpu.h`) to take such an option and be Dawn-aware so
that it handles this more seamlessly behind the scenes.

Fixes https://github.com/hexops/mach/issues/192#issuecomment-1080895255

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-31 16:57:30 +00:00
Andrew Gutekanst
8072839973 gpu: update GetModuleHandleW usage in examples 2022-03-19 18:01:41 -07:00
Stephen Gutekanst
689f2b5122 gpu: example: change window title to "mach/gpu window"
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
fa9b5f1d5d gpu: example: reenable uncaptured error handling
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
1c5c23f101 gpu: fix Queue.submit commands parameter
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
e26a2858ed gpu: example: use CommandEncoder.finish
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
071100a61e gpu: example: use RenderPassEncoder.end
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
3e17d04195 gpu: example: use RenderPassEncoder.draw
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
e6fe33d66d gpu: example: use RenderPassEncoder.setPipeline
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
6385981d55 gpu: example: use CommandEncoder.beginRenderPass
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
12462d42aa gpu: example: use Device.createCommandEncoder
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
117ad5dc3b gpu: example: use SwapChain .getCurrentTextureView, .present, .release
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
1315c6eb53 gpu: example: use SwapChain.configure
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
cc40004a5f gpu: example: use Device.createRenderPipeline
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
956681afbd gpu: example: use gpu.BlendState
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
400833c8c6 gpu: successfully remove c.WGPUInstance from example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
d8c48bdad1 gpu: cleanup example TODOs
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
6c7ea283fe gpu: utilize gpu.Adapter.BackendType in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
40f92dd9d9 gpu: use PowerPreference
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
2e68792f0d gpu: move TextureFormat -> Texture.Format
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
c3cfb77ac7 gpu: correct enums to snake_case
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
0017303cde gpu: use SwapChain.configure in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
f05fdf4414 gpu: use gpu.TextureFormat in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
46e5592165 gpu: use nativeCreateSwapChain in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
53435cd134 gpu: use ShaderModule.release in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
19277b7282 gpu: use Device.createShaderModule in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
99744134f8 gpu: rename Surface.Descriptor.xlib_window -> xlib
To appropriately match the upstream, webgpu.h, which has renamed in this way.

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
6e175ba0f3 gpu: use Queue.submit in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
ad6cfbb0c9 gpu: use Device.getQueue in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
818a2a172c gpu: use requestDevice in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
77b16a3671 gpu: print adapter information in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
c7c8764129 gpu: use requestAdapter in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
9956ff1864 gpu: example: store gpu.Surface
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
9916ec043b gpu: use Surface API in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
8f5e9f89e5 gpu: expose API and begin using in example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00
Stephen Gutekanst
718a66497c gpu: add gpu-hello-triangle (dawn) example
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-19 00:51:48 -07:00