Derivative Texture Sample Cost?

Is there an additional performance cost when using a derivative texture over a standard texture sample in Unreal material editor? If so, is it significant enough that I should add a switch in my material to choose between the standard and derivative texture samples?

I’m using the derivative version in conjunction with the VectorToRadialValue material function to get rid of that nasty crease you get from bending a texture to radial UVs.

1 Like

Hi Travis, I’ve now stumbled upon this question as well, when tasked to optimize some VFX.
Have you found an answer to this yet?

I think the consensus was that having a texture sample set to Derivative and plugging in DDX and DDY was basically free. From what I remember of it being explained, modern GPUs already convert textures to derivative when running a game. So there’s no additional instruction cost, but it doesn’t save you any kind of instructions over just using a normal texture sample either.

If someone else pops in here who could clarify more, or correct me if I’m wrong, by all means please do.

From what I know it definitely comes with a cost, I don’t have any idea how significant this cost is though.

It seems if you do not use this override, the values are calculated automatically “the hardware”. (I’m not exactly sure what that implies), if you do choose to override this, I’m assuming these instructions now need to happen on the gpu, therefore slowing the process down?

Thread of replies from the same question on FB. The responses were mixed, but it seems to lean towards it not being much of a perf hit manually setting your textures to Derivative in your materials.

I find this answer very informative

1 Like

On desktop and consoles this is basically free. Very little performance difference if any between using the basic sampling method (tex2D() / tex.Sample() / sample node / whatever) vs a derivative form.

On mobile there may be a significant cost. On some mobile GPUs it appears to cause some problems related to memory bandwidth that do not occur normally. It was explained to me that in using manual derivatives, each pixel’s texture sample is invalidating the local texture unit’s cache causing it to re-fetch from the next tier. I don’t believe this is true for all mobile GPUs, but it’s enough of them that the mobile focused shader / graphics devs I know will make efforts to avoid using it when unnecessary.

Basically if you’re already in a highly memory bandwidth limited situation (you have a lot of different and/or high resolution uncompressed textures), using manual derivatives may impart a significant performance penalty.

1 Like

Does this factor before or after setting max resolution size in your texture settings in Unreal? I usually import larger textures and then use the max res option to scale them down in the engine. Almost always gives better results than shrinking them before export out of something like Photoshop.

The max texture size determines the max texture size the GPU sees. You could import in a 16k x 16k texture and shrink it down to 64x64, and apart from that taking a stupendously long time to load import in the editor, the GPU only ever knows about the 64x64 version. Texture resolution quality settings also affect what the GPU knows about.

edit for clarification

This is because Photoshop is trash at resizing textures and has done it wrong for 30 years.


Thank you for giving a more clear answer!

The unreal documentation does an attempt at explaining the situation, but they don’t go very deep.

Thanks for clarifying that too, I appreciate the wisdom and insight.