Skip to content

vk/meta: Add copy/fill/update helpers

Boris Brezillon requested to merge bbrezillon/mesa:vk-meta-copy into main

What does this MR do and why?

Add buffer copy/fill/update helpers using compute shaders. The driver
can select the optimal per-workgroup copy/fill/update size by specifying
a non-zero vk_meta_device::buffer_access::optimal_size_per_wg size.
If zero, the core will assume a 64-byte size (the usual cache-line size).

Buffer accesses will be done through SSBOs unless
vk_meta_device::buffer_access::use_global_address is true, in which
case the core will the buffer address using GetBufferDeviceAddress()
and pass that address as a push constant to the compute shader.

Image to buffer copies are always done through a compute shader. The
optimal workgroup size will be chosen based on
vk_meta_copy_image_properties::tile_size: the copy logic picks a
workgroup size matching the tile size, and aligns accesses on a tile.
The view format is selected by the driver. To optimize things on the
shader side, pick UINT formats (usually less work to do to pack data).

Buffer to image copies can be done done through the graphics pipeline
if needed (use_gfx_pipeline passed to vk_meta_copy_buffer_to_image()),
which is useful for vendor-specific compressed formats that can't be
written outside of the graphics pipeline. Drivers should normally prefer
compute-based copies when that's an option. Just like for image to buffer
copies, the workgroup size of compute shaders is picked based on the
image tile size, and the view format must be selected by the driver.

Image to image copies is just a mix of the above, with the driver being
able to select the pipeline type, as well as define the tile size and
view format to use. When using a compute pipeline, the workgroup size
will be MAX2(src_tile_sz, dst_tile_sz), and accesses will be aligned
on the selected reference image.

For compressed formats, the caller should pick an RGBA format matching
the compressed block size.

Depends on !28793 for the pack/unpack helpers, with an extra commit on top to add depth/stencil [un]packers.

I also pushed 1 commits that is not directly related to this MR, but is fixing a bug discovered while working on meta copies, so I figured I would put it here:

Marked as Draft because I didn't test the use_global_address=false case extensively.

/cc @nanokatze @alyssa @gfxstrand @kusma

Edited by Boris Brezillon

Merge request reports