Skip to content

VertexBuffer cleanup and simplification.#3775

Merged
prideout merged 1 commit into
mainfrom
pr/bocleanup
Apr 8, 2021
Merged

VertexBuffer cleanup and simplification.#3775
prideout merged 1 commit into
mainfrom
pr/bocleanup

Conversation

@prideout
Copy link
Copy Markdown
Contributor

@prideout prideout commented Apr 7, 2021

This includes changes to OpenGL, Metal, and Vulkan backends.

At the backend level, vertex buffers are now always composed of buffer
objects. This lets us simplify the Driver API and some bookkeeping in
the backends.

This change also splits MAX_VERTEX_ATTRIBUTE_COUNT into two constants
because the maximum number of bound buffers is a separate concept from
the maximum number of attribute semantics (e.g. consider interleaving).
For now these two constants are set to the same value.

We also now store a byte count in HwBufferObject, which allows us to
remove the byte count from the Metal-specific handle, and to add some
asserts to debug builds to prevent size overflow.

Copy link
Copy Markdown
Collaborator

@pixelflinger pixelflinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice!

updateVertexArrayObject(rp, vb);
}
const GLVertexBuffer* vb = handle_cast<GLVertexBuffer*>(vbwo);
if (UTILS_UNLIKELY(rp->gl.vertexBufferVersion != vb->bufferObjectsVersion)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're sure that vb can't be nullptr here? by construction?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, it's possible for Filament to create a render primitive and never set it up with a vertex buffer and index buffer. However I would argue that calling draw() with an uninitialized render primitive is a mis-use of the Driver API.

Maybe this is a good candidate for assert_invariant.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I think it make more sense to do nothing in that case. It's like drawing an empty draw call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, added an 'if unlikely" for the empty draw call case.

}
buffers.push_back(buffer);
}
buffers.resize(bufferCount);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove the call to buffers.reserve here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, removed.

This includes changes to OpenGL, Metal, and Vulkan backends.

At the backend level, vertex buffers are now always composed of buffer
objects. This lets us simplify the Driver API and some bookkeeping in
the backends.

This change also splits MAX_VERTEX_ATTRIBUTE_COUNT into two constants
because the maximum number of bound buffers is a separate concept from
the maximum number of attribute semantics (e.g. consider interleaving).
For now these two constants are set to the same value.

We also now store a byte count in HwBufferObject, which allows us to
remove the byte count from the Metal-specific handle, and to add some
asserts to debug builds to prevent size overflow.
@prideout prideout merged commit a67505b into main Apr 8, 2021
@prideout prideout deleted the pr/bocleanup branch April 8, 2021 16:56
prideout added a commit that referenced this pull request May 4, 2021
This leak was introduced in the following PR on April 7.
#3775

The guilty party has been contacted and properly admonished for his
transgression.
prideout added a commit that referenced this pull request May 4, 2021
This leak was introduced in the following PR on April 7.
#3775

The guilty party has been contacted and properly admonished for his
transgression.
prideout added a commit that referenced this pull request May 4, 2021
This leak was introduced in the following PR on April 7.
#3775

The guilty party has been contacted and properly admonished for his
transgression.

This was tested by adding the following code after applyAnimation in
gltf_viewer.cpp

        static int nframes = 0;
        if (!gpath.empty() && nframes++ > 100) {
            static int count = 0;
            printf("reloading %d\n", count++);
            nframes = 0;
            app.resourceLoader->asyncCancelLoad();
            app.resourceLoader->evictResourceData();
            app.viewer->removeAsset();
            app.assetLoader->destroyAsset(app.asset);
            loadAsset(gpath, app);
            loadResources(gpath, app);
        }
prideout added a commit that referenced this pull request May 5, 2021
This leak was introduced in the following PR on April 7.
#3775

The guilty party has been contacted and properly admonished for his
transgression.

This was tested by adding the following code after applyAnimation in
gltf_viewer.cpp

        static int nframes = 0;
        if (!gpath.empty() && nframes++ > 100) {
            static int count = 0;
            printf("reloading %d\n", count++);
            nframes = 0;
            app.resourceLoader->asyncCancelLoad();
            app.resourceLoader->evictResourceData();
            app.viewer->removeAsset();
            app.assetLoader->destroyAsset(app.asset);
            loadAsset(gpath, app);
            loadResources(gpath, app);
        }
prideout added a commit that referenced this pull request May 5, 2021
This leak was introduced in the following PR on April 7.
#3775

The guilty party has been contacted and properly admonished for his
transgression.

This was tested by adding the following code after applyAnimation in
gltf_viewer.cpp

        static int nframes = 0;
        if (!gpath.empty() && nframes++ > 100) {
            static int count = 0;
            printf("reloading %d\n", count++);
            nframes = 0;
            app.resourceLoader->asyncCancelLoad();
            app.resourceLoader->evictResourceData();
            app.viewer->removeAsset();
            app.assetLoader->destroyAsset(app.asset);
            loadAsset(gpath, app);
            loadResources(gpath, app);
        }
elisemorysc pushed a commit to elisemorysc/filament that referenced this pull request May 5, 2021
This leak was introduced in the following PR on April 7.
google#3775

The guilty party has been contacted and properly admonished for his
transgression.

This was tested by adding the following code after applyAnimation in
gltf_viewer.cpp

        static int nframes = 0;
        if (!gpath.empty() && nframes++ > 100) {
            static int count = 0;
            printf("reloading %d\n", count++);
            nframes = 0;
            app.resourceLoader->asyncCancelLoad();
            app.resourceLoader->evictResourceData();
            app.viewer->removeAsset();
            app.assetLoader->destroyAsset(app.asset);
            loadAsset(gpath, app);
            loadResources(gpath, app);
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants