'Passing a float array to a ComputeBuffer within a struct
Working with Unity and a Compute Shader (HLSL). I have a struct, P that I am passing into a computeBuffer which has float fields and those pass just fine, but I'm trying to pass an array of floats buffer as well but whenever I do so I get the error
ArgumentException: Array passed to ComputeBuffer.SetData(array) must be blittable. P.buffer is not blittable because it is not of value type (System.Single[])
According to the docs, primitive arrays are blittable, but how I'm doing it isn't working.
public struct P{
. . .
public float[] buffer;
. . .
}
And then space allocation:
private void allocateSpaceP(){
. . .
int bufferSize = sizeof(float) * arraySize;
. . .
int totalSize = . . . + bufferSize;
pBuffer = new ComputeBuffer(pList.Length, totalSize);
pBuffer.SetData(pList);
shader.SetBuffer(mainKernal, "P", pBuffer);
shader.SetBuffer(pKernal, "P", pBuffer);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
