- Home /
Question by
sjb23 · May 23, 2021 at 05:04 PM ·
linuxopenglcompute shaderlinux editor
Compute Shader Not Working in Build (Linux / OpenGL)
I am unable to get my compute shader to write to a texture in a built version of my project, even though it works in the editor. I made a blank project, and added a quad, which has a script containing the following code.
public class CSTtest : MonoBehaviour
{
public ComputeShader cs;
private RenderTexture rt;
private int texWidth = 512;
private int texHeight = 512;
void Start()
{
Screen.SetResolution(1280, 720, false);
rt = new RenderTexture(texWidth, texHeight, 0, RenderTextureFormat.ARGB32);
rt.enableRandomWrite = true;
rt.Create();
GetComponent<Renderer>().material.mainTexture = rt;
cs.SetTexture(0, "Result", rt);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.G))
{
cs.Dispatch(0, texWidth / 8, texHeight / 8, 1);
}
}
void OnDisable()
{
rt.Release();
}
}
The computer shader just turns the quad red.
// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel CSMain
// Create a RenderTexture with enableRandomWrite flag and set it
// with cs.SetTexture
RWTexture2D<float4> Result;
[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
Result[id.xy] = float4(1, 0, 0, 1);
}
In the editor the quad turns red as expected, but in the built version nothing happens when I dispatch the compute shader. Am I doing something wrong, or is this a bug with Unity? I am running on Linux with Editor version 2020.1.2f1, OpenGL 4.5. When I tested this same project on Windows/DX11 the compute shader worked in the editor and the built version.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613034106im_/https://answers.unity.com/themes/thub/images/avi.jpg)