Commit graph

66 commits

Author SHA1 Message Date
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
Raph Levien 050df66801 Redo memory options for usage
Rework the entire mechanism for specifying memory for creating
resources, inferring the correct options from the new usage flags.
2021-05-21 22:17:17 -07:00
Raph Levien 3dfae7aed6 Merge branch 'usage' into dx12_work 2021-05-21 22:00:49 -07:00
Raph Levien 4dcf385b18 Remove MemFlags trait 2021-05-21 21:51:33 -07:00
Raph Levien e9a8b4643b Migrate to BufferUsage
Adopt the BufferUsage concept from WebGPU, and replace MemFlags, which
is inadequate.
2021-05-21 19:43:55 -07:00
Raph Levien cd5e799d1a Beginning of Metal back-end
Work in progress, some types in place but mostly a skeleton.
2021-05-21 17:44:49 -07:00
Raph Levien e4b16e706a Timestamp queries
These function, but can use some work.

First, the buffer situation is worse than it should be. It should be
possible to create a single readback buffer rather then copy from
gpu-local to host-coherent.

Second, the command buffer `finish_timestamps` call doesn't correlate to
anything in Vulkan, so needs plumbing up through the hub in one form or
other when that happens. I'm inclined to make it ergonomic by doing a
bit of resource tracking that will trigger the appropriate call (and
subsequent host barrier) in the `finish` method on the command buffer.
2021-05-21 13:19:10 -07:00
Raph Levien f482921806 Create compute pipelines
Create compute pipelines from shader source and descriptor sets. This
gets it to the point where it can run the collatz example.

Still WIP and with rough edges, of course.
2021-05-18 10:08:23 -07:00
Raph Levien ee0802133b Add new types and methods
This brings the signature current so it compiles, but the
implementations are just stubs for now.
2021-05-16 10:38:09 -07:00
Raph Levien 619fc8d4eb Merge branch 'master' into dx12 2021-05-16 10:19:06 -07:00
Raph Levien a28c0c8c83 A bit more work
Chipping away at the dx12 backend. This should more or less do the
signalling to the CPU that the command buffer is done (ie wire up the
fence). It also creates buffer objects.
2021-05-16 10:18:58 -07:00
Raph Levien a5991ecf97 Expand runtime query of GPU capabilities
Test whether the GPU supports subgroups (including size control) and
memory model.

This patch does all the ceremony needed for runtime query, including
testing the Vulkan version and only probing the extensions when
available. Thus, it should work fine on older devices (not yet tested).

The reporting of capabilities follows Vulkan concepts, but is not
particularly Vulkan-specific.
2021-05-08 11:41:47 -07:00
Raph Levien bcb26c931e Clean up device create extensions 2021-04-08 15:11:17 -07:00
Raph Levien 115cb855d9 Query extensions at runtime
Don't run extensions unless they're available. This includes querying
for descriptor indexing, and running one of two versions of kernel4
depending on whether it's enabled.

Part of the support needed for #78
2021-04-08 15:11:15 -07:00
Elias Naur 22eb418832 fix Vulkan errors on Wayland and Intel GPU
capabilities.min_image_count is 4 on my system, which is larger than
the hard-coded 2.

Use a default swapchain size if we're not getting any size information
from the surface capabilities.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-19 16:43:33 +01:00
Elias Naur 903ab1fb59 implement FillImage command and sRGB support
FillImage is like Fill, except that it takes its color from one or
more image atlases.

kernel4 uses a single image for non-Vulkan hosts, and the dynamic sized array
of image descriptors on Vulkan.

A previous version of this commit used textures. I think images are a better
choice for piet-gpu, for several reasons:

- Texture sampling, in particular textureGrad, is slow on lower spec devices
  such as Google Pixel. Texture sampling is particularly slow and difficult to
implement for CPU fallbacks.
- Texture sampling need more parameters, in particular the full u,v
  transformation matrix, leading to a large increase in the command size. Since
