device/commands.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | /// @file commands.h | ||
| 3 | /// @brief What device calls record into, and the recording code above `device/` may do without | ||
| 4 | /// naming a graphics API: copy between buffers, and write bytes into one. | ||
| 5 | /// | ||
| 6 | /// kernel.Dispatch(pass.commands, groups, parameters); | ||
| 7 | /// pass.commands.Update(buffer, offset, bytes); | ||
| 8 | #pragma once | ||
| 9 | |||
| 10 | #include "ernie/device/vulkan.h" | ||
| 11 | |||
| 12 | #include <cstddef> | ||
| 13 | #include <cstdint> | ||
| 14 | #include <span> | ||
| 15 | |||
| 16 | namespace ernie { | ||
| 17 | |||
| 18 | class Buffer; | ||
| 19 | |||
| 20 | /// @brief A range copied from one buffer offset to another, in bytes. | ||
| 21 | struct CopyRegion { | ||
| 22 | std::uint64_t from = 0; | ||
| 23 | std::uint64_t to = 0; | ||
| 24 | std::uint64_t bytes = 0; | ||
| 25 | }; | ||
| 26 | |||
| 27 | /// @brief Regions copied from one buffer to another, or within one. | ||
| 28 | struct BufferRegions { | ||
| 29 | const Buffer* source = nullptr; | ||
| 30 | const Buffer* destination = nullptr; | ||
| 31 | std::span<const CopyRegion> regions; | ||
| 32 | }; | ||
| 33 | |||
| 34 | /// @brief Commands being recorded for a queue. On Vulkan a command buffer, which converts to one; | ||
| 35 | /// another backend's encoder would take its place. | ||
| 36 | class CommandList { | ||
| 37 | public: | ||
| 38 | 1313 | CommandList(VkCommandBuffer commands) : commands_(commands) {} | |
| 39 | |||
| 40 | 1740 | VkCommandBuffer Handle() const { | |
| 41 | 1740 | return commands_; | |
| 42 | } | ||
| 43 | |||
| 44 | /// @brief Records copies between buffers, ordered after earlier work on them and before later | ||
| 45 | /// work. | ||
| 46 | void Copy(std::span<const BufferRegions> copies) const; | ||
| 47 | /// @brief Records writing `bytes` at `offset` of a buffer, seen by the commands after it. | ||
| 48 | void Update(const Buffer& buffer, std::uint64_t offset, std::span<const std::byte> bytes) const; | ||
| 49 | |||
| 50 | private: | ||
| 51 | VkCommandBuffer commands_; | ||
| 52 | }; | ||
| 53 | |||
| 54 | } // namespace ernie | ||
| 55 |