GPUOpen-Effects / FidelityFX-FSR-Unity-URP

FidelityFX FSR 1.0 for the Unity URP
MIT License
104 stars 21 forks source link

Single pass stereo support? #5

Open Wully616 opened 2 years ago

Wully616 commented 2 years ago

I have modified PostProcessPass.RenderFinalPass to add in the FSR calls to the XR Module block

I'm getting an error with the compute shaders Compute shader (RobustContrastAdaptiveSharpen): Property (_RCASInputTexture) at kernel index (0) has mismatching texture dimension (expected 2, got 5)

Compute shader (EdgeAdaptiveSpatialUpsampling): Property (_EASUInputTexture) at kernel index (0) has mismatching texture dimension (expected 2, got 5)

I suspect its due to using Single pass stereo, is there any way to add support for that?

#if ENABLE_VR && ENABLE_XR_MODULE
            if (cameraData.xr.enabled)
            {
                RenderTargetIdentifier cameraTarget = cameraTargetHandle.Identifier();

                //Blit(cmd, m_Source.Identifier(), BuiltinRenderTextureType.CurrentActive, material);
                bool isRenderToBackBufferTarget = cameraTarget == cameraData.xr.renderTarget && !cameraData.xr.renderTargetIsRenderTexture;
                // We y-flip if
                // 1) we are bliting from render texture to back buffer and
                // 2) renderTexture starts UV at top
                bool yflip = isRenderToBackBufferTarget && SystemInfo.graphicsUVStartsAtTop;

                Vector4 scaleBias = yflip ? new Vector4(1, -1, 0, 1) : new Vector4(1, 1, 0, 0);

                var xrTarget = new RenderTargetIdentifier(cameraTarget, 0, CubemapFace.Unknown, -1);

                var oldCameraTarget = xrTarget;
                var enableFSR = cameraData.enableFSR;
                if ( enableFSR )
                {
                    oldCameraTarget = xrTarget;
                    cmd.GetTemporaryRT(ShaderConstants._EASUInputTexture, GetCompatibleDescriptor());
                    xrTarget = ShaderConstants._EASUInputTexture;
                }

                cmd.SetRenderTarget(xrTarget, colorLoadAction, RenderBufferStoreAction.Store, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.DontCare);

                if ( !enableFSR )
                    cmd.SetViewport(cameraData.pixelRect);
                cmd.SetGlobalVector(ShaderPropertyId.scaleBias, scaleBias);
                cmd.DrawProcedural(Matrix4x4.identity, material, 0, MeshTopology.Quads, 4, 1, null);
                if ( enableFSR )
                    DoFSR(cmd, ref cameraData, oldCameraTarget);
            }
            else
#endif
francisjsun-amd commented 2 years ago

Hi @Wully616 Sure. As your error messages point out, the_EASUInputTexture is not correct. I guess it's because the single pass stereo uses the packed render texture, you can't use it as _EASUInputTexture directly. Fetching the texture with the normal UV will not be right. You can try adding the UnityStereoScreenSpaceUVAdjust where the _EASUInputTexture gets fetched.