Skip to content

Commit 8cb7b4c

Browse files
authored
Add helper to import an external fence (#24)
1 parent 08de596 commit 8cb7b4c

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

Primer.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,15 @@ Command lists can be reused by other command lists as well. When `dkCmdBufCallLi
329329
```c
330330
struct DkFence;
331331
DkResult dkFenceWait(DkFence* obj, int64_t timeout_ns);
332+
void dkFenceImport(DkFence* obj, uint32_t id, uint32_t value);
332333
```
333334

334335
Fences (`DkFence`) are opaque structs that contain GPU synchronization information, used to determine when work submitted to the GPU has finished executing. Each time they're scheduled to be signaled in a queue (`DkQueue`), either directly or indirectly through a command list, their contents are updated. Fences can be waited on by the GPU or CPU (using the `dkFenceWait` function). When a fence is waited on, the waiter (CPU or GPU) will be kept blocked until the point in which it's signaled (hence marking the completion of dependent work).
335336

336337
Usually fences will be used in a signaling command prior to being waited on. If fences are to be potentially waited on before they're signaled (e.g. if they're used to wait on previous work, with no previous work having been submitted yet), they should be initialized to zero in order to ensure that any initial waits will correctly have no effect.
337338

339+
Synchronization between the GPU and external engines (video processing, display, etc) can be achieved through the `dkFenceImport` function, which provides a way of integrating Host1x syncpoint functionality within deko3d. The `id` and `value` parameters respectively represent the syncpt index, and the threshold at which the work associated with the fence can be considered as completed. Note that those values are usually allocated and managed by the driver. More information on syncpoints can be found in the Tegra TRM, chapter 14 ("Host Subsystem").
340+
338341
> **Warning**: Fence wait/signal commands recorded to a command list keep a pointer to the fence struct in the command buffer's bookkeeping memory. Please make sure the struct remains at the same valid memory address for the lifetime of the command list handle; otherwise submitting the command list handle to a queue will result in undefined behavior.
339342
340343
### Variables (`DkVariable`)

include/deko3d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,7 @@ uint32_t dkMemBlockGetSize(DkMemBlock obj);
12441244
DkResult dkMemBlockFlushCpuCache(DkMemBlock obj, uint32_t offset, uint32_t size);
12451245

12461246
DkResult dkFenceWait(DkFence* obj, int64_t timeout_ns);
1247+
void dkFenceImport(DkFence* obj, uint32_t id, uint32_t value);
12471248

12481249
void dkVariableInitialize(DkVariable* obj, DkMemBlock mem, uint32_t offset);
12491250
uint32_t dkVariableRead(DkVariable const* obj);

include/deko3d.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ namespace dk
166166
{
167167
DK_OPAQUE_COMMON_MEMBERS(Fence);
168168
DkResult wait(int64_t timeout_ns = -1);
169+
void import(uint32_t id, uint32_t value);
169170
};
170171

171172
struct Variable : public detail::Opaque<::DkVariable>
@@ -616,6 +617,11 @@ namespace dk
616617
return ::dkFenceWait(this, timeout_ns);
617618
}
618619

620+
inline void Fence::import(uint32_t id, uint32_t value)
621+
{
622+
::dkFenceImport(this, id, value);
623+
}
624+
619625
inline void Variable::initialize(DkMemBlock mem, uint32_t offset)
620626
{
621627
::dkVariableInitialize(this, mem, offset);

source/dk_fence.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,16 @@ DkResult dkFenceWait(DkFence* obj, int64_t timeout_ns)
6969
timeout_us = timeout_ns / 1000;
7070
return obj->wait(timeout_us);
7171
}
72+
73+
void dkFenceImport(DkFence* obj, uint32_t id, uint32_t value) {
74+
obj->m_type = DkFence::External;
75+
obj->m_external.m_fence = {
76+
.num_fences = 1,
77+
.fences = {
78+
{
79+
.id = id,
80+
.value = value,
81+
},
82+
},
83+
};
84+
}

0 commit comments

Comments
 (0)