Skip to content

What is sideeffect #1

Closed
Closed

Description

@FuXiii

When I read test in test.cpp

builder.setSideEffect();

FrameGraph::Builder &FrameGraph::Builder::setSideEffect() {
  m_passNode.m_hasSideEffect = true;
  return *this;
}

and

FrameGraphResource FrameGraph::Builder::write(FrameGraphResource id) {
  assert(m_frameGraph.isValid(id));
  if (m_frameGraph._getResourceEntry(id).isImported()) setSideEffect();
...
}

What is the m_hasSideEffect use for?

And the FrameGraph-Example just a little complex, I am just a fresh hand. Can you update an example about how to draw a box with index buffer? :D Thanks~

Activity

  1. added
    question
    on Jun 3, 2022
  2. skaarj1989 commented on Jun 3, 2022

    @skaarj1989
    Owner

    setSideEffect ensures that a pass is not culled during the compilation phase. (writing to imported resource counts as side-effect).

    Moving to FrameGraph is a big paradigm shift. It might be overwhelming at first but once you understand it you won't look back ;)

    I encourage you to watch/read:

  3. FuXiii commented on Jun 4, 2022

    @FuXiii
    Author

    Oh! I have generally finished reading your project and it wrote very well and clearly, Thank you very much~ :D.


    When I try to read FrameGraph in Filament. FrameGraph looks like rebuild every frame? If I have many many Node and Resource in one rendering frame, if some Node not change but I must rebuild it at next new frame? Is that will waste performance? Is that really necessary to rebuild FrameGraph every frame?


    If I create a PassNode and create an TextureNode for read, there have assert code in FrameGraph::Builder::read(...):

    FrameGraphResource FrameGraph::Builder::read(FrameGraphResource id) {
      assert(m_frameGraph.isValid(id));
      return m_passNode._read(id);
                          |_ assert(!creates(id) && !writes(id));
    }

    It looks like FrameGraph not support PassNode to create ResourceNode for read.


    If I want create an TextureNode for ColorDrawPass and it will sampled in fragment shader.

    1. How I binding the shaders in PassNode
    2. Resource are create and destroy by ResourceEntry::Concept or Model . How to initial the texture's color pixel? If I import this texture into FrameGraph how to do it? the test in TEST_CASE("Imported resource", "[FrameGraph]") the id for the import already existed
     constexpr auto kBackbufferId = 777;
     FrameGraph fg;
     const auto backbuffer = fg.import("Backbuffer", {1280, 720}, FrameGraphTexture{kBackbufferId});

    In really case the code maybe looks like:

    Texture texture = ImageLoader::Load("./SomePicture.png");
    FrameGraph fg;
    fg.import(..., texture );
    

    Is that right?

    or just create an HostWritePass for host texture memory write? but I think this just a little odd.

    image

  4. skaarj1989 commented on Jun 4, 2022

    @skaarj1989
    Owner

    Is that really necessary to rebuild FrameGraph every frame?

    Yes, you need to rebuild the FrameGraph every frame.

    (...) Is that will waste performance?

    Here I have a FrameGraph with 38 passes and 51 resources:

    image
    image

    (measured with Tracy Profiler).
    In my opinion, the cost is negligible.

    It looks like FrameGraph not support PassNode to create ResourceNode for read.

    Do you want to create a resource in a pass and read it immediately in the same pass? That will give you a garbage data.
    Usually, a pass creates a resource (writes to it) and another pass reads from it.

    How I binding the shaders in PassNode

    It's up to you. Pass whatever you need to ctx in an execution callback.

    struct PassData {};
    fg.addCallbackPass<PassData>("SimplePass",
      [&](FrameGraph::Builder &builder, PassData &data) {
        // ...
      },
      [=](const PassData &data, FrameGraphPassResources &resources, void *ctx) {
        auto &rc = *static_cast<RenderContext *>(ctx);
        rc.bindPipeline(/* whatever, could be a member variable */);
        // ...
      }
    );

    Here you have an example:
    https://github.com/skaarj1989/FrameGraph-Example/blob/7867df8e3146acfffaf41173d5776b6ac265fd50/src/WorldRenderer.cpp#L415


    1. Don't use a FrameGraph to create a resource that is initialized once (like mesh vertex buffer or a material texture).
    2. Don't import everyting into a FrameGraph.

    Here, the SSAO pass is the owner of a noise texture and a kernel uniform buffer. Both are initialized by the constructor and then captured by the execution callback.


    To create a resource, the FrameGraph class uses given allocator (transient resource manager/system).

    void execute(void *context = nullptr, void *allocator = nullptr);

    Take a look at here, for an example of a transient resource system.

  5. FuXiii commented on Jun 4, 2022

    @FuXiii
    Author

    Oh~ Thank you very very much~ :D
    I think I need to read your FrameGraph-Example project .♪(^∇^*)

  6. FuXiii commented on Jun 5, 2022

    @FuXiii
    Author

    When to judge ID Valid

    bool FrameGraph::isValid(FrameGraphResource id) const {
      const auto &node = _getResourceNode(id);
      auto &resource = m_resourceRegistry[node.m_resourceId];
      return node.m_version == resource.m_version;
    }

    the code compare the version between ResourceNode and ResourceRegistry. Why? Why to compare the version?

    I know if different pass write to the same ResourceEntry ,the version of ResourceEntry will plus one for each clone and set the new ResourceEntry version into the ResourceNode version, that will let track resource very easy, but I don't understand why use the node.m_version == resource.m_version to judge whether it is valid?

  7. skaarj1989 commented on Jun 5, 2022

    @skaarj1989
    Owner

    It enforces a specific execution order of the render passes (prevents mistakes).

    Imagine that you have a pass P0, that writes to a resource R.
    Followed by a pass P1, that writes to R (version is bumped)
    Then you want to read R in yet another pass P2
    you could by mistake give the handle of the first write operation to P2 (you should use the most recent one)

    I'm gonna convert this issue to a discussion (since it's not really an issue).

  8. Repository owner locked and limited conversation to collaborators on Jun 5, 2022
  9. converted this issue into a discussion #2 on Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions