compute shader script:
#pragma kernel CSMain
RWStructuredBuffer<int> result;
[numthreads(8, 8, 8)]
void CSMain(int id : SV_DispatchThreadID )
{
result[id] = id;
}
c# script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ForTesting : MonoBehaviour
{
public ComputeShader compute;
// Use this for initialization
void Start()
{
ComputeBuffer resultBuffer = new ComputeBuffer(8*8*8, sizeof(int));
var kernel = compute.FindKernel("CSMain");
compute.SetBuffer(kernel, "result", resultBuffer);
compute.Dispatch(kernel,1,1,1);
int[] result = new int[8 * 8 * 8];
resultBuffer.GetData(result);
resultBuffer.Release();
}
}
These are testing code for what value is in a result. I don't understand result[id] = id; line.
Exactly, result[id]. Accessing with index to buffer.
And while google, I saw a post saying that the shader function is executed as many as the number of threads.
Then in above case, cause numthreads(8, 8, 8) and Dispatch(kernel, 1, 1, 1), Does CSMain function run 8 * 8 * 8 * 1 * 1 * 1 times?