First of all, if you're working in 1D then you can set up your threads and dispatches in 1D as well and make your life easier. Just pick the number of threads that you want per thread group (64-256 is a good choice) and use that to set up the numthreads attribute:
static const uint NumThreads = 256;
[numthreads(NumThreads, 1 , 1)]
void CS()
{
}
You should never need to pass anything via a constant buffer to figure out an index, whether your index is 1D, 2D, or 3D. All of the information you need can be computed using the number of threads per thread group, and values that can be obtained using system-value semantics (SV_GroupID, SV_GroupIndex, SV_GroupThreadID, and SV_DispatchThreadID).
Let's walk through a simple example so that you can understand how it all it works: let's say you have a shader that's using 256 threads per group like the one I described above, and you need it to operate on a buffer with 5000 elements. Each thread is going to read a single value from this buffer, do some operation on it, then write out a single value to an output buffer that also has 5000 elements. On the CPU side of things, you need to decide how many thread groups to dispatch. Basically you need to dispatch the minimum number of thread groups required to cover the entire buffer. You can compute this number easily using a function like this:
UINT DispatchSize(UINT ThreadGroupSize, UINT NumElements)
{
return (NumElements + (ThreadGroupSize - 1)) / ThreadGroupSize;
}
Now in your shader, you need to compute a "flattened" index that you'll use as an address for reading from your input buffer and writing to your output buffer. For a 1D case, you basically want (GroupID * ThreadGroupSize) + ThreadID where GroupID is index of the thread group (so it will have range [0, 19]) and ThreadID is the index of the thread within a thread group (so it will have the range [0, 255]). This GroupID is available via SV_GroupID and ThreadID is availabe via SV_GroupThreadID, which means you can calculate this manually if you wish. However you can also have it provided automatically by using SV_DispatchThreadID:
StructuredBuffer<int> InputBuffer;
RWStructuredBuffer<int> OutputBuffer;
static const uint NumThreads = 256;
[numthreads(NumThreads, 1, 1)]
void CS(in uint3 DispatchIdx : SV_DispatchThreadID)
{
int num = InputBuffer[DispatchIdx.x];
num = num * 8 + 4;
OutputBuffer[DispatchIdx.x] = num;
}