Search Unity

In-place texture compute support (UAV Loads support check not in Unity)

Discussion in 'Shaders' started by jolix, Jul 18, 2019.

  1. jolix

    jolix

    Joined:
    May 22, 2016
    Posts:
    53
    In a compute shader I need the value of the current texture as well as to be able to write to the texture.

    So for example:
    _TexRW[coord] = _TexRW[coord2]

    This is only possible when so called "UAV Loads" are supported for the format.
    For DX11, only R32_FLOAT, R32_UINT and R32_SINT are supported, for the rest of the formats, you have to do a check.

    This check can't be called from Unity: I tried SystemInfo.GetCompatibleFormat(..., FormatUsage.LoadStore), but that doesn't seem to check what I'm looking for.

    One option is a technique, called "ping-pong", where you use a second texture to write on:
    _TexRW[coord] = _Tex[icoord2]

    BUT, if you are only changing a small (non-predictable) part of the texture, you are forced to write to the entire texture, which is way slower.

    So I would love to know if there is a way to check for support so I know when to use ping-pong and when I can do in-place calculations.
     
  2. jolix

    jolix

    Joined:
    May 22, 2016
    Posts:
    53
    I think I found a workaround:
    bool supportsUAVLoads = SystemInfo.graphicsDeviceVersion.Contains("11.1");


    So according to here: https://en.wikipedia.org/wiki/Feature_levels_in_Direct3D#Support_matrix
    , UAV loads are supported for AMD DirectX feature level 11.1 and up.
    The only problem is that it's not correct for Intel, but for my game which is quite demanding anyways that's OK.

    Unfortunately SystemInfo.graphicsDeviceVersion doesn't show the true feature level, only the highest level of the target API. So a feature level 12.1 card will show level 11.1 when using the DX11 API.
     
    Last edited: Jul 18, 2019