Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit 9b7ff70

Browse files
committed
Update to use new tg syntax goodies
1 parent 946ee29 commit 9b7ff70

File tree

1 file changed

+47
-26
lines changed

1 file changed

+47
-26
lines changed

docs/taskgraph.md

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ graph.add_task({
7272
},
7373
.task = [=](daxa::TaskInterface ti)
7474
{
75-
copy_image_to_image(ti.recorder, ti.get(src).ids[0], ti.get(dst).ids[0], blur_width);
75+
copy_image_to_image(ti.recorder, ti.id(src), ti.id(dst), blur_width);
7676
},
7777
.name = "example task",
7878
});
@@ -125,11 +125,18 @@ This includes:
125125
- runtime daxa resource view ids (these are created by the graph based on the attachment view type)
126126
- image layout
127127

128+
The get function alone can make the code verbose. The TaskInterface provides many helper functions such as:
129+
* `id`
130+
* `view`
131+
* `info`
132+
* `device_address`
133+
128134
Aside from attachment information the interface also provides:
129135

130136
- a command recorder (automatically reused by the graph)
131137
- a transfer memory allocator (super fast per execution linear allocator for mapped gpu memory)
132138
- attachment shader data (generated from the list of attachments, can be send to shader)
139+
- task metadata such as the name and index
133140

134141
### TaskHead
135142

@@ -165,6 +172,11 @@ DAXA_TH_BUFFER_ID(COMPUTE_SHADER_WRITE, REGULAR_2D, dst_image)
165172
DAXA_DECL_TASK_HEAD_END
166173
```
167174
175+
> NOTE: COMPUTE_SHADER_READ is from the enum daxa::TaskBufferAccess
176+
177+
> NOTE: For each of these access enum values, there is also a shortened version, example: CS_READ
178+
179+
168180
This task head declaration will translate to the following glsl shader struct:
169181
170182
```c
@@ -196,6 +208,10 @@ namespace MyTaskHead
196208
// Number of declared attachments:
197209
static inline constexpr daxa::usize ATTACHMENT_COUNT = {/* TEMPLATE MAGIC */};
198210

211+
// Generated Types:
212+
static inline constexpr auto ATTACHMENTS_T = {/* TEMPLATE MAGIC */};
213+
static inline constexpr auto VIEWS_T = {/* TEMPLATE MAGIC */};
214+
199215
// Attachment meta information:
200216
static inline constexpr auto ATTACHMENTS = {/* TEMPLATE MAGIC */};
201217

