Skip to content

Commit f7e8344

Browse files
alexey-zakharovEvergreen
authored andcommitted
Profiler/renderpipeline/stage 5 remaining
1 parent 4b6ea83 commit f7e8344

9 files changed

Lines changed: 54 additions & 12 deletions

File tree

Packages/com.unity.render-pipelines.core/Runtime/Debugging/ProfilingScope.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public ProfilingScope(ProfilingSampler sampler)
392392
/// with this sample. The Profiler displays it in the sample hierarchy.</param>
393393
[MethodImpl(MethodImplOptions.AggressiveInlining | (MethodImplOptions)512)]
394394
public ProfilingScope(ProfilingSampler sampler, Object contextObject)
395-
: this(null, sampler, contextObject)
395+
: this((CommandBuffer)null, sampler, contextObject)
396396
{
397397
}
398398

@@ -458,6 +458,26 @@ public ProfilingScope(BaseCommandBuffer cmd, ProfilingSampler sampler)
458458
#endif
459459
}
460460

461+
/// <summary>
462+
/// Creates a profiling scope that records markers into <paramref name="cmd"/> as well as inline on the CPU,
463+
/// and associates a Unity Object with the sample for identification in the Profiler.
464+
/// </summary>
465+
/// <remarks>
466+
/// Do not use with a named <see cref="CommandBuffer"/>. A named command buffer inserts its own
467+
/// scope marker on execution, which orphans the markers added here: the begin and end appear
468+
/// inside different named-buffer execution brackets and will be mismatched in the Profiler timeline.
469+
/// </remarks>
470+
/// <param name="cmd">BaseCommandBuffer (e.g. RasterCommandBuffer, UnsafeCommandBuffer) to receive the GPU-visible begin/end markers.</param>
471+
/// <param name="sampler">The sampler that provides the underlying marker.
472+
/// May be <c>null</c>; the scope is a no-op in that case.</param>
473+
/// <param name="contextObject">Unity Object (e.g. Texture, Mesh, Material) to associate
474+
/// with this sample. The Profiler displays it in the sample hierarchy.</param>
475+
[MethodImpl(MethodImplOptions.AggressiveInlining | (MethodImplOptions)512)]
476+
public ProfilingScope(BaseCommandBuffer cmd, ProfilingSampler sampler, Object contextObject)
477+
: this(cmd.m_WrappedCommandBuffer, sampler, contextObject)
478+
{
479+
}
480+
461481
/// <summary>
462482
/// Ends the profiling scope by calling <see cref="ProfilingSampler.End"/>. Safe to call multiple times.
463483
/// </summary>

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeBrickPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ internal void Update(CommandBuffer cmd, CellStreamingScratchBuffer dataBuffer, C
384384
List<BrickChunkAlloc> dstLocations, bool updateSharedData, Texture validityTexture, ProbeVolumeSHBands bands,
385385
bool skyOcclusion, Texture skyOcclusionTexture, bool skyShadingDirections, Texture skyShadingDirectionsTexture, bool probeOcclusion)
386386
{
387-
using (new ProfilingScope(cmd, CoreProfilingSamplers.APVDiskStreamingUpdatePool))
387+
using (new ProfilingScope(cmd, CoreProfilingSamplers.APVDiskStreamingUpdatePool, m_Pool.TexL0_L1rx))
388388
{
389389
int chunkCount = dstLocations.Count;
390390

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.Streaming.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ public void UpdateCellStreaming(CommandBuffer cmd, Camera camera, ProbeVolumesOp
805805
// Handle cell streaming for blending
806806
if (supportScenarioBlending)
807807
{
808-
using (new ProfilingScope(cmd, CoreProfilingSamplers.APVScenarioBlendingUpdate))
808+
using (new ProfilingScope(cmd, CoreProfilingSamplers.APVScenarioBlendingUpdate, camera))
809809
UpdateBlendingCellStreaming(cmd);
810810
}
811811
}

Packages/com.unity.render-pipelines.core/Runtime/PathTracing/LightmapIntegration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ public void Accumulate(
377377
_accumulationShader.SetIntParam(cmd, LightmapIntegratorShaderIDs.SampleOffset, (int)currentSampleCountPerTexel);
378378
_accumulationShader.SetIntParam(cmd, LightmapIntegratorShaderIDs.MaxLocalSampleCount, (int)sampleCountToTakePerTexel);
379379

380-
cmd.BeginSample("Accumulation (Expanded)");
380+
cmd.BeginSample(LightmapIntegratorShaderIDs.k_AccumulationExpanded);
381381
_accumulationShader.Dispatch(cmd, traceScratchBuffer, _accumulationDispatchBuffer);
382-
cmd.EndSample("Accumulation (Expanded)");
382+
cmd.EndSample(LightmapIntegratorShaderIDs.k_AccumulationExpanded);
383383
}
384384
}
385385

Packages/com.unity.render-pipelines.core/Runtime/PathTracing/LightmapIntegrationHelpers.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ internal static class ShaderIDs
6868
internal static int CopyTextureAdditiveKernel;
6969
internal static int MaskAlphaChannelKernel;
7070

71+
/// <summary>
72+
/// Profiles the additive texture copy compute dispatch that blends a source region
73+
/// into a destination region of a lightmap during accumulation.
74+
/// </summary>
75+
static readonly ProfilerMarker k_CopyTextureAdditive =
76+
new ProfilerMarker(ProfilerCategory.Render, "CopyTextureAdditive",
77+
MarkerFlags.Default | MarkerFlags.SampleGPU);
78+
79+
/// <summary>
80+
/// Profiles the alpha channel mask compute dispatch that clears or fills the alpha
81+
/// channel of a lightmap texture to mark valid texel coverage.
82+
/// </summary>
83+
static readonly ProfilerMarker k_MaskAlphaChannel =
84+
new ProfilerMarker(ProfilerCategory.Render, "MaskAlphaChannel",
85+
MarkerFlags.Default | MarkerFlags.SampleGPU);
86+
7187
#if UNITY_EDITOR
7288
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
7389
static void ResetStaticsOnLoad()
@@ -109,7 +125,7 @@ public void Load()
109125
public void CopyTextureAdditive(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier destination,
110126
int width, int height, int sourceX = 0, int sourceY = 0, int destinationX = 0, int destinationY = 0)
111127
{
112-
cmd.BeginSample("CopyTextureAdditive");
128+
cmd.BeginSample(k_CopyTextureAdditive);
113129
cmd.SetComputeTextureParam(ComputeHelperShader, CopyTextureAdditiveKernel, ShaderIDs.SourceTexture, source);
114130
cmd.SetComputeTextureParam(ComputeHelperShader, CopyTextureAdditiveKernel, ShaderIDs.DestinationTexture, destination);
115131
cmd.SetComputeIntParam(ComputeHelperShader, ShaderIDs.SourceWidth, width);
@@ -120,18 +136,18 @@ public void CopyTextureAdditive(CommandBuffer cmd, RenderTargetIdentifier source
120136
cmd.SetComputeIntParam(ComputeHelperShader, ShaderIDs.DestinationY, destinationY);
121137
ComputeHelperShader.GetKernelThreadGroupSizes(CopyTextureAdditiveKernel, out uint groupX, out uint groupY, out _);
122138
cmd.DispatchCompute(ComputeHelperShader, CopyTextureAdditiveKernel, GraphicsHelpers.DivUp(width, groupX), GraphicsHelpers.DivUp(height, groupY), 1);
123-
cmd.EndSample("CopyTextureAdditive");
139+
cmd.EndSample(k_CopyTextureAdditive);
124140
}
125141

126142
public void MaskAlphaChannel(CommandBuffer cmd, RenderTargetIdentifier texture, int width, int height)
127143
{
128-
cmd.BeginSample("MaskAlphaChannel");
144+
cmd.BeginSample(k_MaskAlphaChannel);
129145
cmd.SetComputeTextureParam(ComputeHelperShader, MaskAlphaChannelKernel, ShaderIDs.TextureInOut, texture);
130146
cmd.SetComputeIntParam(ComputeHelperShader, ShaderIDs.TextureWidth, width);
131147
cmd.SetComputeIntParam(ComputeHelperShader, ShaderIDs.TextureHeight, height);
132148
ComputeHelperShader.GetKernelThreadGroupSizes(MaskAlphaChannelKernel, out uint groupX, out uint groupY, out _);
133149
cmd.DispatchCompute(ComputeHelperShader, MaskAlphaChannelKernel, GraphicsHelpers.DivUp(width, groupX), GraphicsHelpers.DivUp(height, groupY), 1);
134-
cmd.EndSample("MaskAlphaChannel");
150+
cmd.EndSample(k_MaskAlphaChannel);
135151
}
136152
}
137153

Packages/com.unity.render-pipelines.core/Tests/Runtime/Debugging/ProfilingSamplerTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,24 @@ public void Create_ReturnsNonNull()
4444
var sampler = ProfilingSampler.Create("CreatedMarker", MarkerFlags.Default);
4545
Assert.IsNotNull(sampler);
4646
Assert.IsTrue(sampler.IsValid());
47+
#if USE_RECORDER
4748
Assert.IsFalse(sampler.m_Recorder.Valid);
4849
Assert.IsFalse(sampler.m_GpuRecorder.Valid);
4950
Assert.IsFalse(sampler.m_InlineRecorder.Valid);
51+
#endif
5052
}
5153

