Examples

This example shows how to use the GpuBuffer class to send data to a compute shader:
struct MyData
{
    public float Value;
}

// Allocate the GPU buffer
using (var buffer = new GpuBuffer<MyData>( 2 ))
{
	// Upload data to the GPU buffer
	var data = new MyData[] { new MyData { Value = 1.0f }, new MyData { Value = 2.0f } };
	buffer.SetData( data );

    // Pass the buffer to a compute shader
    ComputeShader.Attributes.Set( "myData", buffer );
    
    // Dispatch the shader
    ComputeShader.Dispatch();
}
This example shows how to retrieve data from a GPU using the GpuBuffer class:
struct MyData
{
    public float Value;
}

using (var buffer = new GpuBuffer<MyData>( 8 ))
{
    // Pass the buffer to a compute shader
    ComputeShader.Attributes.Set( "myData", buffer );
    
    // Dispatch the shader
    ComputeShader.Dispatch();
    
	// Retrieve the data from the GPU
	var data = new MyData[ 8 ];
	buffer.GetData( data, 0, 8 );
}

Inheritance

people
Log in to reply
You can't reply if you're not logged in. That would be crazy.