我有一个Metal结构体:
struct BlurDesc {
short fenceRows;
short offs;
short sampleCnt;
float muls[64];
};
它被用作着色器参数:
kernel void hBlurCompute(
constant BlurDesc & blurDesc [[ buffer(0) ]],
texture2d<half, access::read> srcTexture [[ texture(0) ]],
texture2d<half, access::write> hBlurTexture [[ texture(1) ]],
ushort gid [[ thread_position_in_grid ]]
) {
以下为对应的Swift结构体:
struct BlurDesc {
var fenceRows : Int16 = 0
var offs : Int16 = -32
var sampleCnt : Int16 = 64
let muls = Array<Float>(repeating: (1.0/64), count: 64)
}
var blurDesc = BlurDesc()
如何将Swift结构体作为参数传递给着色器?
是否有可能从中创建具有正确字节顺序的字节缓冲区,并以某种方式将其传递给:MTLDevice.makeBuffer(bytes pointer: UnsafeRawPointer, length: Int, options: MTLResourceOptions = [])?