Description

When using materials with CustomData inputs, such as the Eye material with Iris Distance and Mask, Virtual Texture samples will increase the instruction count for each unique VTPageResult.

Each custom data pin connection will duplicate the material graph into the GetCustomData<X> function, where X appears to be the index of the custom data pins. For non-virtual textures, the samplers have no side-effects, and the compiler will correctly identify that no data dependency exists. In this case, the function will be elided.

Unforunately, Virtual Texture's use TextureLoadVirtualPageTable to get a VTPageTableResult struct that is used in the virtual texture sample. The sample itself is elided as nothing depends on it; however, the TextureLoadVirtualPageTable is not elided as it appears to have a side-effect. Looking at the DXIL, it appears the VTPageResult.PackedRequest is being written to 7 addresses, including the VirtualTextureFeedback member of the MaterialParameters struct.

The net result of this superfluous operation is the addition of 67 instructions per TextureLoadVirtualPageTable call.

Steps to Reproduce
  • Create a material using the Eye shading model
  • Connect a virtual texture to the base colour pin
  • Connect a constant to the Iris Mask and Distance pins
  • Count the instructions after applying.
  • Create a material parameter and connect that to the Iris pins.
  • Count the instructions again after applying.

Expectation: Instruction count is the same or similar
Result: The instruction count increases by an unexpected amount for a parameter. In testing, 67 instructions was the most common increase.

Callstack

Git Diff shows the following difference between the constant and parameterised versions:

-'s are the code from the parameterised version
+'s are the code from the constant version

float GetMaterialCustomData0(in out FMaterialPixelParameters Parameters)
{
-     float3 Local0 = lerp(float3(0.00000000,0.00000000,0.00000000),Material_PreshaderBuffer[0].yzw,Material_PreshaderBuffer[0].x);
-     float2 Local1 = Parameters.TexCoords[0].xy;
-     float Local2 = 1.0f;
-     VTPageTableResult Local3 = TextureLoadVirtualPageTable(Material_VirtualTexturePageTable0_0, VTPageTableUniform_Unpack(Material_VTPackedPageTableUniform[0*2], Material_VTPackedPageTableUniform[0*2+1]), Local1 , 1u, 1u, View_MaterialTextureMipBias, Parameters.SvPosition.xy, 0U + 0, Parameters.VirtualTextureFeedback);
-     float4 Local4 = TextureVirtualSample(Material_VirtualTexturePhysical_0, Material_VirtualTexturePhysical_0Sampler, Local3, 0, VTUniform_Unpack(Material_VTPackedUniform[0]));
-     float Local5 = 1.0f;
-     float Local6 = 1.0f;
-     return Material_PreshaderBuffer[1].y;;
+     return 0.00000000;;
}

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-232142 in the post.

2
Login to Vote

Unresolved
ComponentUE - Rendering Architecture - Materials
Affects Versions5.55.4.4
Target Fix5.6
CreatedDec 4, 2024
UpdatedDec 5, 2024
View Jira Issue