Restore the main pass state when rendering a 3D sub-scene


QQuick3DSceneRenderer::renderToRhiTexture() sets the main render pass
descriptor, render target, command buffer and sample count on the shared
QSSGRhiContext and leaves them there. That is a problem when it runs in
the middle of another View3D's frame, which happens when an Item2D or a
layer in the outer scene contains a View3D: the Item2D pass prepares
the 2D scene inline, the scenegraph's preprocess step renders the nested
View3D, and the outer View3D then continues with its remaining prepare
passes using the nested View3D's state.

The transparent pass is prepared after the Item2D pass, so its graphics
pipelines were created for the nested View3D's texture format and sample
count. Rendering with them into the outer view's render target is
undefined. It is enough that the outer view uses MSAA and the nested one
does not for Metal API validation to abort on the first blended draw of
the outer scene:

    For color attachment 0, the texture sample count (4) does not match
    the renderPipelineState colorSampleCount (1).

On visionOS the mismatch is there without anyone asking for MSAA, as the
compositor layer is RGBA16Float while the nested View3D renders to RGBA8
with 4x MSAA. That is what made everything behind the windshield of the
Outrun demo come out as posterized garbage.

The renderer already saves and restores its own viewport, scissor and
device pixel ratio around a 2D sub-scene, in QSSGLayerRenderData's
SavedRenderState, for exactly the same reason. Extend that with the main
pass state on the rhi context rather than adding a second mechanism
elsewhere, so the outer View3D's passes see the state that was set up
for them.

Pick-to: 6.12
Change-Id: I1d8f8fe2a9ed946b6aa09cf936258b8ef58219b4
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
commit3d2e4cb7a6705a42cf1b13b5f74881824b7d3ce2
parent08d9c296e004816a735de68f77d0fb56e97250ae
authorChristian Strømme <christian.stromme@qt.io>
committerChristian Strømme <christian.stromme@qt.io>
commit timeTue, 13 Oct 2026 19:37:08 +0000