Search code examples
directxhlsldirectx-11directx-9directx-10

Complexity of sample methods HLSL. O(1), O(n)?


Hy everyone. I wanted to know if someone knew the complexity of the HLSL texture sampling functions, like tex2d and the DX10/11 equivalent. If the texture where a pixel array, it would be of constant complexity access a pixel, but it uses UVs to access the pixel, so I don't know the complexity of the function then. Any one knows?


Solution

  • O(1)

    I don't know how the HLSL sampling works internally, but I recently built my own (working) samplers for a custom grid class. The difference in performance is caused by the choice of the interpolation method:

    Point Sampler

    The point sampler uses nearest-neighbour interpolation. This algorithm is, of course, very performant, since the UVs are simply rounded to the nearest integer pixel indices.

    Linear Sampler

    This kind produces nicer results, sinces it uses linear interpolation. Assume your UVs point to a location between four pixels. A lerp is then performed on the top pixels in the square, another on the bottom pixels and a third on the results. Since this kind of filtering involves four pixels and 12 float interpolations, it's not as fast as point sampling.

    Anisotropic Sampler

    An anisotropic filter produces the (currently) highest quality results. It is the slowest of the available types.


    Sampling comparison