Filling Float buffer in Metal
<p><strong>Problem:</strong></p>

<p>I need to fill a <code>MTLBuffer</code> of <code>Float</code>s with a constant value — say <code>1729.68921</code>. I also need it to be as fast as possible.</p>

<p>Therefore I'm prohibited from filling the buffer on the CPU side (i.e. getting <code>UnsafeMutablePointer&lt;Float&gt;</code> from the <code>MTLBuffer</code> and assigning in serial manner).</p>

<p><strong>My approach</strong></p>

<p>Ideally I'd use <a href="https://developer.apple.com/reference/metal/mtlblitcommandencoder/1400761-fill" rel="nofollow noreferrer"><code>MTLBlitCommandEncoder.fill()</code></a>, however AFAIK it's only capable to fill a buffer with <code>UInt8</code> values (given that <code>UInt8</code> is 1 byte long and <code>Float</code> is 4 bytes long, I can't specify arbitrary value of my <code>Float</code> constant).</p>

<p>So far I can see only 2 options left, but both seem to be overkill:</p>

<ol>
<li>create another buffer <code>B</code> filled with the constant value and copy its contents into my buffer via <code>MTLBlitCommandEncoder</code></li>
<li>create a <code>kernel</code> function that'd fill the buffer</li>
</ol>

<p><strong>Questions</strong></p>

<p>What's the fastest way of filling <code>MTLBuffer</code> of <code>Float</code>s with a 
constant value?</p>