Commit graph

92 commits

Author SHA1 Message Date
Raph Levien 2ebdd942cf Use bytemuck
Get rid of `PlainData` trait and use `Pod` from bytemuck instead.
2021-11-23 08:24:16 -08:00
Raph Levien 0762cc763c Implement clear_buffers on Metal
Since clearing functionality is not built-in, use a compute shader.

Simplify tests greatly; they don't need the workaround.
2021-11-20 22:24:52 -08:00
Raph Levien 657f219ce8 Better DX12 descriptor management
Reduce allocation of descriptor heaps. This change also enables clearing
of buffers, as the handles are needed at command dispatch time.

Also updates the tests to use clear_buffers on DX12. Looking forward to
being able to get rid of the compute shader workaround on Metal.

This is a followup on #125, and progress toward #95
2021-11-20 16:36:43 -08:00
Raph Levien 3f1bbe4af1 Commit DXIL to repo
We're following the policy of committing all translated shaders to the
git repo rather than rebuilding at runtime. Here are the new DXIL ones.
2021-11-11 13:05:22 -08:00
Raph Levien f9d0aa078b Use DXIL shader compilation
Integrate DXC for translating HLSL for use in DX12. This will work
around FXC limitations and unlock the use of more advanced HLSL features
such as subgroups.

This hardcodes the use of DXIL, but it could be adapted (with a bit of
effort) to choose between DXIL and HLSL at runtime.
2021-11-11 12:55:10 -08:00
Raph Levien 94949a6906 Mac port of bind layout rework
This gets it working on mac. Also delete old implementation.

There's also an update to winit 0.25 in here, because it was easier to
roll forward than fix inconsistent Cargo.lock. At some point, we should
systematically update all deps.
2021-11-10 13:40:16 -08:00
Raph Levien 74f2b4fd1c Rework bind layout
Use an array of bindtypes rather than the previous situation, which was
a choice of buffer counts, or a heavier builder pattern.

The main thing this unlocks is distinguishing between readonly and
read/write buffers, which is important for DX12.

This is WIP, the Metal part hasn't been done, and the old stuff not
deleted.

Part of #125
2021-11-10 11:25:16 -08:00
Raph Levien 19fedf36db
Merge pull request #123 from linebender/tests
Start testing framework, with prefix sum
2021-11-10 11:10:45 -08:00
Raph Levien 0a9dd3a386 Actually turn on memory model 2021-11-07 17:03:11 -08:00
Raph Levien 3820e4b2f4 Add missing file
Also add finish_timestamps call, which is needed for DX12 (there are
other issues but this is an easy fix for that one).
2021-11-06 21:46:01 -07:00
Raph Levien d04ae44618 Upgrade to Ash 0.33
This was motivated by experiments with the Vulkan memory model. To use
that, we actually need to explicitly enable the relevant feature on
device creation time. That's a lot easier to do now that push_next works
on the structs in that chain. This PR doesn't do that though, it only
upgrades the dependency and cleans up deprecations.
2021-11-05 14:01:50 -07:00
Raph Levien c648038967
Merge pull request #117 from linebender/cleanup
Reuse command buffers
2021-10-27 07:23:29 -07:00
Rose Hudson 1bdd2a7c86 Vulkan: account for no limit on image count
when clamping image count within device bounds, some devices can report
max_image_count = 0 to indicate no limit on image count. this triggers
assertion in clamp because max < min.

therefore if the device reports zero we treat it as `u32::MAX`

see https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkSurfaceCapabilitiesKHR.html
2021-10-27 10:45:28 +01:00
Raph Levien 59e850a7b1 Reuse command buffers
Reuse submitted command buffers rather than continually allocating them.

This patch also improves the story across the different backends. On
DX12 it was reusing allocators without resetting them, which could be a
leak. And on Metal the reset "fails," so there's always a new alloc.
2021-10-23 09:21:19 -07:00
Raph Levien b423e6c25d Warning cleanup
This patch gets rid of warnings and runs cargo fmt.