5254
[Test]
5355
public void CreateWithFlags_IsValid()
5456
{
5557
var sampler = ProfilingSampler.Create("FlagsMarker", MarkerFlags.VerbosityAdvanced);
5658
Assert.IsTrue(sampler.IsValid());
59+
#if USE_RECORDER
5760
// Recorders are allocated lazily; none should be valid before enableRecording = true.
5861
Assert.IsFalse(sampler.m_Recorder.Valid);
5962
Assert.IsFalse(sampler.m_GpuRecorder.Valid);
6063
Assert.IsFalse(sampler.m_InlineRecorder.Valid);
64+
#endif
6165
}
6266

6367
[Test]
@@ -113,6 +117,7 @@ public IEnumerator TimingProperties_ReturnZero_WhenNotRecording()
113117
Assert.AreEqual(0, m_Sampler.inlineCpuSampleCount);
114118
}
115119

120+
#if USE_RECORDER
116121
// Bits 10-12 all zero → SampleGPU auto-added → GpuRecorder is created on first enableRecording = true
117122
[Test]
118123
public void SampleGPU_AutoAdded_ForUserFacingMarker()
@@ -245,5 +250,6 @@ public void Dispose_CalledTwice_DoesNotThrow()
245250
sampler.Dispose(); // recorders are no longer .Valid after first dispose
246251
});
247252
}
253+
#endif
248254
}
249255
}

