public static void SetBuffers(this IMTLComputeCommandEncoder table, IMTLBuffer[] buffers, nuint[] offsets, NSRange range)
        {
            if (buffers == null)
            {
                throw new ArgumentNullException(nameof(buffers));
            }
            if (offsets == null)
            {
                throw new ArgumentNullException(nameof(offsets));
            }

            var bufferPtrArray = buffers.Length <= 1024 ? stackalloc IntPtr[buffers.Length] : new IntPtr [buffers.Length];

            // get all intptr from the array to pass to the lower level call
            for (var i = 0; i < buffers.Length; i++)
            {
                bufferPtrArray [i] = buffers [i].Handle;
            }

            unsafe
            {
                fixed(void *buffersPtr = bufferPtrArray)
                fixed(void *offsetsPtr = offsets)                    // can use fixed
                {
                    table.SetBuffers((IntPtr)buffersPtr, (IntPtr)offsetsPtr, range);
                }
            }
            GC.KeepAlive(buffers)
        }
Пример #2
0
 public static void SampleCounters(this IMTLComputeCommandEncoder This, IMTLCounterSampleBuffer sampleBuffer, nuint sampleIndex, bool barrier)
 {
     if (sampleBuffer == null)
     {
         ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(sampleBuffer));
     }
     global::ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_UIntPtr_bool(This.Handle, Selector.GetHandle("sampleCountersInBuffer:atSampleIndex:withBarrier:"), sampleBuffer.Handle, (UIntPtr)sampleIndex, barrier);
 }
Пример #3
0
 public void TearDown()
 {
     commandQ?.Dispose();
     commandQ = null;
     commandBuffer?.Dispose();
     commandBuffer = null;
     encoder?.Dispose();
     encoder = null;
 }
Пример #4
0
        public void Compute(IMTLCommandBuffer commandBuffer)
        {
            IMTLComputeCommandEncoder computeEncoder = commandBuffer.ComputeCommandEncoder;

            if (computeEncoder == null)
            {
                return;
            }

            computeEncoder.SetComputePipelineState(kernel);
            computeEncoder.SetTexture(mpInTexture.MetalTexture, 0);
            computeEncoder.SetTexture(outTexture, 1);
            computeEncoder.DispatchThreadgroups(localCount, workgroupSize);
            computeEncoder.EndEncoding();
        }
Пример #5
0
        public void Draw(MTKView view)
        {
            // Create a new command buffer for each renderpass to the current drawable
            IMTLCommandBuffer commandBuffer = commandQueue.CommandBuffer();

            // Compute commands
            IMTLComputeCommandEncoder computeCommandEncoder = commandBuffer.ComputeCommandEncoder;

            computeCommandEncoder.SetComputePipelineState(computePipelineState);

            computeCommandEncoder.SetBuffer(tessellationFactorsBuffer, 0, 2);

            computeCommandEncoder.DispatchThreadgroups(new MTLSize(1, 1, 1), new MTLSize(1, 1, 1));

            computeCommandEncoder.EndEncoding();

            // Render commands

            // Call the view's completion handler which is required by the view since it will signal its semaphore and set up the next buffer
            var drawable = view.CurrentDrawable;

            // Obtain a renderPassDescriptor generated from the view's drawable textures
            MTLRenderPassDescriptor renderPassDescriptor = view.CurrentRenderPassDescriptor;

            // Create a render command encoder so we can render into something
            IMTLRenderCommandEncoder renderCommandEncoder = commandBuffer.CreateRenderCommandEncoder(renderPassDescriptor);

            // Set context state
            renderCommandEncoder.SetTriangleFillMode(MTLTriangleFillMode.Lines);
            renderCommandEncoder.SetDepthStencilState(depthState);
            renderCommandEncoder.SetRenderPipelineState(renderPipelineState);
            renderCommandEncoder.SetVertexBuffer(controlPointsBuffer, 0, 0);
            renderCommandEncoder.SetTessellationFactorBuffer(tessellationFactorsBuffer, 0, 0);

            // Tell the render context we want to draw our primitives
            renderCommandEncoder.DrawPatches(3, 0, 1, null, 0, 1, 0);

            // We're done encoding commands
            renderCommandEncoder.EndEncoding();

            // Schedule a present once the framebuffer is complete using the current drawable
            commandBuffer.PresentDrawable(drawable);


            // Finalize rendering here & push the command buffer to the GPU
            commandBuffer.Commit();
        }
Пример #6
0
        public void SetUp()
        {
            device = MTLDevice.SystemDefault;
            // some older hardware won't have a default
            if (device == null)
            {
                Assert.Inconclusive("Metal is not supported");
            }

            commandQ = device.CreateCommandQueue();
            if (commandQ == null)              // this happens on a simulator
            {
                Assert.Inconclusive("Could not get the functions library for the device.");
            }

            commandBuffer = commandQ.CommandBuffer();
            if (commandBuffer == null)             // happens on sim
            {
                Assert.Inconclusive("Could not get the command buffer for the device.");
            }

            encoder = commandBuffer.ComputeCommandEncoder;
        }