A lot of the warnings were unused items (especially in DX12 land). At
some point we might want to bring some of that back, at which point it
might be useful to refer to what was deleted in this commit.
2021-10-23 09:21:19 -07:00
Raph Levien 7adb300671 Double-buffer scene buffer
Pipeline the CPU and GPU work so that two frames can be in flight at
once.

This dramatically improves the performance especially on Android. Note
that I've also changed the default configuration to be 3 frames in
flight and FIFO mode.
2021-10-21 14:28:27 -07:00
Raph Levien a3d3f39fbd Wait on query results
This shouldn't be necessary, but was causing NOT_READY errors.
2021-10-19 17:26:45 -07:00
Raph Levien f73da22a69 Clean up command buffers
This patch deallocates command buffers after command submission completes (the same time as other resources are released).

It should be portable and robust on all back-ends, but not necessarily the most efficient. But reuse of command buffers, as well as more efficient allocation on Vulkan and DX12, are for followup work.
2021-10-19 17:17:41 -07:00
Raph Levien 056446c23d Cargo fmt 2021-09-06 10:19:55 -07:00
Raph Levien 4b2a720289 Animating scene
Make the scene dependent on timing.

This commit patches the HAL to reuse command buffers; this works well on
Vulkan and prevents a leak, but breaks the other back-ends. That will
require a solution, possibly including plumbing up the resource lifetime
responsibilities to the client.

Other things might be hacky as well.
2021-09-06 10:18:14 -07:00
Raph Levien 05e81acebc Basically get gradients working
Separate out render context upload from renderer creation. Upload ramps
to GPU buffer. Encode gradients to scene description. Fix a number of
bugs in uploading and processing.

This renders gradients in a test image, but has some shortcomings. For
one, staging buffers need to be applied for a couple things (they're
just host mapped for now). Also, the interaction between sRGB and
premultiplied alpha isn't quite right. The size of the gradient ramp
buffer is fixed and should be dynamic.

