Skip to content

Commit 2b5ea30

Browse files
authored
Renderer: Fix transmission flicker. (#32043)
1 parent 2cfd573 commit 2b5ea30

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

src/renderers/webgpu/WebGPUBackend.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,7 @@ class WebGPUBackend extends Backend {
777777

778778
if ( renderContext.scissor ) {
779779

780-
const { x, y, width, height } = renderContext.scissorValue;
781-
currentPass.setScissorRect( x, y, width, height );
780+
this.updateScissor( renderContext );
782781

783782
}
784783

@@ -1138,6 +1137,20 @@ class WebGPUBackend extends Backend {
11381137

11391138
}
11401139

1140+
/**
1141+
* Updates the scissor with the values from the given render context.
1142+
*
1143+
* @param {RenderContext} renderContext - The render context.
1144+
*/
1145+
updateScissor( renderContext ) {
1146+
1147+
const { currentPass } = this.get( renderContext );
1148+
const { x, y, width, height } = renderContext.scissorValue;
1149+
1150+
currentPass.setScissorRect( x, y, width, height );
1151+
1152+
}
1153+
11411154
/**
11421155
* Returns the clear color and alpha into a single
11431156
* color object.
@@ -2401,6 +2414,15 @@ class WebGPUBackend extends Backend {
24012414
]
24022415
);
24032416

2417+
// mipmaps must be genereated with the same encoder otherwise the copied texture data
2418+
// might be out-of-sync, see #31768
2419+
2420+
if ( texture.generateMipmaps ) {
2421+
2422+
this.textureUtils.generateMipmaps( texture, encoder );
2423+
2424+
}
2425+
24042426
if ( renderContextData.currentPass ) {
24052427

24062428
const { descriptor } = renderContextData;
@@ -2425,9 +2447,7 @@ class WebGPUBackend extends Backend {
24252447

24262448
if ( renderContext.scissor ) {
24272449

2428-
const { x, y, width, height } = renderContext.scissorValue;
2429-
2430-
renderContextData.currentPass.setScissorRect( x, y, width, height );
2450+
this.updateScissor( renderContext );
24312451

24322452
}
24332453

@@ -2437,12 +2457,6 @@ class WebGPUBackend extends Backend {
24372457

24382458
}
24392459

2440-
if ( texture.generateMipmaps ) {
2441-
2442-
this.textureUtils.generateMipmaps( texture );
2443-
2444-
}
2445-
24462460
}
24472461

24482462
dispose() {

src/renderers/webgpu/utils/WebGPUTexturePassUtils.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,29 +310,27 @@ fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {
310310
* @param {GPUTexture} textureGPU - The GPU texture object.
311311
* @param {Object} textureGPUDescriptor - The texture descriptor.
312312
* @param {number} [baseArrayLayer=0] - The index of the first array layer accessible to the texture view.
313+
* @param {?GPUCommandEncoder} [encoder=null] - An optional command encoder used to generate mipmaps.
313314
*/
314-
generateMipmaps( textureGPU, textureGPUDescriptor, baseArrayLayer = 0 ) {
315+
generateMipmaps( textureGPU, textureGPUDescriptor, baseArrayLayer = 0, encoder = null ) {
315316

316317
const textureData = this.get( textureGPU );
317318

318-
if ( textureData.useCount === undefined ) {
319+
if ( textureData.layers === undefined ) {
319320

320-
textureData.useCount = 0;
321321
textureData.layers = [];
322322

323323
}
324324

325325
const passes = textureData.layers[ baseArrayLayer ] || this._mipmapCreateBundles( textureGPU, textureGPUDescriptor, baseArrayLayer );
326326

327-
const commandEncoder = this.device.createCommandEncoder( {} );
327+
const commandEncoder = encoder || this.device.createCommandEncoder( { label: 'mipmapEncoder' } );
328328

329329
this._mipmapRunBundles( commandEncoder, passes );
330330

331-
this.device.queue.submit( [ commandEncoder.finish() ] );
332-
333-
if ( textureData.useCount !== 0 ) textureData.layers[ baseArrayLayer ] = passes;
331+
if ( encoder === null ) this.device.queue.submit( [ commandEncoder.finish() ] );
334332

335-
textureData.useCount ++;
333+
textureData.layers[ baseArrayLayer ] = passes;
336334

337335
}
338336

src/renderers/webgpu/utils/WebGPUTextureUtils.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,16 +344,17 @@ class WebGPUTextureUtils {
344344
* Generates mipmaps for the given texture.
345345
*
346346
* @param {Texture} texture - The texture.
347+
* @param {?GPUCommandEncoder} [encoder=null] - An optional command encoder used to generate mipmaps.
347348
*/
348-
generateMipmaps( texture ) {
349+
generateMipmaps( texture, encoder = null ) {
349350

350351
const textureData = this.backend.get( texture );
351352

352353
if ( texture.isCubeTexture ) {
353354

354355
for ( let i = 0; i < 6; i ++ ) {
355356

356-
this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU, i );
357+
this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU, i, encoder );
357358

358359
}
359360

@@ -363,7 +364,7 @@ class WebGPUTextureUtils {
363364

364365
for ( let i = 0; i < depth; i ++ ) {
365366

366-
this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU, i );
367+
this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU, i, encoder );
367368

368369
}
369370

@@ -814,10 +815,11 @@ class WebGPUTextureUtils {
814815
* @param {GPUTexture} textureGPU - The GPU texture object.
815816
* @param {Object} textureDescriptorGPU - The texture descriptor.
816817
* @param {number} [baseArrayLayer=0] - The index of the first array layer accessible to the texture view.
818+
* @param {?GPUCommandEncoder} [encoder=null] - An optional command encoder used to generate mipmaps.
817819
*/
818-
_generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer = 0 ) {
820+
_generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer = 0, encoder = null ) {
819821

820-
this._getPassUtils().generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer );
822+
this._getPassUtils().generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer, encoder );
821823

822824
}
823825

0 commit comments

Comments
 (0)