[Solved] Compute shader on Android not working

I’ve spent the last couple days trying to figure out why my compute shader isn’t working on Android. I’ve narrowed it down to the tex2dlod call always returning 0. Here’s a minimal example:

#pragma kernel NotWorking

RWTexture2D<float4> result;

float tex_width;
float tex_height;
sampler2D input;

[numthreads(8,8,1)]
void NotWorking (uint3 id : SV_DispatchThreadID) {
    float2 uv = float2(id.x / tex_width, id.y / tex_height);
    float4 sample = tex2Dlod(input, float4(uv.x, uv.y, 0, 0));
    result[id.xy] = sample;
}

On desktop, the output is the result texture being a copy of the input texture. As soon as I build/deploy to Android, result is just a blank (black) texture. I know the compute shader is getting executed because if I remove the tex2Dlod and replace it with a constant, I get the expected result on both platforms. EDIT: Turns out tex2Dlod wasn’t to blame. I had replaced it with float4(1,1,1,1) and that was working but other values were not. Solution below.

What am I doing wrong?!

Hi!
Can you please file a bug report?
Thanks!

@aleksandrk filed report 1214413. Thanks!

I spent a long time playing with all the variables I could. In the end, the one that made the shader start working was to change the format on the RenderTexture that I was using to write result into:

renderTexture.format = RenderTextureFormat.RFloat;

The default RenderTextureFormat doesn’t work on Android (gives error RENDERTEXTURE.CREATE FAILED: FORMAT UNSUPPORTED FOR RANDOM WRITES - RGBA4 UNORM (7)). I had originally tried replacing it with RenderTextureFormat.ARGB32 since that’s the most common one. Turns out that doesn’t work either. Maybe it needs a different declaration in the compute shader? I don’t know - it all worked in the editor…

3 Likes