Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DirtyFlag optimization by avoiding remaking decision #379

Open
@nategoose

Description

@nategoose

Once you know that a sub-tree is dirty, you know that all of its children are dirty and can avoid making that decision again.
Splitting render into Clean (so far) and (known to be) Dirty functions lets most of the nodes only have to either make the decision about clean/dirty (on the clean so far path) or combine the transforms (on the dirty path). The only node that has to do both is the 1st node reached that is dirty.
Note that if renderMesh can be moved to the end of the calls (after rendering children) then tail call optimization is also a possibility. Tail call optimization is not reasonably doable when the functions end in a for loop. But it's also possible that renderMesh might be more expensive if done after children.

diff --git a/code/cpp/dirty-flag.h b/code/cpp/dirty-flag.h
index 31df713..cf674df 100644
--- a/code/cpp/dirty-flag.h
+++ b/code/cpp/dirty-flag.h
@@ -147,6 +147,8 @@ namespace DirtyFlag
       static const int MAX_CHILDREN = 16;
       GraphNode* children_[MAX_CHILDREN];
       int numChildren_;

  •      void renderDirty(Transform parentWorld);
  •      void renderClean();
           //^omit
         };
         //^dirty-graph-node
    @@ -162,18 +164,36 @@ namespace DirtyFlag
         //^dirty-render
         void GraphNode::render(Transform parentWorld, bool dirty)
         {
  •      dirty |= dirty_;
           if (dirty)
           {
  •        world_ = local_.combine(parentWorld);
  •        dirty_ = false;
  •        renderDirty(parentWorld);
  •      } else
  •      {
  •        renderClean();
           }
  •    }
  •    void GraphNode::renderDirty(Transform parentWorld)
  •    {
  •      world_ = local_.combine(parentWorld);
  •      dirty_ = false;
           if (mesh_) renderMesh(mesh_, world_);

       for (int i = 0; i < numChildren_; i++)
       {

  •        children_[i]->render(world_, dirty);
  •        children_[i]->renderDirty(world_);
  •      }
  •    }
  •    void GraphNode::renderClean()
  •    {
  •      if (dirty_)
  •      {
  •        renderDirty(world_);
  •      } else
  •      {
  •        if (mesh_) renderMesh(mesh_, world_);
  •        for (int i = 0; i < numChildren_; i++)
  •        {
  •          children_[i]->renderClean();
  •        }
           }
         }
         //^dirty-render

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp