-
-
Notifications
You must be signed in to change notification settings - Fork 423
Render pass teardown #3622
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
Open
Open
Render pass teardown #3622
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f1c8467
fix(OpenGL): release render pass resources on render window deletion
PaulHax 7cafe94
fix(VolumeMapper): release owned GPU objects on delete
PaulHax 05ce544
fix(RenderWindow): release render passes the window stops using
PaulHax 33803fb
fix(RenderWindow): free child window render passes on delete
PaulHax 269c2ac
fix(Convolution2DPass): reuse the vertex array across a kernel dimens…
PaulHax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Sources/Rendering/OpenGL/Convolution2DPass/test/testReleaseGraphicsResources.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { it, expect } from 'vitest'; | ||
| import testUtils from 'vtk.js/Sources/Testing/testUtils'; | ||
| import { | ||
| createConeActor, | ||
| createTrackedRenderView, | ||
| expectPassResourcesFreedOnDelete, | ||
| expectSameImageAfterPassRelease, | ||
| usePostProcessingPass, | ||
| } from 'vtk.js/Sources/Testing/renderTestUtils'; | ||
|
|
||
| import vtkConvolution2DPass from 'vtk.js/Sources/Rendering/OpenGL/Convolution2DPass'; | ||
|
|
||
| const createPass = (gc) => | ||
| gc.registerResource(vtkConvolution2DPass.newInstance()); | ||
|
|
||
| it.skipIf(__VTK_TEST_NO_WEBGL__)( | ||
| 'frees the convolution pass GPU objects when the view is deleted', | ||
| () => expectPassResourcesFreedOnDelete(createPass) | ||
| ); | ||
|
|
||
| it.skipIf(__VTK_TEST_NO_WEBGL__)( | ||
| 'draws the same image after the view releases its render pass resources', | ||
| () => expectSameImageAfterPassRelease(createPass) | ||
| ); | ||
|
|
||
| // A kernel of the given dimension that leaves the image untouched. | ||
| function identityKernel(dimension) { | ||
| const kernel = new Float32Array(dimension * dimension); | ||
| kernel[Math.floor(kernel.length / 2)] = 1; | ||
| return kernel; | ||
| } | ||
|
|
||
| it.skipIf(__VTK_TEST_NO_WEBGL__)( | ||
| 'frees the vertex array it rebuilds for a new kernel dimension', | ||
| () => { | ||
| const gc = testUtils.createGarbageCollector(); | ||
| const { tracker, renderer, renderWindow, view } = | ||
| createTrackedRenderView(gc); | ||
|
|
||
| const pass = usePostProcessingPass(gc, view, createPass); | ||
| renderer.addActor(createConeActor(gc)); | ||
| renderer.resetCamera(); | ||
| renderWindow.render(); | ||
| const objectsInUse = tracker.count(); | ||
|
|
||
| // A new dimension recompiles the shader, and the vertex array that feeds | ||
| // it has to be rebuilt against the new program rather than replaced. | ||
| pass.setKernelDimension(5); | ||
| pass.setKernel(identityKernel(5)); | ||
| renderWindow.render(); | ||
|
|
||
| expect(tracker.count()).toBe(objectsInUse); | ||
|
|
||
| gc.releaseResources(); | ||
| } | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
Sources/Rendering/OpenGL/ForwardPass/test/testReleaseGraphicsResources.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { it, expect } from 'vitest'; | ||
| import testUtils from 'vtk.js/Sources/Testing/testUtils'; | ||
| import { | ||
| createConeActor, | ||
| createTrackedRenderView, | ||
| } from 'vtk.js/Sources/Testing/renderTestUtils'; | ||
|
|
||
| import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor'; | ||
| import vtkConeSource from 'vtk.js/Sources/Filters/Sources/ConeSource'; | ||
| import vtkPixelSpaceCallbackMapper from 'vtk.js/Sources/Rendering/Core/PixelSpaceCallbackMapper'; | ||
|
|
||
| it.skipIf(__VTK_TEST_NO_WEBGL__)( | ||
| 'frees the translucent pass GPU objects when the view is deleted', | ||
| () => { | ||
| const gc = testUtils.createGarbageCollector(); | ||
| const { tracker, renderer, renderWindow, emptySceneObjects } = | ||
| createTrackedRenderView(gc); | ||
|
|
||
| renderer.addActor(createConeActor(gc, { opacity: 0.5 })); | ||
| renderer.resetCamera(); | ||
| renderWindow.render(); | ||
| expect(tracker.count()).toBeGreaterThan(emptySceneObjects); | ||
|
|
||
| gc.releaseResources(); | ||
| expect(tracker.count()).toBe(0); | ||
| } | ||
| ); | ||
|
|
||
| // Reading z values makes the forward pass capture a depth buffer, so this | ||
| // actor is what gives the pass a framebuffer of its own to hand out. | ||
| function createDepthReadingActor(gc, callback) { | ||
| const cone = gc.registerResource(vtkConeSource.newInstance()); | ||
| const mapper = gc.registerResource(vtkPixelSpaceCallbackMapper.newInstance()); | ||
| mapper.setInputConnection(cone.getOutputPort()); | ||
| mapper.setUseZValues(true); | ||
| mapper.setCallback(callback); | ||
| const actor = gc.registerResource(vtkActor.newInstance()); | ||
| actor.setMapper(mapper); | ||
| return actor; | ||
| } | ||
|
|
||
| it.skipIf(__VTK_TEST_NO_WEBGL__)( | ||
| 'draws the same image after the view releases its render pass resources', | ||
| async () => { | ||
| const gc = testUtils.createGarbageCollector(); | ||
| const { tracker, renderer, renderWindow, view, emptySceneObjects } = | ||
| createTrackedRenderView(gc); | ||
|
|
||
| let depthReads = 0; | ||
| renderer.addActor(createConeActor(gc, { opacity: 0.5 })); | ||
| renderer.addActor(createDepthReadingActor(gc, () => (depthReads += 1))); | ||
| renderer.resetCamera(); | ||
|
|
||
| const beforeRelease = view.captureNextImage(); | ||
| renderWindow.render(); | ||
| expect(tracker.count()).toBeGreaterThan(emptySceneObjects); | ||
| expect(depthReads).toBeGreaterThan(0); | ||
|
|
||
| const depthReadsBeforeRelease = depthReads; | ||
| view.releaseGraphicsResources(); | ||
|
|
||
| const afterRelease = view.captureNextImage(); | ||
| renderWindow.render(); | ||
| expect(await afterRelease).toBe(await beforeRelease); | ||
| expect(depthReads).toBeGreaterThan(depthReadsBeforeRelease); | ||
|
|
||
| gc.releaseResources(); | ||
| } | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Sources/Rendering/OpenGL/RadialDistortionPass/test/testReleaseGraphicsResources.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { it } from 'vitest'; | ||
| import { | ||
| expectPassResourcesFreedOnDelete, | ||
| expectSameImageAfterPassRelease, | ||
| } from 'vtk.js/Sources/Testing/renderTestUtils'; | ||
|
|
||
| import vtkRadialDistortionPass from 'vtk.js/Sources/Rendering/OpenGL/RadialDistortionPass'; | ||
|
|
||
| // A zero distortion pass is a no-op that never allocates. | ||
| const createPass = (gc) => { | ||
| const pass = gc.registerResource(vtkRadialDistortionPass.newInstance()); | ||
| pass.setK1(0.2); | ||
| return pass; | ||
| }; | ||
|
|
||
| it.skipIf(__VTK_TEST_NO_WEBGL__)( | ||
| 'frees the radial distortion pass GPU objects when the view is deleted', | ||
| () => expectPassResourcesFreedOnDelete(createPass) | ||
| ); | ||
|
|
||
| it.skipIf(__VTK_TEST_NO_WEBGL__)( | ||
| 'draws the same image after the view releases its render pass resources', | ||
| () => expectSameImageAfterPassRelease(createPass) | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the null check guards before calling release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tris is created in extend() and must remain available after releasing its GPU resources. The next render call expects
model.tristo exist. The flow:(and no need to null check model.copyShader before setting it to null)