how to send mesh's vertex& index buffer into compute shader?

i did tried GetIndexBuffer and GetVertexBuffer for it, but the result looks not right.

mesh.indexBufferTarget |= GraphicsBuffer.Target.Raw;
var vertexBuffer = mesh.GetVertexBuffer(0);
var indexBuffer = mesh.GetIndexBuffer();

computeShader.SetBuffer(kernel, "indexBuffer",indexBuffer);
computeShader.SetBuffer(kernel, "vertexBuffer",vertexBuffer);

if i use the StructuredBuffer to handle indexBuffer, then the sum of the list in buffer will be 0, while if i use the ByteAddressBuffer like the doc shows, the value of index will be extra huge.

how can i use those? or any other way to pass mesh into compute shader?

Hmmm… that’s close to what I’m doing and not having any problems. Are you sure everything is being bound correctly?

You should not need to fetch them every frame. Instead just fetch them once and check if they’re valid or not, eg…

        public GraphicsBuffer unskinnedVertices
        {
            get
            {
                checkValid();
                if(_isSkinned)
                    throw new Exception("unskinnedVertices is only valid for unskinned meshes");
                if(_unskinnedVertices == null || !_unskinnedVertices.IsValid())
                {
                    // unity seems to invalide this at random times
                    _unskinnedVertices?.Dispose(); // non-null but invalid case
                    _mesh.vertexBufferTarget |= GraphicsBuffer.Target.Raw;
                    _unskinnedVertices = _mesh.GetVertexBuffer(0);
                }
                return _unskinnedVertices;
            }
        }

        public GraphicsBuffer indices
        {
            get
            {
                checkValid();
                if(_indices == null || !_indices.IsValid())
                {
                    _indices?.Dispose(); // non-null but invalid case
                    _mesh.indexBufferTarget |= GraphicsBuffer.Target.Raw;
                    _indices = _mesh.GetIndexBuffer();
                }
                return _indices;
            }
        }

Also try setting them via the command buffer instead of the compute shader instance immediately before dispatching, eg…

        private void dispatchKernel(int kernel, GraphicsBuffer vertices, int threadGroupsX, int threadGroupsY, bool setI2W)
        {
            if(kernel != _lastKernel)
            {
                _lastKernel = kernel;
                _cmd.SetComputeBufferParam(_csComputeShadow, kernel, ID_VERTICES_OUT, _verticesOut);
                _cmd.SetComputeBufferParam(_csComputeShadow, kernel, ID_INDIRECT_ARGS, _indirectArgs);
                if(setI2W) _cmd.SetComputeBufferParam(_csComputeShadow, kernel, ID_INSTANCE_TO_WORLD, _instanceToWorld);
            }
            _cmd.SetComputeBufferParam(_csComputeShadow, kernel, ID_VERTICES_IN, vertices);
            _cmd.DispatchCompute(_csComputeShadow, kernel, threadGroupsX, threadGroupsY, 1);
        }

thanks for reply 0-0,
actually i have forgotten that i asked this question before, and i met it again (found this post from google XD) ,
the way i avoid this problem is to set new buffers from cpu side, but this way is quite costly:

        _vertexBuffer.SetData(targetMeshFilter.mesh.vertices);
        _indexBuffer.SetData(targetMeshFilter.mesh.triangles);
        MeshSliceCS.SetBuffer(_kernelMain, "_Vertex", _vertexBuffer);
        MeshSliceCS.SetBuffer(_kernelMain, "_Triangles", _indexBuffer);