How do i make a Texture2DArray writable in Shader

I’m getting this error when trying to set my texture array to a RWTexture2DArray in my compute shader, i’m not getting it when setting for read only.

Compute shader (/myshader/): Property (VT_ATLAS_1) at kernel index (1): Attempting to bind >texture as UAV but the texture wasn’t created with the UAV usage flag set!

I’m setting my texture as a global shader texture like this:

        atlas = new(256, 256, TexTureCacheSize, TextureFormat.R16, false); 
atlas.Apply(false, true);
Shader.SetGlobalTexture("VT_ATLAS_1", atlas);

My shader is declared like this:
RWTexture2DArray<float> VT_ATLAS_1;

Thanks in advance!

As “atals” you need to create RenderTexture with RenderTextureDescriptor structure.
Essential fields are:

dimension = TextureDimension.Tex2DArray;
enableRandomWrite = true;

You cannot use ordinary Texture2DArray as RW shader resource.

Thanks! I’m a bit disappointed that texture arrays are not writable in shaders but it should be pretty easy to transition my program to use render textures.
Sorry to ask another thing, but do you know what the best approach to copy an entire texture2d stored in cpu to the GPU rendertexture (copying it with some offset, like a tile in an atlas) is? With best I mean performance, just to know if there is one clearly superior method over the rest.

The fastest method is to use Graphics.CopyTexture.

1 Like