how to write value into a "integer" type render texture in compute shader?

i’m trying to make a mask by int render texture, but the problem is that i can’t write my value in it R8 format.
if i change to RInt, then i can write but can’t read from surface shader.
if i change to RFloat, then all process will be succeed.

m_MaskLabelRT = new RenderTexture(m_volumeObject.Dim.x, m_volumeObject.Dim.y, 0, RenderTextureFormat.R8);
m_MaskLabelRT.volumeDepth = m_volumeObject.Dim.z;
m_MaskLabelRT.dimension = UnityEngine.Rendering.TextureDimension.Tex3D;
m_MaskLabelRT.enableRandomWrite = true;
m_MaskLabelRT.Create();
[numthreads(8,8,8)]
void InitMask(uint3 id : SV_DispatchThreadID){
_MaskTex[id].r = 255;
}
int getMaskLabel(float3 pos){
return tex3Dlod(_MaskTex,float4(pos.x,pos.y,pos.z,0)).r;
}

Just to make sure, you did declare the texture as RWTexture3D?

yes,and actually i found that only when i use RWTexture3D i can’t read and write R8 texture,
if i use RInt or R8 while use RWTexture3D or RWTexture3D in CS, then i would read and write texture normally ( but R8 can’t get right value due to truncation)

and although RWTexture3D is working for RInt in compute shader, but i can’t read it from surface shader by tex3Dlod(_MaskTex, float4(pos.xyz,0));

To use tex3dlod with integers, the texture must have been declared as an isampler3d (signed) or usampler3d (unsigned), not a sampler3d.
https://developer.download.nvidia.com/cg/tex3Dlod.html

Or just declare it as a Texture2D and either use Load or the [ ] operator.

Update: Actually, I might be confusing GLSL syntax with Unity’s DX9 syntax here, but using DX11 syntax (Texture2D) should work.