RenderGraph Depth/Opaque Texture disabled Error
I am trying to update my project to use RenderGraph support for newer features being used by OpenXR. I have been using Shapes with RenderGraph disabled (Compatibility Mode) because Shapes was always throwing errors at me when using Immediate Mode drawing.
I took the time to make a new project using RenderGraph and implemented your sample IM drawing script, and too my surprise I didn't get the same errors I had in my project. After investigating I found the reason was the URPAsset between the 2 projects.
If both Depth Texture & Opaque Texture are disabled in the URPAsset and RenderGraph is enabled, Shapes will throw the following errors and then crash Unity:
NullReferenceException: Object reference not set to an instance of an object
Render Graph Execution error
InvalidOperationException: The CullingResults instance is no longer valid. This can happen if you re-use it across multiple frames.
I'll post the full log in the next comment.
My game targets the Meta Quest 3, and I need to have the Depth Texture & Opaque Texture disabled for performance reasons, and Shapes is heavily integrated into the game, I hope you can help me Freya!
[Exception] NullReferenceException: Object reference not set to an instance of an object
RenderGraphResourceRegistry.GetRenderTargetInfo() at ./Library/PackageCache/com.unity.render-pipelines.core@2be5e7224a10/Runtime/RenderGraph/RenderGraphResourceRegistry.cs:714
712: // Lots of legacy if's and but's
713: TextureResource tex = GetTextureResource(res);
--> 714: if (tex.imported)
715: {
716: // Imported, try to get back to the original handle we imported and get the properties from there
RenderGraphBuilders.CheckUseFragment() at ./Library/PackageCache/com.unity.render-pipelines.core@2be5e7224a10/Runtime/RenderGraph/RenderGraphBuilders.cs:355
353: }
--> 355: m_Resources.GetRenderTargetInfo(tex.handle, out var info);
357: // The old path is full of invalid uses that somehow work (or seemt to work) so we skip the tests if not using actual native renderpass
RenderGraphBuilders.SetRenderAttachment() at ./Library/PackageCache/com.unity.render-pipelines.core@2be5e7224a10/Runtime/RenderGraph/RenderGraphBuilders.cs:390
388: public void SetRenderAttachment(TextureHandle tex, int index, AccessFlags flags, int mipLevel, int depthSlice)
389: {
--> 390: CheckUseFragment(tex, false);
391: ResourceHandle result = UseResource(tex.handle, flags);
392: // Note the version for the attachments is a bit arbitrary so we just use the latest for now
IRasterRenderGraphBuilder.SetRenderAttachment() at ./Library/PackageCache/com.unity.render-pipelines.core@2be5e7224a10/Runtime/RenderGraph/IRenderGraphBuilder.cs:196
194: void SetRenderAttachment(TextureHandle tex, int index, AccessFlags flags = AccessFlags.Write)
195: {
--> 196: SetRenderAttachment(tex, index, flags, 0, -1);
197: }
ShapesRenderPass.RecordRenderGraph() at /Shapes/Scripts/Runtime/Immediate Mode/ShapesRenderPass.cs:44
42: builder.AllowPassCulling( false );
43: UniversalResourceData resourceData = frameData.Get();
--> 44: builder.SetRenderAttachment( resourceData.cameraColor, 0, AccessFlags.Write );
45: builder.SetRenderFunc(
46: ( PassData dataParam, RasterGraphContext context ) => {
ScriptableRenderer.RecordCustomRenderGraphPassesInEventRange() at ./Library/PackageCache/com.unity.render-pipelines.universal@a55da47cc43f/Runtime/ScriptableRenderer.cs:1247
1245: {
1246: if (pass.renderPassEvent >= eventStart && pass.renderPassEvent < eventEnd)
-->1247: pass.RecordRenderGraph(renderGraph, m_frameData);
1248: }
1249: }
ScriptableRenderer.RecordCustomRenderGraphPasses() at ./Library/PackageCache/com.unity.render-pipelines.universal@a55da47cc43f/Runtime/ScriptableRenderer.cs:1266
1264: int range = ScriptableRenderPass.GetRenderPassEventRange(endInjectionPoint);
-->1266: RecordCustomRenderGraphPassesInEventRange(renderGraph, startInjectionPoint, endInjectionPoint + range);
1267: }
ScriptableRenderer.RecordCustomRenderGraphPasses() at ./Library/PackageCache/com.unity.render-pipelines.universal@a55da47cc43f/Runtime/ScriptableRenderer.cs:1271
1269: internal void RecordCustomRenderGraphPasses(RenderGraph renderGraph, RenderPassEvent injectionPoint)
1270: {
-->1271: RecordCustomRenderGraphPasses(renderGraph, injectionPoint, injectionPoint);
1272: }
UniversalRenderer.OnAfterRendering() at ./Library/PackageCache/com.unity.render-pipelines.universal@a55da47cc43f/Runtime/UniversalRendererRenderGraph.cs:1433
1431: DrawRenderGraphGizmos(renderGraph, frameData, resourceData.activeColorTexture, resourceData.activeDepthTexture, GizmoSubset.PreImageEffects);
-->1433: RecordCustomRenderGraphPasses(renderGraph, RenderPassEvent.BeforeRenderingPostProcessing);
1435: bool cameraTargetResolved = false;
UniversalRenderer.OnRecordRenderGraph() at ./Library/PackageCache/com.unity.render-pipelines.universal@a55da47cc43f/Runtime/UniversalRendererRenderGraph.cs:804
802: OnMainRendering(renderGraph, context);
--> 804: OnAfterRendering(renderGraph);
806: EndRenderGraphXRRendering(renderGraph);
ScriptableRenderer.RecordRenderGraph() at ./Library/PackageCache/com.unity.render-pipelines.universal@a55da47cc43f/Runtime/ScriptableRenderer.cs:1200
1198: using (new ProfilingScope(Profiling.recordRenderGraph))
1199: {
-->1200: OnRecordRenderGraph(renderGraph, context);
1201: }
UniversalRenderPipeline.RecordRenderGraph() at ./Library/PackageCache/com.unity.render-pipelines.universal@a55da47cc43f/Runtime/UniversalRenderPipelineRenderGraph.cs:10
8: static void RecordRenderGraph(RenderGraph renderGraph, ScriptableRenderContext context, ScriptableRenderer renderer)
9: {
--> 10: renderer.RecordRenderGraph(renderGraph, context);
11: }
UniversalRenderPipeline.RecordAndExecuteRenderGraph() at ./Library/PackageCache/com.unity.render-pipelines.universal@a55da47cc43f/Runtime/UniversalRenderPipelineRenderGraph.cs:24
23: renderGraph.BeginRecording(rgParams);
--> 24: RecordRenderGraph(renderGraph, context, renderer);
25: renderGraph.EndRecordingAndExecute();
26: }
UniversalRenderPipeline.RenderSingleCamera() at ./Library/PackageCache/com.unity.render-pipelines.universal@a55da47cc43f/Runtime/UniversalRenderPipeline.cs:855
853: if (useRenderGraph)
854: {
--> 855: RecordAndExecuteRenderGraph(s_RenderGraph, context, renderer, cmd, cameraData.camera, cameraMetadata.name);
856: renderer.FinishRenderGraphRendering(cmd);
857: }
UniversalRenderPipeline.RenderSingleCameraInternal() at ./Library/PackageCache/com.unity.render-pipelines.universal@a55da47cc43f/Runtime/UniversalRenderPipeline.cs:688
686: #endif
--> 688: RenderSingleCamera(context, cameraData);
689: }
UniversalRenderPipeline.RenderSingleCameraInternal() at ./Library/PackageCache/com.unity.render-pipelines.universal@a55da47cc43f/Runtime/UniversalRenderPipeline.cs:663
661: camera.gameObject.TryGetComponent(out additionalCameraData);
--> 663: RenderSingleCameraInternal(context, camera, ref additionalCameraData, isLastBaseCamera);
664: }
UniversalRenderPipeline.Render() at ./Library/PackageCache/com.unity.render-pipelines.universal@a55da47cc43f/Runtime/UniversalRenderPipeline.cs:480
478: UpdateVolumeFramework(camera, null);
--> 480: RenderSingleCameraInternal(renderContext, camera, isLastBaseCamera);
481: }
482: }
RenderPipeline.InternalRender() at <575c8d5d94a9444f82eba927ac72f8df>:0
RenderPipelineManager.DoRenderLoop_Internal() at <575c8d5d94a9444f82eba927ac72f8df>:0
GUIUtility.ProcessEvent()