all commands use the same size, that memory penalty is paid by all scenes, not
just scenes with textures.
- It is unlikely that piet-gpu will support every kind of fill for every
  client, because each kind must be added to kernel4.

With FillImage, a client will prepare the image(s) in separate shader stages,
sampling and applying transformations and special effects as needed. Textures
that align with the output pixel grid can be used directly, without
pre-processing.

Note that the pre-processing step can run concurrently with the piet-gpu pipeline;
Only the last stage, kernel4, needs the images.

Pre-processing most likely uses fixed function vertex/fragment programs,
which on some GPUs may run in parallel with piet-gpu's compute programs.

While here, fix a few validation errors:
- Explicitly enable EXT_descriptor_indexing, KHR_maintenance3,
  KHR_get_physical_device_properties2.
- Specify a vkDescriptorSetVariableDescriptorCountAllocateInfo for
  vkAllocateDescriptorSets. Otherwise, variable image2D arrays won't work (but
sampler2D arrays do, at least on my setup).

Updates #38

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2021-03-19 12:50:12 +01:00
Raph Levien facc9e0982 Use sampler for texture images
Provide images to fine rasterization kernel as readonly textures with a
sampler, rather than storage images. That lets us use the GPU's hardware
for sampling, which should be considerably more efficient.

There are a bunch of parameters that are hardcoded, but it does seem to
work.
2020-11-25 18:05:10 -08:00
Raph Levien 047a0830d1 Towards wiring up images to k4
This patch passes a dynamically sized array of textures to the fine
rasterizer.

A bunch of the low level Vulkan stuff is done, but only enough of the
shaders and encoders to do minimal testing. We'll want to switch from
storage images to sampled images, track the actual array of textures
during encoding, use that to build the descriptor set (which will need
to be more dynamic), and of course run image elements through the
pipeline.

Progress towards #38
2020-11-24 22:11:38 -08:00
Raph Levien 6b06d249ab Builder pattern for pipelines
Use a builder pattern for pipelines and descriptor sets, so we can go
richer without hugely complicating existing code.

WIP
2020-11-24 22:11:38 -08:00
Raph Levien d63583083c Start DX12 backend
Very early so far, but cool to have a branch for it.
2020-11-24 10:32:49 -08:00
Raph Levien a60c2dd3c8 Scratch buffer for clip stack
We keep a small window of the clip stack in registers in the fine
rasterization kernel, and when that window is exceeded, spill to global
memory, so the clip stack can be unbounded.
2020-11-22 18:14:09 -08:00
Raph Levien 47e24ec9d5 Start adding support for creating images
This is still WIP, focused on creating image resources and making them
available GPU-side.

Progress toward #38
2020-11-19 16:32:29 -08:00
Raph Levien 75c4b62730 Add hub abstraction
The hub does a little better lifetime tracking of resources (so
Rust-side references can be dropped), and in the future will be used for
dynamic selection of backend.

The migration is still a bit half-baked, as there are a bunch of
Vulkan-specific types in the signatures, but it shouldn't be too much
work to sort that out. Perhaps it can wait until there is a second
backend though.

The main motivation for this is to create image objects with lifetime
tracking, one of the things required for #38.
2020-11-18 16:06:08 -08:00
Raph Levien 301abf4db7 Minor cleanups
Mostly cleaning up some comments. Also adds host barrier and a command
to copy a buffer to an image (in preparation for images, see #38).
2020-11-17 14:18:30 -08:00
Raph Levien 8e2f2aeeba Update dependencies
Update to latest versions of all dependencies. Among other things, this
gets us on piet 0.2, though almost all of the changes were around text,
which is not yet implemented.
2020-11-14 08:25:43 -08:00
Alexey Zatelepin 9667c34e7e Fix read mapping size (size is number of bytes, not number of items) 2020-07-02 21:32:17 +03:00
Raph Levien 8d01aba237 Update to piet 0.13
Get rid of kurbo patch, as we now use kurbo through piet. Also clean up
some warnings.
2020-05-12 08:26:48 -07:00