RWTexture2D in Compute Shader on Android?
Asked Answered
M

1

0

I am trying to use this asset to test out a compute shader on android, that allows texture modification. I’m new to shaders, I could have misunderstood or not realizing some kind of limitation on mobile. I had assumed since the editor (while under android platform) worked that it would just work on android. I have tested this in the editor, on android platform, with opengl 3.1 as min graphics API, disabled the graphics emulation, and the asset works as expected. Player settings like this:
83658-b8b256d68784a6cdb751453836cd2dee.png

When testing it on android, the asset caused a force close on Unity 5.4, and on 5.5, it would complain about "Kernel at index 0 is invalid" when I ran the code the same as in the editor. If I modify the shader code by commenting out a section where it assigns to a RWTexture2D, then the error goes away, but obviously nothing is drawn to the screen.

This is a snippet of code to describe the problem area (cannot share complete code, its asset from asset store):

#pragma kernel pixelCalc
  
RWTexture2D<float4> textureOut;
  
[numthreads(32,32,1)]
void pixelCalc (uint3 id : SV_DispatchThreadID)
{
    // some stuff happens here...
    while (itn < 255 && d < 4)
    {
        // calculations and stuff...
        itn++;
    }
    if (itn == 256) // if this line and 3 below it are commented out, runs on android!
        textureOut[id.xy] = float4(0, 0, 0, 1);
    else
        textureOut[id.xy] = colors[itn];
}

Hope somebody can confirm that RWTexture2D on a compute shader should work or not on android? Has anybody had this error and found a way to make it work on android?

Mellow answered 12/10, 2023 at 13:7 Comment(0)
M
0

I cracked away at it for days and days (remember, I know jack about shaders), and finally got a compute shader working that uses RWTexture2D running on Android!

I couldn’t get that asset working as it does in the editor, but instead learned a good bit about shader coding and followed a variety of tutorials before I found one that helped me with this problem, so if future readers need help getting RWTexture2D working on Android, have a look at this tutorial page to get you going in the right direction:

https://web.archive.org/web/20180616083119/http://cheneyshen.com/directcompute-tutorial-for-unity-textures/

Mellow answered 12/10, 2023 at 13:13 Comment(1)

You are very welcome!

Cle

© 2022 - 2024 — McMap. All rights reserved.