Giter Site home page Giter Site logo

acdemiralp / fg Goto Github PK

View Code? Open in Web Editor NEW
526.0 526.0 58.0 1.06 MB

Rendering abstraction which describes a frame as a directed acyclic graph of render tasks and resources.

License: MIT License

CMake 1.26% C++ 98.48% Python 0.25%
abstraction cpp17 frame graph rendering

fg's People

Contributors

acdemiralp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fg's Issues

Asynchronous render task launch.

The framegraph currently performs each unculled render task sequentially. It is possible to have multiple framegraphs executing render tasks in parallel (e.g. an OpenGL framegraph and a Cuda framegraph or two Vulkan framegraphs submitting to two distinct queues), but this only applies when communication and resource sharing between the tasks is not necessary.

The framegraph should ideally provide functionality for asynchronous launch of multiple render tasks. This requires:

  • Computation and placement of synchronization points to resources read/written by multiple render tasks during the compilation phase. The library user must provide implementation of a synchronization point for each render backend (e.g. a glMemoryBarrier, VkMemoryBarrier, ...) so a function similar to fg::realize should be introduced.
  • The transient resource lifetimes should be adjusted according to the render tasks accessing / mutating them in parallel.

Since the resource usage of each render task is specified during the setup phase, it is possible to identify parallel executable render tasks automatically during the compilation phase. This however may have an adverse effect on memory usage since a large amount of resources may be realized in parallel. Hence the framegraph should provide options to both automatically and manually (per render task) specify async execution.

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.
framegraph

how to fix it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.