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

WebGPURenderer: Use renderBundles for repeated mipmap creation. #29197

Merged
merged 4 commits into from
Aug 22, 2024

Conversation

aardgoose
Copy link
Contributor

The example webgpu_backdrop_area requires regeneration of a texture mipmap for each frame, using bundles allows the overhead to be reduced.

The renderBundles are only cached when a texture is mipmapped more than once.

Copy link

github-actions bot commented Aug 21, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
685.4 kB (169.7 kB) 685.4 kB (169.7 kB) +0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize dev Filesize PR Diff
462 kB (111.4 kB) 462 kB (111.4 kB) +0 B

@sunag sunag merged commit 09430e8 into mrdoob:dev Aug 22, 2024
12 checks passed
@aardgoose aardgoose deleted the mip-bundle branch August 23, 2024 10:22
@RenaudRohlinger
Copy link
Collaborator

@aardgoose After I saw this PR I was wondering, since WebGPU doesn't have a multidraw API like WebGL as RenderBundles are basically the same thing, could we update the BatchedMesh part of the WebGPUBackend with renderBundle?

So that this part would be bundled OOTB:

if ( object.isBatchedMesh === true ) {

	const starts = object._multiDrawStarts;
	const counts = object._multiDrawCounts;
	const drawCount = object._multiDrawCount;
	const drawInstances = object._multiDrawInstances;

	const bytesPerElement = hasIndex ? index.array.BYTES_PER_ELEMENT : 1;

	for ( let i = 0; i < drawCount; i ++ ) {

		const count = drawInstances ? drawInstances[ i ] : 1;
		const firstInstance = count > 1 ? 0 : i;

		passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / bytesPerElement, 0, firstInstance );

	}

}

@aardgoose
Copy link
Contributor Author

I'm not sure it is worth it yet, I looked at the chromium/dawn issue log and it appears the multidraw has been implemented in Dawn for D3D12 and Vulkan backends, but not Metal yet. So it looks like it will appear in Chrome, although when is not know of course.

Although could you take it one step further and use multiple drawIndirect() with the a single indirect buffer mapped at different offsets at for each call, so you could try gpu compute directed rendering? That way you could get more of the benefits of multidraw and make it more worthwhile?

@RenaudRohlinger
Copy link
Collaborator

I like the idea a lot. I guess it's time to work on [WebGPU] drawIndirect and drawIndexedIndirect ^^.

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.

4 participants