|
84 | 84 | src::MtlPtr{T}, N::Integer; |
85 | 85 | queue::MTLCommandQueue=global_queue(dev), |
86 | 86 | async::Bool=false) where T |
87 | | - cmdbuf = MTLCommandBuffer(queue) |
88 | | - MTLBlitCommandEncoder(cmdbuf) do enc |
89 | | - MTL.append_copy!(enc, dst.buffer, dst.offset, src.buffer, src.offset, N * sizeof(T)) |
| 87 | + if N > 0 |
| 88 | + cmdbuf = MTLCommandBuffer(queue) |
| 89 | + MTLBlitCommandEncoder(cmdbuf) do enc |
| 90 | + MTL.append_copy!(enc, dst.buffer, dst.offset, src.buffer, src.offset, N * sizeof(T)) |
| 91 | + end |
| 92 | + commit!(cmdbuf) |
| 93 | + async || wait_completed(cmdbuf) |
90 | 94 | end |
91 | | - commit!(cmdbuf) |
92 | | - async || wait_completed(cmdbuf) |
| 95 | + return dst |
93 | 96 | end |
94 | 97 |
|
95 | | -@autoreleasepool function unsafe_fill!(dev::MTLDevice, ptr::MtlPtr{T}, |
96 | | - value::Union{UInt8,Int8}, N::Integer) where T |
97 | | - cmdbuf = MTLCommandBuffer(global_queue(dev)) |
98 | | - MTLBlitCommandEncoder(cmdbuf) do enc |
99 | | - MTL.append_fillbuffer!(enc, ptr.buffer, value, N * sizeof(T), ptr.offset) |
| 98 | +@autoreleasepool function unsafe_fill!(dev::MTLDevice, dst::MtlPtr{T}, |
| 99 | + value::Union{UInt8,Int8}, N::Integer; |
| 100 | + queue::MTLCommandQueue=global_queue(dev), |
| 101 | + async::Bool=false) where T |
| 102 | + if N > 0 |
| 103 | + cmdbuf = MTLCommandBuffer(queue) |
| 104 | + MTLBlitCommandEncoder(cmdbuf) do enc |
| 105 | + MTL.append_fillbuffer!(enc, dst.buffer, value, N * sizeof(T), dst.offset) |
| 106 | + end |
| 107 | + commit!(cmdbuf) |
| 108 | + async || wait_completed(cmdbuf) |
100 | 109 | end |
101 | | - commit!(cmdbuf) |
102 | | - wait_completed(cmdbuf) |
| 110 | + return dst |
103 | 111 | end |
104 | 112 |
|
105 | 113 | # TODO: Implement generic fill since mtBlitCommandEncoderFillBuffer is limiting |
0 commit comments