#Cached Shadow Maps increase FPS in one place but decrease FPS in another?

1 messages · Page 1 of 1 (latest)

sly grove
#

I'm using cached shadow maps to improve my performance, but as the title says, my performance improved in one area but got worse in another.
I marked my static geometry with the “Static Shadow Caster” flag, as well as some of my dynamic objects that remain in one place, so that their shadows are also cached.

This is how I update cascades: https://pastebin.com/JhTzRs1u
As you can see in the script, shadow update mode is OnDemand and "Always Draw Dynamic" is enabled as well.

What can cause it?

inland pelican
#

Yeah, I found cached shadow maps to have bad performance as well. You'd think it would be nearly free.

hushed marten
#

One problem with cached shadow maps is that you need a seperate shadow map for dynamic objects. This dynamic shadow map then has to be combined with the cached shadowmap before the final combined shadowmap can be used for rendering. This incurs a bit of an extra cost which in some cases might be enough to offset the benefits. (There is also the extra memory overhead from needing more shadowmaps)

#

So like with most optmisations, there's some situations where it helps, and in other situations it doesn't. I'd use a graphics profiler to compare a frame with it on/off to see exactly where the extra cost is coming from to see if there's anything in particular causing the performance drop. It's possible that HDRP's implementation is missing a few optimisation opportunities.

sly grove
hushed marten
#

That's crazy haha. What GPU/shadow resolution is this using?
I think the way I'd implement this would be to copy the static shadowmap into a new depth texture, and then render the dynamic shadowmap on top of that. Avoids a blit entirely since a copy can be done on a seperate queue and not block the graphics pipeline, and also means you'd get some earlyZ rejection during the dynamic shadow map rendering.

I'd be surprised if HDRP isn't doing this, seems like an obvious win, unlss I'm missing something.

#

Looking at the shader, it seems like that's exactly what it's doing.. I have no idea why they are using a blit here instead of a copy, and they're using a texture sample instead of a load which is also wasting a bit of performance.

sly grove
inland pelican
#

Shadow resolution doesn't really matter in this case

#

Shadow blending and filtering are apparently very expensive in HDRP, so if you cache them you only lose part of the cost.

And if it's still casting the same shadow map for dynamic objects, you're now paying the cost to blend two shadow maps, and all you gain are a few less draw calls.

carmine portal
sly grove
carmine portal
#

What software were you inspecting them in?

sly grove
carmine portal
# sly grove Pix

Then you should be able to see what its doing and possibly come up with a way to optimize it.

inland pelican
#

Alternatively, since you're already reaching 152fps on an RTX 3060, you might consider just focusing on more important things.

hushed marten
#

Cached shadows makes no difference to the cost of filtering since they are combined into a single shadow map

hushed marten
inland pelican
#

Especially since the shader is just

#

⁨```c
Varyings Vert(Attributes input)
{
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
output.texcoord = DYNAMIC_SCALING_APPLY_SCALEBIAS(GetFullScreenTriangleTexCoord(input.vertexID));
return output;
}

float Frag(Varyings input) : SV_Depth
{
return SAMPLE_TEXTURE2D_LOD(_CachedShadowmapAtlas, s_point_clamp_sampler, input.texcoord.xy, 0).x;
}