Compute shader questions and debugging

I have a compute shader that is supposed to take a float3 input, do some calculations, and output a single float value. I haven’t setup the CPU side of things yet. I am getting an error when compiling it, though:

Shader error in 'Method 2.compute': cannot implicitly convert from 'const float' to 'RWStructuredBuffer<float>' at line 23

Here’s the compute shader code:

#pragma kernel DensityFunction

float3 ws;
RWStructuredBuffer<float> density;

void DensityFunction(uint3 id : SV_DispatchThreadID)
	density = -ws.y + 1.0f;

I have a few other questions, if anyone can answer them because the documentation on compute shaders in Unity is pretty empty. (If I should post these as different questions, let me know. I’m not sure on this site’s policies compared to Stack Exchange).

  1. What is causing this error.
  2. Is it possible to link compute shaders to vertex and pixel shaders directly without having to interface with the CPU?
  3. What is [numthreads()] exactly? I imagine that it’s how many threads the shader should use. But, why are there three values instead of just one?
  4. How can I know how many threads would be most efficient for my shader?
  1. density is array. If you want get element use (eg density[5] = some
  2. Without CPU no. But it is working fast, you can redirect buffer from CS to Shader without rewriting GPU Memory, just creating linkage (SetBuffer from Material somehow, see reference about shader and ComputeBuffer, i founded it somewhere).
  3. You setting the threads cube, size of it by x, y and z. When you dispatching it you writing in arguments how many cubes will be launched by x, y and z.
  4. As max as posissible, but not greater than 1024 at multiplication of x,y and z threads.