internal unsafe void __MarshalTo(ref __Native @ref) { @ref.NumEntries = Elements?.Length ?? 0; if (@ref.NumEntries > 0) { var nativeElements = (StreamOutputElement.__Native *)Interop.Alloc <StreamOutputElement.__Native>(@ref.NumEntries); for (int i = 0; i < @ref.NumEntries; i++) { Elements[i].__MarshalTo(ref nativeElements[i]); } @ref.pSODeclaration = nativeElements; } @ref.NumStrides = Strides?.Length ?? 0; if (@ref.NumStrides > 0) { var nativeStrides = Interop.Alloc <int>(@ref.NumStrides); fixed(int *src = &Strides[0]) { MemoryHelpers.CopyMemory(nativeStrides, (IntPtr)src, @ref.NumStrides * sizeof(int)); } @ref.pBufferStrides = nativeStrides; } @ref.RasterizedStream = RasterizedStream; }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.ByteStride = ByteStride; @ref.NumArgumentDescs = IndirectArguments?.Length ?? 0; if (@ref.NumArgumentDescs > 0) { @ref.pArgumentDescs = Interop.Alloc <IndirectArgumentDescription>(@ref.NumArgumentDescs); MemoryHelpers.CopyMemory( @ref.pArgumentDescs, (IntPtr)Unsafe.AsPointer(ref IndirectArguments[0]), @ref.NumArgumentDescs * sizeof(IndirectArgumentDescription)); } @ref.NodeMask = NodeMask; }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.NumElements = Elements?.Length ?? 0; if (@ref.NumElements > 0) { var nativeElements = (InputElementDescription.__Native *)Interop.Alloc <InputElementDescription.__Native>(@ref.NumElements); for (int i = 0; i < @ref.NumElements; i++) { Elements[i].__MarshalTo(ref nativeElements[i]); } @ref.pInputElementDescs = nativeElements; } }
public void ReAlloc() { IntPtr ptr = IntPtr.Zero; try { ptr = Interop.Alloc(32); ptr = Interop.ReAlloc(ptr, 64); Assert.NotEqual(IntPtr.Zero, ptr); } finally { Interop.Free(ptr); } }
/// <summary> /// Signal a fence when a device event occurs. /// </summary> /// <param name="device">A logical device on which the event may occur.</param> /// <param name="deviceEventInfo">A structure describing the event of interest to the application.</param> /// <param name="allocator">Controls host memory allocation.</param> /// <returns>The resulting fence object.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static Fence RegisterDeviceEventExt(this Device device, DeviceEventInfoExt deviceEventInfo, AllocationCallbacks? allocator = null) { deviceEventInfo.Prepare(); AllocationCallbacks.Native* nativeAllocator = null; if (allocator.HasValue) { nativeAllocator = (AllocationCallbacks.Native*)Interop.Alloc<AllocationCallbacks.Native>(); allocator.Value.ToNative(nativeAllocator); } long handle; Result result = vkRegisterDeviceEventEXT(device)(device, &deviceEventInfo, nativeAllocator, &handle); Interop.Free(nativeAllocator); VulkanException.ThrowForInvalidResult(result); return new Fence(device, ref allocator, handle); }
unsafe IntPtr IStateSubObjectDescriptionMarshal.__MarshalAlloc(Dictionary <StateSubObject, IntPtr> subObjectLookup) { __Native *native = (__Native *)Marshal.AllocHGlobal(sizeof(__Native)); DxilLibrary.__MarshalTo(ref native->DXILLibrary); native->NumExports = Exports?.Length ?? 0; if (native->NumExports > 0) { var nativeExports = (ExportDescription.__Native *)Interop.Alloc <ExportDescription.__Native>(native->NumExports); for (int i = 0; i < native->NumExports; i++) { Exports[i].__MarshalTo(ref nativeExports[i]); } native->pExports = nativeExports; } return((IntPtr)native); }
unsafe IntPtr IStateSubObjectDescriptionMarshal.__MarshalAlloc(Dictionary <StateSubObject, IntPtr> subObjectLookup) { __Native *native = (__Native *)Marshal.AllocHGlobal(sizeof(__Native)); native->pExistingCollection = CppObject.ToCallbackPtr <ID3D12StateObject>(ExistingCollection); native->NumExports = Exports?.Length ?? 0; if (native->NumExports > 0) { var nativeExports = (ExportDescription.__Native *)Interop.Alloc <ExportDescription.__Native>(native->NumExports); for (int i = 0; i < native->NumExports; i++) { Exports[i].__MarshalTo(ref nativeExports[i]); } native->pExports = nativeExports; } return((IntPtr)native); }
/// <summary> /// Create a <see cref="SurfaceKhr"/> object for a VI layer. /// <para> /// During the lifetime of a surface created using a particular `NativeWindowHandle`, any /// attempts to create another surface for the same `Layer` and any attempts to connect to /// the same layer through other platform mechanisms will have undefined results. /// </para> /// <para> /// The <see cref="SurfaceCapabilitiesKhr.CurrentExtent"/> of a VI surface is always /// undefined. Applications are expected to choose an appropriate size for the swapchain's /// <see cref="SwapchainCreateInfoKhr.ImageExtent"/> (e.g., by matching the the result of a /// call to `GetDisplayResolution`). /// </para> /// </summary> /// <param name="instance">The <see cref="Instance"/> to associate with the surface.</param> /// <param name="createInfo"> /// The structure containing the parameters affecting the creation of the surface object. /// </param> /// <param name="allocator"> /// The allocator used for host memory allocated for the surface object. /// </param> /// <returns>The resulting surface object handle.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static SurfaceKhr CreateVISurfaceNN(this Instance instance, VISurfaceCreateInfoNN createInfo, AllocationCallbacks?allocator = null) { createInfo.Prepare(); AllocationCallbacks.Native *nativeAllocator = null; if (allocator.HasValue) { nativeAllocator = (AllocationCallbacks.Native *)Interop.Alloc <AllocationCallbacks.Native>(); allocator.Value.ToNative(nativeAllocator); } long handle; Result result = vkCreateViSurfaceNN(instance)(instance, &createInfo, nativeAllocator, &handle); Interop.Free(nativeAllocator); VulkanException.ThrowForInvalidResult(result); return(new SurfaceKhr(instance, ref allocator, handle)); }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.shaderBufferSize = ShaderBufferWithInputSignature?.Length ?? 0; if (@ref.shaderBufferSize > 0) { @ref.shaderBufferWithInputSignature = Interop.AllocToPointer(ShaderBufferWithInputSignature); } @ref.elementCount = Elements?.Length ?? 0; if (@ref.elementCount > 0) { var nativeElements = (InputElementDescription.__Native *)Interop.Alloc <InputElementDescription.__Native>(@ref.elementCount); for (int i = 0; i < @ref.elementCount; i++) { Elements[i].__MarshalTo(ref nativeElements[i]); } @ref.inputElements = nativeElements; } @ref.stride = Stride; }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.Type = Type; @ref.NumSubobjects = SubObjects?.Length ?? 0; if (@ref.NumSubobjects > 0) { var subObjectLookup = new Dictionary <StateSubObject, IntPtr>(); var nativeSubObjects = (StateSubObject.__Native *)Interop.Alloc <StateSubObject.__Native>(@ref.NumSubobjects); // Create lookup table first for (int i = 0; i < @ref.NumSubobjects; i++) { subObjectLookup.Add(SubObjects[i], new IntPtr(&nativeSubObjects[i])); } for (int i = 0; i < @ref.NumSubobjects; i++) { SubObjects[i].__MarshalTo(ref nativeSubObjects[i], subObjectLookup); } @ref.pSubobjects = nativeSubObjects; } }
public void AllocZeroBytes() { IntPtr handle = Interop.Alloc(0); Assert.Equal(IntPtr.Zero, handle); }