···6677.. note::
88 The API docs are generated from :file:`kestrel/include/kestrel/kestrel.h`.
99- To update this documentation, please edit the header file.
99+ To update this documentation, please also edit the header file.
10101111.. toctree::
1212 :hidden:
···44Each driver library (`libkestrel_<platform>.so`) exports only
55a single symbol.
6677-.. doxygenfile:: kestrel/interface.h
77+8899When a new Device is created, the Kestrel runtime iterates
1010the available DRM devices on the system, and tries to resolve
···11#pragma once
2233+/**
44+ * @file kestrel.h
55+ * @brief Core Kestrel API
66+ */
77+38#include <cstdint>
49#include <stddef.h>
510#include <stdint.h>
···813extern "C" {
914#endif
10151616+/**
1717+ * GPU pointer type.
1818+ */
1119typedef uint64_t kes_gpuptr_t;
2020+/**
2121+ * Opaque handle to a Device.
2222+ */
1223typedef void *KesDevice;
2424+/**
2525+ * Opaque handle to a Command Queue.
2626+ */
1327typedef void *KesQueue;
2828+/**
2929+ * Opaque handle to a Command List.
3030+ */
1431typedef void *KesCommandList;
15323333+/**
3434+ * Structure describing a memory allocation.
3535+ * @sa kes_malloc
3636+ */
1637struct KesAllocation {
3838+ /**
3939+ * Pointer to the CPU-accessible memory.
4040+ */
1741 void *cpu;
4242+ /**
4343+ * GPU pointer to the allocated memory.
4444+ */
1845 kes_gpuptr_t gpu;
4646+ /**
4747+ * Size of the allocation in bytes.
4848+ */
1949 size_t size;
5050+ /**
5151+ * Internal driver-specific data. Should not be modified directly.
5252+ */
2053 void *_internal;
2154};
22555656+/**
5757+ * Memory types for allocation.
5858+ * @sa kes_malloc
5959+ */
2360enum KesMemory {
6161+ /**
6262+ * Memory type suitable for most data (uniforms, etc). Always visible to both the CPU and GPU.
6363+ */
2464 KesMemoryDefault,
6565+ /**
6666+ * Memory type optimized for GPU access, not visible to the CPU. Use for large buffers or textures
6767+ * that the CPU does not need to read or write.
6868+ */
2569 KesMemoryGpu,
7070+ /**
7171+ * Memory type optimized for CPU readback. Visible to both CPU and GPU, but optimized for CPU reads.
7272+ */
2673 KesMemoryReadback
2774};
28757676+/**
7777+ * Special flags for wait operations.
7878+ * @sa kes_cmd_wait_before
7979+ */
2980enum KesHazardFlags {
8181+ /**
8282+ * No special hazard flags.
8383+ */
3084 KesHazardFlagsNone = 0,
8585+ /**
8686+ * Indicates that the wait is for draw arguments.
8787+ */
3188 KesHazardFlagsDrawArguments = 1 << 0,
8989+ /**
9090+ * Indicates that the wait is for descriptor updates.
9191+ */
3292 KesHazardFlagsDescriptors = 1 << 1,
3393};
34949595+/**
9696+ * Comparison operations for wait operations.
9797+ * @sa kes_cmd_wait_before
9898+ */
3599enum KesOp {
100100+ /**
101101+ * Never pass the wait.
102102+ */
36103 KesOpNever,
104104+ /**
105105+ * Pass the wait if the value is less than the specified value.
106106+ */
37107 KesOpLess,
108108+ /**
109109+ * Pass the wait if the value is equal to the specified value.
110110+ */
38111 KesOpEqual
39112};
40113114114+/**
115115+ * Signal operations for signal operations.
116116+ * @sa kes_cmd_signal_after
117117+ */
41118enum KesSignal {
119119+ /**
120120+ * Set the value atomically.
121121+ */
42122 KesSignalAtomicSet,
123123+ /**
124124+ * Set the value to the maximum of the current and specified value atomically.
125125+ */
43126 KesSignalAtomicMax,
127127+ /**
128128+ * Perform a bitwise OR with the specified value atomically.
129129+ */
44130 KesSignalAtomicOr,
45131};
46132133133+/**
134134+ * Pipeline stages for synchronization.
135135+ * @sa kes_cmd_signal_after, kes_cmd_wait_before
136136+ */
47137enum KesStage {
138138+ /**
139139+ * Transfer stage. Should only be used on transfer queues.
140140+ */
48141 KesStageTransfer,
142142+ /**
143143+ * Compute stage.
144144+ */
49145 KesStageCompute,
146146+ /**
147147+ * Raster color output stage (e.g., render target writes).
148148+ */
50149 KesStageRasterColorOut,
150150+ /**
151151+ * Pixel shader stage.
152152+ */
51153 KesStagePixelShader,
154154+ /**
155155+ * Vertex shader stage.
156156+ */
52157 KesStageVertexShader
53158};
54159160160+/**
161161+ * Types of command queues.
162162+ * @sa kes_create_queue
163163+ */
55164enum KesQueueType {
165165+ /**
166166+ * Graphics queue, capable of rasterization and compute.
167167+ */
56168 KesQueueTypeGraphics,
169169+ /**
170170+ * Compute-only queue.
171171+ */
57172 KesQueueTypeCompute,
173173+ /**
174174+ * Transfer-only queue, optimized for memory copy and fill operations.
175175+ */
58176 KesQueueTypeTransfer
59177};
60178179179+/**
180180+ * Create a new Device.
181181+ * @return A handle to the created device.
182182+ */
61183KesDevice kes_create();
6262-void kes_destroy(KesDevice);
631846464-struct KesAllocation kes_malloc(KesDevice, size_t size, size_t align, KesMemory);
6565-void kes_free(KesDevice, struct KesAllocation *);
185185+/**
186186+ * Destroy a Device.
187187+ * @param device The device to destroy.
188188+ */
189189+void kes_destroy(KesDevice device);
661906767-KesQueue kes_create_queue(KesDevice, KesQueueType);
6868-void kes_destroy_queue(KesQueue);
191191+/**
192192+ * Allocate memory on the device.
193193+ * @param device The device to allocate memory on.
194194+ * @param size The size of the allocation in bytes.
195195+ * @param align The alignment of the allocation in bytes.
196196+ * @param memory The type of memory to allocate.
197197+ * @return A KesAllocation structure describing the allocated memory.
198198+ */
199199+struct KesAllocation kes_malloc(KesDevice device, size_t size, size_t align, enum KesMemory memory);
692007070-KesCommandList kes_start_recording(KesQueue);
201201+/**
202202+ * Free a previously allocated memory allocation.
203203+ * @param device The device the memory was allocated on.
204204+ * @param allocation The allocation to free.
205205+ */
206206+void kes_free(KesDevice device, struct KesAllocation *allocation);
712077272-void kes_submit(KesQueue, KesCommandList);
208208+/**
209209+ * Create a command queue on the device.
210210+ * @param device The device to create the queue on.
211211+ * @param type The type of queue to create.
212212+ * @return A handle to the created queue.
213213+ */
214214+KesQueue kes_create_queue(KesDevice device, enum KesQueueType type);
732157474-void kes_cmd_memset(KesCommandList, kes_gpuptr_t addr, size_t size, uint32_t value);
7575-void kes_cmd_write_timestamp(KesCommandList, kes_gpuptr_t addr);
216216+/**
217217+ * Destroy a command queue.
218218+ * @param queue The queue to destroy.
219219+ */
220220+void kes_destroy_queue(KesQueue queue);
762217777-void kes_cmd_signal_after(KesCommandList, KesStage before, kes_gpuptr_t addr, uint64_t value, KesSignal);
7878-void kes_cmd_wait_before(KesCommandList, KesStage after, kes_gpuptr_t addr, uint64_t value, KesOp, KesHazardFlags, uint64_t mask);
222222+/**
223223+ * Start recording commands on a command queue.
224224+ * @param queue The queue to record commands on.
225225+ * @return A handle to the command list for recording commands.
226226+ */
227227+KesCommandList kes_start_recording(KesQueue queue);
228228+229229+/**
230230+ * Submit a recorded command list to a command queue for execution.
231231+ * @param queue The queue to submit the command list to. Must be the queue that the command list was created for.
232232+ * @param command_list The command list to submit.
233233+ */
234234+void kes_submit(KesQueue queue, KesCommandList command_list);
235235+236236+/**
237237+ * Record a memory set command in the command list.
238238+ * @param command_list The command list to record the command in.
239239+ * @param addr The GPU address to set memory at.
240240+ * @param size The size of the memory to set in bytes.
241241+ * @param value The value to set each byte to.
242242+ */
243243+void kes_cmd_memset(KesCommandList command_list, kes_gpuptr_t addr, size_t size, uint32_t value);
244244+245245+/**
246246+ * Record a timestamp write command in the command list. Writes a 64-bit unsigned timestamp in ticks to the provided address.
247247+ * @param command_list The command list to record the command in.
248248+ * @param addr The GPU address to write the timestamp to.
249249+ */
250250+void kes_cmd_write_timestamp(KesCommandList command_list, kes_gpuptr_t addr);
251251+252252+/**
253253+ * Record a signal command in the command list.
254254+ * @param command_list The command list to record the command in.
255255+ * @param before The pipeline stage before which the signal should occur.
256256+ * @param addr The GPU address to signal to.
257257+ * @param value The value to signal.
258258+ * @param signal The type of signal operation to perform.
259259+ */
260260+void kes_cmd_signal_after(KesCommandList command_list, enum KesStage before, kes_gpuptr_t addr, uint64_t value, enum KesSignal signal);
261261+262262+/**
263263+ * Record a wait command in the command list.
264264+ * @param command_list The command list to record the command in.
265265+ * @param after The pipeline stage after which the wait should occur.
266266+ * @param addr The GPU address to wait on.
267267+ * @param value The value to compare against.
268268+ * @param op The comparison operation to use.
269269+ * @param hazard_flags Special hazard flags for the wait operation.
270270+ * @param mask A bitmask to apply to the value before comparison.
271271+ */
272272+void kes_cmd_wait_before(KesCommandList command_list, enum KesStage after, kes_gpuptr_t addr, uint64_t value, enum KesOp op, enum KesHazardFlags hazard_flags, uint64_t mask);
7927380274#ifdef __cplusplus
81275}