Custom Depth Stencil Write Mask not work on Mobile

On Mobile, Custom Depth Stencil Write Mask is not respected at all. For example, stencil value = 3. write mask = first bit. it should write out 1. but it write out 3. When can this be fixed?

346841-stencil-write-mask.jpg

my further investigation shows that Scenetexture::CustomStencil is not reading from the depthstencil buffer. instead it is reading from a custom unorm buffer which is not stored the correct value. the stencil value looks correct in the depthstencil buffer though(via renderDoc)

348249-read-stecil.jpg

Any ETA for a fix?

Hi, my problem is Custom Depth Stencil Write Mask doesn’t work any more on Mobile~How did you make it effect on Mobile?
Snipaste_2022-04-29_02-00-43

I’m reading the engine source code and it seems that mobile doesn’t even use custom stencil even with hdr enabled.

in the non mobile post processing pass you have this

Engine\Source\Runtime\Renderer\Private\PostProcess\PostProcessing.cpp

		if (PassSequence.IsEnabled(EPass::Tonemap))
		{
			const FPostProcessMaterialChain MaterialChain = GetPostProcessMaterialChain(View, BL_ReplacingTonemapper);

			if (MaterialChain.Num())
			{
				const UMaterialInterface* HighestPriorityMaterial = MaterialChain[0];

				FPostProcessMaterialInputs PassInputs;
				PassSequence.AcceptOverrideIfLastPass(EPass::Tonemap, PassInputs.OverrideOutput);
				PassInputs.SetInput(EPostProcessMaterialInput::SceneColor, FScreenPassTexture::CopyFromSlice(GraphBuilder, SceneColorSlice));
				//PassInputs.SetInput(EPostProcessMaterialInput::SeparateTranslucency, SeparateTranslucency);
				PassInputs.SetInput(EPostProcessMaterialInput::CombinedBloom, Bloom);
				PassInputs.SceneTextures = GetSceneTextureShaderParameters(Inputs.SceneTextures);
				PassInputs.CustomDepthTexture = CustomDepth.Texture;
				PassInputs.bManualStencilTest = Inputs.bSeparateCustomStencil;

main thing being this line → PassInputs.bManualStencilTest = Inputs.bSeparateCustomStencil;

but in the mobile version there is no mention of stencil at all, just the custom depth texture. so it may be that objects get marked as custom depth, but there is no index associated to any of the objects. I’m still digging. The input seems like you could just insert the bool into the mobile pass, but I don’t know if any of the custom stencil stuff is built at that point.