Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement robust dynamic memory #181

Merged
merged 5 commits into from
Jul 14, 2022
Merged

Implement robust dynamic memory #181

merged 5 commits into from
Jul 14, 2022

Conversation

raphlinus
Copy link
Contributor

This is the core logic for robust dynamic memory. There are changes to both shaders and the driver logic.

On the shader side, failure information is more useful and fine grained. In particular, it now reports which stage failed and how much memory would have been required to make that stage succeed.

On the driver side, there is a new RenderDriver abstraction which owns command buffers (and associated query pools) and runs the logic to retry and reallocate buffers when necessary. There's also a fairly significant rework of the logic to produce the config block, as that overlaps the robust memory.

The RenderDriver abstraction may not stay. It was done this way to minimize code disruption, but arguably it should just be combined with Renderer.

Another change: the GLSL length() method on a buffer requires additional infrastructure (at least on Metal, where it needs a binding of its own), so we now pass that in as a field in the config.

This also moves blend memory to its own buffer. This worked out well because coarse rasterization can simply report the size of the blend buffer and it can be reallocated without needing to rerun the pipeline. In the previous state, blend allocations and ptcl writes were interleaved in coarse rasterization, so a failure of the former would require rerunning coarse. This should fix #83 (finally!)

There are a few loose ends. The binaries haven't (yet) been updated (I've been testing using a hand-written test program). Gradients weren't touched so still have a fixed size allocation. And the logic to calculate the new buffer size on allocation failure could be smarter.

Closes #175

@raphlinus
Copy link
Contributor Author

Also note: this commit doesn't include generated shaders. We should land #178 and #179 then PR this against dev. But I wanted to get a draft out there to look at.

Base automatically changed from desc_update to master July 11, 2022 15:28
@raphlinus raphlinus changed the base branch from main to dev July 13, 2022 19:32
This is the core logic for robust dynamic memory. There are changes to both shaders and the driver logic.

On the shader side, failure information is more useful and fine grained. In particular, it now reports which stage failed and how much memory would have been required to make that stage succeed.

On the driver side, there is a new RenderDriver abstraction which owns command buffers (and associated query pools) and runs the logic to retry and reallocate buffers when necessary. There's also a fairly significant rework of the logic to produce the config block, as that overlaps the robust memory.

The RenderDriver abstraction may not stay. It was done this way to minimize code disruption, but arguably it should just be combined with Renderer.

Another change: the GLSL length() method on a buffer requires additional infrastructure (at least on Metal, where it needs a binding of its own), so we now pass that in as a field in the config.

This also moves blend memory to its own buffer. This worked out well because coarse rasterization can simply report the size of the blend buffer and it can be reallocated without needing to rerun the pipeline. In the previous state, blend allocations and ptcl writes were interleaved in coarse rasterization, so a failure of the former would require rerunning coarse. This should fix #83 (finally!)

There are a few loose ends. The binaries haven't (yet) been updated (I've been testing using a hand-written test program). Gradients weren't touched so still have a fixed size allocation. And the logic to calculate the new buffer size on allocation failure could be smarter.

Closes #175
raphlinus and others added 2 commits July 13, 2022 17:01
Also change command line binaries to use new abstraction.
Makes the changes work on Windows and Android.
@raphlinus raphlinus marked this pull request as ready for review July 14, 2022 00:45
@raphlinus
Copy link
Contributor Author

Marking this as ready for review, as the command line drivers are updated. No changes have been made to pgpu_render, so hopefully that'll continue as before (requiring pre-allocation of adequate buffers).

@raphlinus raphlinus requested a review from dfrg July 14, 2022 00:46
Copy link
Collaborator

@dfrg dfrg left a comment

Choose a reason for hiding this comment

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

I've gone through this several times now and aside from some potential resource management improvements that have already been discussed (and that are marked in the code with comments), nothing stands out as needing attention. This is a huge step forward for the project-- let's get it merged :)

@raphlinus raphlinus merged commit bfa4abf into dev Jul 14, 2022
@raphlinus raphlinus deleted the mem2 branch July 14, 2022 14:27
@eliasnaur
Copy link
Collaborator

Was shader/image.png intentionally checked in? I couldn't find a reference to it in the PR.

@raphlinus
Copy link
Contributor Author

Nope, that was by mistake. We'll remove it in a cleanup, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants