Skip to content

Commit 23e9538

Browse files
mvaligurskyMartin Valigursky
andauthored
Fix canvas texture dimension mismatch causing texture upload to not work on WebGPU (#8113)
Co-authored-by: Martin Valigursky <[email protected]>
1 parent 29ad3a4 commit 23e9538

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/platform/graphics/webgpu/webgpu-texture.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,19 @@ class WebgpuTexture {
297297
uploadData(device) {
298298

299299
const texture = this.texture;
300+
301+
// If texture dimensions have changed, recreate the GPU texture (for example loading external texture
302+
// with different dimensions)
303+
if (this.desc && (this.desc.size.width !== texture.width || this.desc.size.height !== texture.height)) {
304+
Debug.warnOnce(`Texture '${texture.name}' is being recreated due to dimension change from ${this.desc.size.width}x${this.desc.size.height} to ${texture.width}x${texture.height}. Consider creating the texture with correct dimensions to avoid recreation.`);
305+
306+
this.gpuTexture.destroy();
307+
this.create(device);
308+
309+
// Notify bind groups that this texture has changed and needs rebinding
310+
texture.renderVersionDirty = device.renderVersion;
311+
}
312+
300313
if (texture._levels) {
301314

302315
// upload texture data if any
@@ -421,7 +434,8 @@ class WebgpuTexture {
421434
texture: this.gpuTexture,
422435
mipLevel: mipLevel,
423436
origin: [0, 0, index],
424-
aspect: 'all' // can be: "all", "stencil-only", "depth-only"
437+
aspect: 'all', // can be: "all", "stencil-only", "depth-only"
438+
premultipliedAlpha: this.texture._premultiplyAlpha
425439
};
426440

427441
const copySize = {

0 commit comments

Comments
 (0)