Packages/com.unity.render-pipelines.universal/Runtime/Passes/ColorGradingLutPass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private static void ExecutePass(RasterCommandBuffer cmd, PassData passData, RTHa
115115
var lutBuilderHdr = passData.lutBuilderHdr;
116116
var allowColorGradingACESHDR = passData.allowColorGradingACESHDR;
117117

118-
using (new ProfilingScope(cmd, URPProfilingSamplers.ColorGradingLUT))
118+
using (new ProfilingScope(cmd, URPProfilingSamplers.ColorGradingLUT, passData.hdrGrading ? lutBuilderHdr : lutBuilderLdr))
119119
{
120120
// TODO: should these components be set instead?
121121

Packages/com.unity.render-pipelines.universal/Runtime/Passes/MainLightShadowCasterPass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void RenderMainLightCascadeShadowmap(RasterCommandBuffer cmd, ref PassData data)
268268

269269
VisibleLight shadowLight = lightData.visibleLights[shadowLightIndex];
270270

271-
using (new ProfilingScope(cmd, URPProfilingSamplers.MainLightShadow))
271+
using (new ProfilingScope(cmd, URPProfilingSamplers.MainLightShadow, shadowLight.light))
272272
{
273273
// Need to start by setting the Camera position and worldToCamera Matrix as that is not set for passes executed before normal rendering
274274
ShadowUtils.SetCameraPosition(cmd, data.cameraData.worldSpaceCameraPos);

Packages/com.unity.render-pipelines.universal/Runtime/ReflectionProbeManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public unsafe void UpdateGpuData(CommandBuffer cmd, ref CullingResults cullResul
300300
Debug.LogWarning("A number of reflection probes have been skipped due to the reflection probe atlas being full.\nTo fix this, you can decrease the number or resolution of probes.");
301301
}
302302

303-
using (new ProfilingScope(cmd, URPProfilingSamplers.UpdateReflectionProbeAtlas))
303+
using (new ProfilingScope(cmd, URPProfilingSamplers.UpdateReflectionProbeAtlas, m_AtlasTexture0))
304304
{
305305
cmd.SetRenderTarget(m_AtlasTexture0);
306306

0 commit comments

Comments
 (0)