And of course there's always more optimization to be done, including
making the upload of gradient ramps more incremental, and probably
hashing of the stops instead of the processed ramps.
2021-08-09 16:16:46 -07:00
Raph Levien 6f707c4c62 Start work on gradients
WIP. Most of the GPU-side work should be done (though it's not tested
end-to-end and it's certainly possible I missed something), but still
needs work on encoding side.
2021-07-12 06:56:52 -07:00
Ishi Tatsuyuki e610c71f13 Adjust metal workgroup limits 2021-06-12 15:28:30 +09:00
Ishi Tatsuyuki d77dfb8c00 Runtime querying of threadgroup size 2021-06-08 16:29:40 +09:00
Raph Levien 074fafad1e Turn off reuse of command buffers for now
It worked ok on Vulkan but is causing problems on DX12 and Metal. Punt
for now and come back to this later when we do more sophisticated
resource management.
2021-05-31 21:09:15 -07:00
Raph Levien 87a84eb490 Fix some dx12 bugs
Missing a potential barrier, and had src and dst switched on blit.
2021-05-31 20:39:38 -07:00
Raph Levien 431486a766 Merge branch 'master' into api_reorg 2021-05-31 06:46:18 -07:00
Raph Levien bae185efbd API reorg
Move types into the toplevel and hide implementation details. Remove
deref of hub CmdBuf to mux. Restrict public visibility of internals.

Most items have some docs, though improvements are still possible. In
particular, there should be detailed safety info.
2021-05-29 21:11:02 -07:00
Raph Levien 0c35b74699 Wire up swapchain presentation
This gets a swapchain displayed and fills out a number of the image
related parts of the API: image creation, binding to descriptor sets,
and blitting.
2021-05-28 21:41:04 -07:00
Raph Levien 7d7c86c44b API changes and cleanup
Add workgroup size to dispatch call (needed by metal). Change all fence
references to mutable for consistency.

Move backend traits to a separate file (move them out of the toplevel
namespace in preparation for the hub types going there, to make the
public API nicer).

Add a method and macro for automatically choosing shader code, and
change collatz example to generate all 3 kinds on build.
2021-05-28 16:14:39 -07:00
Raph Levien af4b568589 Merge branch 'master' into metal 2021-05-28 14:47:05 -07:00
Raph Levien 5481621184 First light on running a compute shader
A bunch of loose ends remain, including needing to plumb the size of the
workgroup through. Image and swapchains also need to be added. But it
does run collatz.

Progress towards #95.
2021-05-28 14:03:44 -07:00
Raph Levien c2965254db Merge branch 'dx12' into metal 2021-05-27 16:12:21 -07:00
Raph Levien b4ba6886d8 Tweak wait_and_reset mutable fence signature
A reference to a slice of mutable references is not a thing.
2021-05-27 16:10:14 -07:00
Raph Levien 84dabcf049 Merge branch 'dx12' into metal 2021-05-27 16:02:12 -07:00
Raph Levien b6292c644f Make fences mutable
Change the interface for fences to accept mutable references. This will
actualy help the Metal backend more than dx12 (avoiding interior
mutability) but more accurately captures intent and matches gfx-hal.
2021-05-27 15:53:12 -07:00
Raph Levien 3067733310 Implement more of the API
WIP. Goal is to get collatz running.
2021-05-27 14:55:40 -07:00
Raph Levien ebefd025f7 Fix up merge
Update signatures to match changes to backend trait, and add new types
and stub methods to complete mux abstraction.
2021-05-26 21:30:28 -07:00
Raph Levien 0d5ff515ec Merge branch 'dx12' into metal 2021-05-26 18:16:45 -07:00
Raph Levien 37de07f670 More work on DX12 backend
This gets swapchain presentation wired up, and some more changes.
2021-05-26 16:31:24 -07:00
Raph Levien 2ecfc7a414 Wire hub to mux
Make the hub abstraction connect to the mux, rather than directly to the
Vulkan back-end.

As of this commit, both command line and winit examples work (on
Vulkan). In theory it should be possible to get them working on Dx12 as
well by translating the shader code, but there's a lot that can go
wrong.

This commit also contains a bunch of changes to mux to make conditional
compilation of match arms work, and new methods to support swapchain.
2021-05-26 09:30:07 -07:00
Raph Levien d15994fe44 Fix cfg'ed backend imports 2021-05-25 17:09:24 -07:00
Raph Levien f04da3af9d Add multiplexer abstraction
Adds a new "mux" module which can have multiple backends. As of this
commit, it's not wired up at all, but the functionality should be
reasonably complete.

Minor tweaks to the backend trait to accommodate this, mostly changing
Fence and Semaphore to references so they don't need to be Copy.

Part of the work toward #95
2021-05-25 15:12:37 -07:00
Raph Levien 6ac46340e6 Fixup merge of staging changes
Update the backend to reflect trait changes.
2021-05-24 15:50:50 -07:00
Raph Levien dfac2148a9 Merge branch 'staging' into dx12 2021-05-24 15:44:53 -07:00
Raph Levien 174c81ec09 Cleanup
Fix bound on blanket RetainResource impl. Clean up run_cmd_buf.
2021-05-24 15:42:25 -07:00
Raph Levien 22935fccc6 Use const generics for IntoRefs
Yay! Now we can use an array of any size, slice, or vector.
2021-05-24 14:25:13 -07:00
Raph Levien 0cc72d9765 Reduce allocations for retaining resources
Use an enum instead of Box<dyn Any> for resources to be retained until
command buffer completion, and allow both references (which will be
cloned) and owned resources (useful for staging buffers).
2021-05-24 14:10:28 -07:00
Raph Levien 47d2e0a756 Add create_buffer_init method
Add a method to create a buffer with initial content, which requires
staging buffers under the hood.

This patch also changes the lower-level (Vulkan) interface to be closer
to the raw Vulkan call.
2021-05-24 13:18:11 -07:00
Raph Levien 60d54b6e69 Add image support
Adds image data types and operations. At this point, lightly tested.
2021-05-22 15:15:33 -07:00