How to use the frame graph?
Hi, I'm not sure how to use correctly the frame graph. I've got a simple resource which is a string and I want to create this resource in a first pass, then "transfer" the output of the first pass to 4 other passes. But these 4 passes get culled and I don't know why. For my liking, it should work.
namespace gl
{
using texture_2d = std::string;
}
namespace glr
{
struct texture_description
{
std::string name;
};
using texture_2d_resource = fg::resource<texture_description, gl::texture_2d>;
}
namespace fg
{
template<>
std::unique_ptr<gl::texture_2d> realize(const glr::texture_description& description)
{
return std::make_unique<gl::texture_2d>(description.name);
}
}
int main()
{
fg::framegraph framegraph;
struct render_task_0_data
{
glr::texture_2d_resource* output;
};
auto render_task_0 = framegraph.add_render_task<render_task_0_data>(
"Render Task 0",
[&](render_task_0_data& data, fg::render_task_builder& builder)
{
data.output = builder.write(builder.read(builder.create<glr::texture_2d_resource>("Resource 0", glr::texture_description("0"))));
},
[=](const render_task_0_data& data)
{
auto actual1 = data.output->actual();
//do something with the actual1
std::cout << *actual1 << "\n";
});
auto& data_0 = render_task_0->data();
struct render_task_data
{
glr::texture_2d_resource* input;
glr::texture_2d_resource* output;
};
for (int i = 1; i <= 4; ++i) {
auto render_task = framegraph.add_render_task<render_task_data>(
"Render Task " + std::to_string(i),
[&](render_task_data& data, fg::render_task_builder& builder)
{
data.input = builder.read(data_0.output);
data.output = builder.write<glr::texture_2d_resource>(builder.create<glr::texture_2d_resource>("Resource " + std::to_string(i), glr::texture_description(std::to_string(i))));
},
[=](const render_task_data& data)
{
auto actual1 = data.input->actual();
auto actual2 = data.output->actual();
//do something with the actual1 and actual2
std::cout << *actual2 << "\n";
});
}
framegraph.compile();
framegraph.execute();
framegraph.export_graphviz("framegraph.gv");
framegraph.clear();
return 0;
}
the first pass is executed correctly, but the next 4 passes are culled.
the generated graph looks ok, except that the resources have a ref of 0.

how to fix it?
Dear @dontweaks ,
Render Task 1-4 are writing to transient (temporary) resources that are never being used, hence they will get culled.
You can (a) Render to a retained (non-temporary) resource with a new task that depends on Resource 1-4 as in the examples. (b) Disable culling via task.set_cull_immune(true) for the render tasks which you do not want to be culled.
Oh, ok, now I get it. Thanks for the quick reply