@@ -235,6 +235,15 @@ class WebgpuRenderTarget {
235235 }
236236 }
237237
238+ /**
239+ * @param {WebgpuGraphicsDevice } device - The graphics device.
240+ * @returns {number } Number of array layers rendered by a native view-instanced backbuffer pass.
241+ * @private
242+ */
243+ getViewCount ( device ) {
244+ return this . isBackbuffer && device . xrNativeViewInstancing ? device . xrViewCount : 1 ;
245+ }
246+
238247 /**
239248 * Initialize render target for rendering one time.
240249 *
@@ -277,6 +286,13 @@ class WebgpuRenderTarget {
277286
278287 this . updateKey ( ) ;
279288
289+ const viewCount = this . getViewCount ( device ) ;
290+ if ( viewCount > 1 ) {
291+ this . renderPassDescriptor . viewCount = viewCount ;
292+ } else {
293+ delete this . renderPassDescriptor . viewCount ;
294+ }
295+
280296 this . initialized = true ;
281297
282298 WebgpuDebug . end ( device , 'RenderTarget initialization' , { renderTarget } ) ;
@@ -286,6 +302,12 @@ class WebgpuRenderTarget {
286302 initDepthStencil ( device , wgpu , renderTarget ) {
287303
288304 const { samples, width, height, depth, depthBuffer } = renderTarget ;
305+ const viewCount = this . getViewCount ( device ) ;
306+ const viewDesc = viewCount > 1 ? {
307+ dimension : '2d-array' ,
308+ baseArrayLayer : 0 ,
309+ arrayLayerCount : viewCount
310+ } : undefined ;
289311
290312 // depth buffer that we render to (single or multi-sampled). We don't create resolve
291313 // depth buffer as we don't currently resolve it. This might need to change in the future.
@@ -302,7 +324,7 @@ class WebgpuRenderTarget {
302324
303325 /** @type {GPUTextureDescriptor } */
304326 const depthTextureDesc = {
305- size : [ width , height , 1 ] ,
327+ size : [ width , height , viewCount ] ,
306328 dimension : '2d' ,
307329 sampleCount : samples ,
308330 format : this . depthAttachment . format ,
@@ -325,7 +347,7 @@ class WebgpuRenderTarget {
325347 this . depthAttachment . depthTexture = depthTexture ;
326348 this . depthAttachment . depthTextureInternal = true ;
327349
328- renderingView = depthTexture . createView ( ) ;
350+ renderingView = depthTexture . createView ( viewDesc ) ;
329351 DebugHelper . setLabel ( renderingView , `${ renderTarget . name } .autoDepthView` ) ;
330352
331353 } else { // use provided depth buffer
@@ -341,7 +363,7 @@ class WebgpuRenderTarget {
341363 this . depthAttachment . hasStencil = depthFormat === 'depth24plus-stencil8' ;
342364
343365 // key for matching multi-sampled depth buffer
344- const key = `${ depthBuffer . id } :${ width } :${ height } :${ samples } :${ depthFormat } ` ;
366+ const key = `${ depthBuffer . id } :${ width } :${ height } :${ viewCount } : ${ samples } :${ depthFormat } ` ;
345367
346368 // check if we have already allocated a multi-sampled depth buffer for the depth buffer
347369 const msTextures = getMultisampledTextureCache ( device ) ;
@@ -350,7 +372,7 @@ class WebgpuRenderTarget {
350372
351373 /** @type {GPUTextureDescriptor } */
352374 const multisampledDepthDesc = {
353- size : [ width , height , 1 ] ,
375+ size : [ width , height , viewCount ] ,
354376 dimension : '2d' ,
355377 sampleCount : samples ,
356378 format : depthFormat ,
@@ -370,7 +392,7 @@ class WebgpuRenderTarget {
370392 this . depthAttachment . multisampledDepthBuffer = msDepthTexture ;
371393 this . depthAttachment . multisampledDepthBufferKey = key ;
372394
373- renderingView = msDepthTexture . createView ( ) ;
395+ renderingView = msDepthTexture . createView ( viewDesc ) ;
374396 DebugHelper . setLabel ( renderingView , `${ renderTarget . name } .multisampledDepthView` ) ;
375397
376398 } else {
@@ -379,7 +401,7 @@ class WebgpuRenderTarget {
379401 const depthTexture = depthBuffer . impl . gpuTexture ;
380402 this . depthAttachment . depthTexture = depthTexture ;
381403
382- renderingView = depthTexture . createView ( ) ;
404+ renderingView = depthTexture . createView ( viewDesc ) ;
383405 DebugHelper . setLabel ( renderingView , `${ renderTarget . name } .depthView` ) ;
384406 }
385407 }
@@ -409,6 +431,12 @@ class WebgpuRenderTarget {
409431
410432 const { samples, width, height, mipLevel } = renderTarget ;
411433 const colorBuffer = renderTarget . getColorBuffer ( index ) ;
434+ const viewCount = this . getViewCount ( device ) ;
435+ const viewDesc = viewCount > 1 ? {
436+ dimension : '2d-array' ,
437+ baseArrayLayer : 0 ,
438+ arrayLayerCount : viewCount
439+ } : undefined ;
412440
413441 // view used to write to the color buffer (either by rendering to it, or resolving to it)
414442 let colorView = null ;
@@ -446,7 +474,7 @@ class WebgpuRenderTarget {
446474
447475 /** @type {GPUTextureDescriptor } */
448476 const multisampledTextureDesc = {
449- size : [ width , height , 1 ] ,
477+ size : [ width , height , viewCount ] ,
450478 dimension : '2d' ,
451479 sampleCount : samples ,
452480 format : format ,
@@ -458,7 +486,7 @@ class WebgpuRenderTarget {
458486 DebugHelper . setLabel ( multisampledColorBuffer , `${ renderTarget . name } .multisampledColor` ) ;
459487 this . setColorAttachment ( index , multisampledColorBuffer , multisampledTextureDesc . format ) ;
460488
461- colorAttachment . view = multisampledColorBuffer . createView ( ) ;
489+ colorAttachment . view = multisampledColorBuffer . createView ( viewDesc ) ;
462490 DebugHelper . setLabel ( colorAttachment . view , `${ renderTarget . name } .multisampledColorView` ) ;
463491
464492 colorAttachment . resolveTarget = colorView ;
0 commit comments