Search Unity

Resolved Writing to RWTexture2DArray mipmaps in compute shader

Discussion in 'Shaders' started by GuitarBro, May 5, 2020.

  1. GuitarBro

    GuitarBro

    Joined:
    Oct 9, 2014
    Posts:
    180
    Currently attempting to dive into compute shaders and trying to google some of this stuff is kicking my butt. :confused:

    Pretty sure I've got the basics down but I hit a roadblock attempting to write to the mipmaps for a RWTexture2DArray I created. My current relevant code excerpts:

    Code (CSharp):
    1. RWTexture2DArray<float4> outputTexture : register(u0);
    2.  
    3. ...
    4.  
    5. [numthreads(32, 32, 1)]
    6. void Convolve(uint3 ThreadID : SV_DispatchThreadID)
    7. {
    8.     ...
    9.  
    10.     outputTexture[ThreadID] = float4(1.0, 1.0, 1.0, 1.0);
    11. }
    12.  
    It only seems to be able to write to mip 0 and outputTexture doesn't accept a float4 to specify a mip level.

    I feel like this has to be a thing (this page certainly would seem to imply such a thing is possible: https://docs.microsoft.com/en-us/windows/win32/direct3d12/subresources) but I'm not exactly sure what to do with that information, especially in the context of Unity.

    From what I gather, the subresource exists and I could sample it with a sampler, but how do I go about writing to it? Is there some Unity-specific thing I'm missing here? Unity's compute shader documentation is, uh... lacking, to put it nicely. :rolleyes:


    For some background context: the whole reason I'm using RWTexture2DArray explicitly is that there appears to be no way to write to a TextureCube so I'm doing the compute logic in a 6-deep RWTexture2DArray instead, then copying back to a cubemap RenderTexture afterwards. If there's a better way to do that, I'm all ears. ;)
     
  2. GuitarBro

    GuitarBro

    Joined:
    Oct 9, 2014
    Posts:
    180
    Is the destination mip level something that needs to be specified on the C# side? I haven't found any Unity documentation suggesting so which leads me to believe this needs to be done in the compute shader itself.
     
  3. GuitarBro

    GuitarBro

    Joined:
    Oct 9, 2014
    Posts:
    180
  4. florianpenzkofer

    florianpenzkofer

    Unity Technologies

    Joined:
    Sep 2, 2014
    Posts:
    479
    PrimalCoder and GuitarBro like this.
  5. GuitarBro

    GuitarBro

    Joined:
    Oct 9, 2014
    Posts:
    180
    Ah ha! Thank you, that's exactly what I was missing.