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

"copyTextureToTexture" for webGPU #27859

Closed
Spiri0 opened this issue Mar 2, 2024 · 2 comments
Closed

"copyTextureToTexture" for webGPU #27859

Spiri0 opened this issue Mar 2, 2024 · 2 comments
Labels
Milestone

Comments

@Spiri0
Copy link
Contributor

Spiri0 commented Mar 2, 2024

Description

In webGL I can insert a texture into another texture. This can be done in webGL with texSubImage2D. Three.js has a wrapper function for this called copyTextureToTexture().

In webGL:
renderer.copyTextureToTexture(new THREE.Vector2(x, y), srcTexture, targetTexture);

Interestingly, in webGPU the analogous function is called exactly the same as the three.js wrapper for the webGL variant.

webGPU_capabilities

In three.js WebGPUBackend.js the webGPU function is already used, but only within the wrapper copyFramebufferToTexture(). Or am I missing something?

Solution

In itself a simple point, please just make the webGPU function copyTextureToTexture available as such in an analog wrapper like in webGL.

In webGL available:
renderer.copyTextureToTexture(new THREE.Vector2(x, y), srcTexture, targetTexture);

My wish for webGPU:
renderer.copyTextureToTexture(new THREE.Vector2(x, y), srcTexture, targetTexture);

Alternatives

There is probably no alternative to this because it is a very specific functionality. But fortunately it is a simple topic

Additional context

I developed a virtual texture system in three.js. However, only for webGL and I would like to have that in webGPU too. Together with my CDLOD system, I could use it to create huge landscapes in a very resource-efficient way. Three.js rocks 🤩

@Mugen87 Mugen87 added the WebGPU label Mar 3, 2024
@Spiri0
Copy link
Contributor Author

Spiri0 commented Mar 9, 2024

I'm trying to better understand three.js at its core. Over time, there will be some WebGPU functions in three.js that will need to be implemented. And if I learn how three.js works, I can also actively support the project.
These are my thoughts so far. I don't yet understand how the renderContext works, but maybe this will help you developers a little with the implementation.

//In usercode

renderer.copyTextureToTexture(new THREE.Vector2(x, y), srcTexture, dstTexture);




//In jsm/renderers/common/Renderer.js

copyTextureToTexture( position, level = 0, srcTexture, dstTexture ) {

	const renderContext = this._currentRenderContext;

	this.backend.copyTextureToTexture( position, level, srcTexture, dstTexture, renderContext );
}




//In jsm/renderers/common/webgpu/WebGPUBackend.js

copyTextureToTexture( position, level, srcTexture, dstTexture, renderContext ) {

	const renderContextData = this.get( renderContext );

	const { encoder, descriptor } = renderContextData;


	encoder.copyTextureToTexture(
		{
			texture: ...
			origin: { x: , y: , z:  }
		},
		{
			texture: ...
		},
		[
			texture.image.width,
			texture.image.height
		]
	);
}

@RenaudRohlinger
Copy link
Collaborator

Thanks for the exploration. I will give it a try today 👍

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

No branches or pull requests

4 participants