@@ -212,13 +228,14 @@ namespace MyTaskHead
212228
// also getting some fields into the task structs namespace:
213229
struct Task : public daxa::IPartialTask
214230
{
215-
using AttachmentViews = daxa::AttachmentViews<ATTACHMENT_COUNT>;
231+
using AttachmentViews = ATTACHMENTS_T;
232+
using Views = VIEWS_T;
216233
static constexpr AttachmentsStruct<ATTACHMENT_COUNT> const & AT = ATTACHMENTS;
217234
static constexpr daxa::usize ATTACH_COUNT = ATTACHMENT_COUNT;
218235
static auto name() -> std::string_view { return std::string_view{NAME}; }
219236
static auto attachments() -> std::span<daxa::TaskAttachment const>
220237
{
221-
return AT.attachment_decl_array;
238+
return AT._internal.values;
222239
}
223240
static auto attachment_shader_blob_size() -> daxa::u32
224241
{
@@ -292,14 +309,16 @@ daxa::ImageViewId some_img_view = ...;
292309
daxa::BufferViewId some_buf_view = ...;
293310

294311
task_graph.add_task(MyTask{
295-
.views = {
296-
MyTaskHead::AT.src_buffer | some_img_view,
297-
MyTaskHead::AT.dst_image | some_img_view,
312+
.views = MyTask::Views{
313+
.src_buffer = some_img_view,
314+
.dst_image = some_img_view,
298315
},
299316
.other_stuff = ...,
300317
});
301318
```
302319

320+
Daxa automatically generates a struct type `MyTask::Views` for syntactic suggar when assigning views. Its a struct with one field for each declared attachment. Each field is of the type `TaskAttachmentViewWrapper<T>` which accept task resource views.
321+
303322
### Alternative Use Of TaskHead
304323

305324
Task heads can also be directly used in inline tasks without having to declare a struct inheriting the task:
@@ -309,12 +328,14 @@ Task heads can also be directly used in inline tasks without having to declare a
309328
daxa::ImageViewId some_img_view = ...;
310329
daxa::BufferViewId some_buf_view = ...;
311330

312-
task_graph.add_task(daxa::InlineTaskWithHead<MyTaskHead::Task>{
313-
.views = std::array{
314-
MyTaskHead::AT.src_buffer | some_img_view,
315-
MyTaskHead::AT.dst_image | some_img_view,
316-
},
317-
.task = [=](daxa::TaskInterface ti) { ... },
331+
using MyTask = daxa::InlineTaskWithHead<MyTaskHead::Task>
332+
333+
task_graph.add_task(MyTask{
334+
.views = MyTask::Views{
335+
.src_buffer = some_img_view,
336+
.dst_image = some_img_view,
337+
},
338+
.task = [=](daxa::TaskInterface ti) { ... },
318339
});
319340

320341
```
@@ -344,16 +365,29 @@ void callback(daxa::TaskInterface ti)
344365
}
345366
// The Buffer Attachment info contents:
346367
{
368+
// Information retrieved from convenience functions:
369+
[[maybe_unused]] daxa::BufferId id_ = ti.id(AT.src_buffer, /*optional*/0);
370+
[[maybe_unused]] daxa::DeviceAddress address_ = ti.device_address(AT.src_buffer, /*optional*/0).value();
371+
[[maybe_unused]] std::byte* host_address = ti.buffer_host_address(AT.src_buffer).value();
372+
[[maybe_unused]] daxa::BufferInfo info_ = ti.info(AT.src_buffer, /*optional*/0).value();
373+
374+
// Information retrieved from the .get meta function:
375+
[[maybe_unused]] std::span<daxa::BufferId const> ids = ti.get(AT.src_buffer).ids;
347376
[[maybe_unused]] daxa::BufferId id = ti.get(AT.src_buffer).ids[0];
348377
[[maybe_unused]] char const * name = ti.get(AT.src_buffer).name;
349378
[[maybe_unused]] daxa::TaskBufferAccess access = ti.get(AT.src_buffer).access;
350379
[[maybe_unused]] u8 shader_array_size = ti.get(AT.src_buffer).shader_array_size;
351380
[[maybe_unused]] bool shader_as_address = ti.get(AT.src_buffer).shader_as_address;
352381
[[maybe_unused]] daxa::TaskBufferView view = ti.get(AT.src_buffer).view;
353-
[[maybe_unused]] std::span<daxa::BufferId const> ids = ti.get(AT.src_buffer).ids;
354382
}
355383
// The Image Attachment info contents:
356384
{
385+
// Information retrieved from convenience functions:
386+
[[maybe_unused]] daxa::ImageId id_ = ti.id(AT.dst_image, /*optional*/0);
387+
[[maybe_unused]] daxa::ImageViewId view_ = ti.view(AT.dst_image, /*optional*/0);
388+
[[maybe_unused]] daxa::ImageViewInfo info_ = ti.info(AT.dst_image, /*optional*/0).value();
389+
390+
// Information retrieved from the .get meta function:
357391
[[maybe_unused]] char const * name = ti.get(AT.dst_image).name;
358392
[[maybe_unused]] daxa::TaskImageAccess access = ti.get(AT.dst_image).access;
359393
[[maybe_unused]] daxa::ImageViewType view_type = ti.get(AT.dst_image).view_type;
@@ -368,19 +402,6 @@ void callback(daxa::TaskInterface ti)
368402
/// there will be an empty daxa::ImageViewId{} put into this array for the attachment!
369403
[[maybe_unused]] std::span<daxa::ImageViewId const> view_ids = ti.get(AT.dst_image).view_ids;
370404
}
371-
// The interface has multiple convenience functions for easier access to the underlying resources attributes:
372-
{
373-
// Overloaded for buffer, blas, tlas, image
374-
[[maybe_unused]] daxa::BufferInfo info = ti.info(AT.src_buffer).value();
375-
// Overloaded for buffer, blas, tlas
376-
[[maybe_unused]] daxa::DeviceAddress address = ti.device_address(AT.src_buffer).value();
377-
378-
[[maybe_unused]] std::byte* host_address = ti.buffer_host_address(AT.src_buffer).value();
379-
[[maybe_unused]] daxa::ImageViewInfo img_view_info = ti.image_view_info(AT.dst_image).value();
380-
381-
// In case the task resource has an array of real resources, one can use the optional second parameter to access those:
382-
[[maybe_unused]] daxa::BufferInfo info2 = ti.info(AT.src_buffer, 123 /*resource index*/).value();
383-
}
384405
// The attachment infos are also provided, directly via a span:
385406
for ([[maybe_unused]] daxa::TaskAttachmentInfo const & attach : ti.attachment_infos)
386407
{

0 commit comments

Comments
 (0)