cryptic error message with compute buffer

Maybe I’m getting used to more informative error messages, this doesn’t mean much, I don’t know if it’s a regression, I didn’t do CS until async in 18.1 was introduced so maybe it’s just cryptic stuff you guys need to work on.

UnityException: SetTexture failed
UnityEngine.ComputeShader.SetTexture (Int32 kernelIndex, System.String name, UnityEngine.Texture texture) (at C:/buildslave/unity/build/artifacts/generated/bindings_old/common/Core/ComputeShaderBindings.gen.cs:146)
SimpleComputeShader.OnEnable () (at Assets/compute shader tutorials/SimpleComputeShader.cs:13)

A better message would tell me why this failed.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SimpleComputeShader : MonoBehaviour {
    public ComputeShader shader;
    Texture2D tex;

    void OnEnable()
    {
        tex = new Texture2D(64, 64,TextureFormat.RGBAFloat, false);

        shader.SetTexture(0, "tex", tex);
        shader.Dispatch(0, tex.width / 8, tex.height / 8, 1);
    }

    private void OnGUI()
    {
        int w = Screen.width / 2;
        int h = Screen.height / 2;
        int s = 512;

        GUI.DrawTexture(new Rect(w - s / 2, h - s / 2, s, s), tex);
    }
}
#pragma kernel CSMain

RWTexture2D<float4> tex;

[numthreads(8,8,1)]
void CSMain (uint2 id : SV_DispatchThreadID)
{
    float w,h;
    tex.GetDimensions(w,h);
    float uv = float2(idx/w, idy/h);
    tex[id] = float4(uv,0.0,1.0);
}

I suspect its because you are trying to use a standard texture as a writable texture in the compute shader. You should be using a RenderTexture thats been setup to allow random writes. Its been this way since compute shaders were very first supported in Unity as far as I remember.

ok, and in another test project this error isn’t there, the project runs fine, just nothing happens because gpu can only write to rendertexture, so maybe this error is something else than rendertexture. in this case problem solved, but i notice also that compute shaders errors only show up in the compute shader asset, UT: it should be in the console as well