MTLComputeCommandEncoder.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using static Veldrid.MetalBindings.ObjectiveCRuntime;
  3. namespace Veldrid.MetalBindings
  4. {
  5. public struct MTLComputeCommandEncoder
  6. {
  7. public readonly IntPtr NativePtr;
  8. public bool IsNull => NativePtr == IntPtr.Zero;
  9. private static readonly Selector sel_setComputePipelineState = "setComputePipelineState:";
  10. private static readonly Selector sel_setBuffer = "setBuffer:offset:atIndex:";
  11. private static readonly Selector sel_dispatchThreadgroups0 = "dispatchThreadgroups:threadsPerThreadgroup:";
  12. private static readonly Selector sel_dispatchThreadgroups1 = "dispatchThreadgroupsWithIndirectBuffer:indirectBufferOffset:threadsPerThreadgroup:";
  13. private static readonly Selector sel_endEncoding = "endEncoding";
  14. private static readonly Selector sel_setTexture = "setTexture:atIndex:";
  15. private static readonly Selector sel_setSamplerState = "setSamplerState:atIndex:";
  16. private static readonly Selector sel_setBytes = "setBytes:length:atIndex:";
  17. public void setComputePipelineState(MTLComputePipelineState state)
  18. => objc_msgSend(NativePtr, sel_setComputePipelineState, state.NativePtr);
  19. public void setBuffer(MTLBuffer buffer, UIntPtr offset, UIntPtr index)
  20. => objc_msgSend(NativePtr, sel_setBuffer,
  21. buffer.NativePtr,
  22. offset,
  23. index);
  24. public unsafe void setBytes(void* bytes, UIntPtr length, UIntPtr index)
  25. => objc_msgSend(NativePtr, sel_setBytes, bytes, length, index);
  26. public void dispatchThreadGroups(MTLSize threadgroupsPerGrid, MTLSize threadsPerThreadgroup)
  27. => objc_msgSend(NativePtr, sel_dispatchThreadgroups0, threadgroupsPerGrid, threadsPerThreadgroup);
  28. public void dispatchThreadgroupsWithIndirectBuffer(
  29. MTLBuffer indirectBuffer,
  30. UIntPtr indirectBufferOffset,
  31. MTLSize threadsPerThreadgroup)
  32. => objc_msgSend(NativePtr, sel_dispatchThreadgroups1,
  33. indirectBuffer.NativePtr,
  34. indirectBufferOffset,
  35. threadsPerThreadgroup);
  36. public void endEncoding() => objc_msgSend(NativePtr, sel_endEncoding);
  37. public void setTexture(MTLTexture texture, UIntPtr index)
  38. => objc_msgSend(NativePtr, sel_setTexture, texture.NativePtr, index);
  39. public void setSamplerState(MTLSamplerState sampler, UIntPtr index)
  40. => objc_msgSend(NativePtr, sel_setSamplerState, sampler.NativePtr, index);
  41. public void pushDebugGroup(NSString @string)
  42. => objc_msgSend(NativePtr, Selectors.pushDebugGroup, @string.NativePtr);
  43. public void popDebugGroup() => objc_msgSend(NativePtr, Selectors.popDebugGroup);
  44. public void insertDebugSignpost(NSString @string)
  45. => objc_msgSend(NativePtr, Selectors.insertDebugSignpost, @string.NativePtr);
  46. }
  47. }