ndepoel / FSR3Unity

FSR 3.1 Upscaler integration for Unity built-in render pipeline, with support for DX11, Mac, Linux and consoles.
https://discussions.unity.com/t/open-source-fidelityfx-super-resolution-3-1-fsr3-upscaler-for-unity-birp-dx11-ppv2-hdrp17-multi-platform/917847
MIT License
251 stars 30 forks source link

black screen #19

Open AIMTeam-Lmb opened 2 months ago

AIMTeam-Lmb commented 2 months ago

My unity 2020.3.38f1 Removed previous FSR2, installed FSR3.1 Everything works correctly in the Unity editor. Development build = correct. Without the "Development build" checkbox, only the UI is displayed, the rest of the screen is black.

In real time, I turn off FSR, everything works correctly. I turn on FSR again, black screen. I do FSR via PostProcess and just hang the FSR3 script, in both cases, a black screen and a memory leak occurs. I changed various FSR settings, nothing works.

The error that I caught in the build:

ArgumentNullException: Value cannot be null. Parameter name: sampler UnityEngine.Rendering.CommandBuffer.BeginSample (UnityEngine.Profiling.CustomSampler sampler) (at <966ecbc21bec4138a5192b5e1b2dd41f>:0) FidelityFX.FSR3.Fsr3UpscalerPass.ScheduleDispatch (UnityEngine.Rendering.CommandBuffer commandBuffer, FidelityFX.FSR3.Fsr3Upscaler+DispatchDescription dispatchParams, System.Int32 frameIndex, System.Int32 dispatchX, System.Int32 dispatchY) (at <8cac5cb91d8245779384d224056738f9>:0) FidelityFX.FSR3.Fsr3UpscalerContext.Dispatch (FidelityFX.FSR3.Fsr3Upscaler+DispatchDescription dispatchParams, UnityEngine.Rendering.CommandBuffer commandBuffer) (at <8cac5cb91d8245779384d224056738f9>:0) UnityEngine.Rendering.PostProcessing.SuperResolution.Render (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) (at :0) UnityEngine.Rendering.PostProcessing.PostProcessLayer.Render (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) (at :0) UnityEngine.Rendering.PostProcessing.PostProcessLayer.BuildCommandBuffers () (at :0) UnityEngine.Rendering.PostProcessing.PostProcessLayer.OnPreCull () (at :0)

ndepoel commented 2 months ago

Hi, thanks for your report. I was able to reproduce your problem using Unity 2020.x and it seems to be isolated to that version of Unity, as from 2021.x onward things are fine. It's a bit weird though because just looking at Unity's code and the implementation of CustomSampler, there's no reason why this should cause an ArgumentNullException in non-development builds. Probably a compiler bug that got resolved in Unity 2021.

For the time being you can work around the issue by surrounding the calls to BeginSample and EndSample in Fsr3UpscalerPass.cs with #if ENABLE_PROFILER blocks, like so:

        public void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
        {
        #if ENABLE_PROFILER
            commandBuffer.BeginSample(Sampler);
        #endif
            DoScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchX, dispatchY);
        #if ENABLE_PROFILER
            commandBuffer.EndSample(Sampler);
        #endif
        }

and further down in the Fsr3UpscalerGenerateReactivePass class:

        public void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.GenerateReactiveDescription dispatchParams, int dispatchX, int dispatchY)
        {
        #if ENABLE_PROFILER
            commandBuffer.BeginSample(Sampler);
        #endif

            ref var opaqueOnly = ref dispatchParams.ColorOpaqueOnly;
            ref var color = ref dispatchParams.ColorPreUpscale;
            ref var reactive = ref dispatchParams.OutReactive;

            commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvOpaqueOnly, opaqueOnly.RenderTarget, opaqueOnly.MipLevel, opaqueOnly.SubElement);
            commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement);
            commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavAutoReactive, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement);

            commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbGenReactive, _generateReactiveConstants, 0, Marshal.SizeOf<Fsr3Upscaler.GenerateReactiveConstants>());

            commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);

        #if ENABLE_PROFILER
            commandBuffer.EndSample(Sampler);
        #endif
        }

I'll try to come up with a more elegant solution for this problem in the meantime.