private void CreateImage(uint width, uint height, Format format, ImageTiling imageTiling, ImageUsageFlags usage, MemoryPropertyFlags properties, out Image image, out DeviceMemory imageMemory) { image = this.device.CreateImage(new ImageCreateInfo { ImageType = ImageType.Image2d, Extent = new Extent3D { Width = width, Height = height, Depth = 1 }, ArrayLayers = 1, MipLevels = 1, Format = format, Tiling = imageTiling, InitialLayout = ImageLayout.Preinitialized, Usage = usage, SharingMode = SharingMode.Exclusive, Samples = SampleCountFlags.SampleCount1, Flags = ImageCreateFlags.None }); var memoryRequirements = image.GetMemoryRequirements(); imageMemory = this.device.AllocateMemory(new MemoryAllocateInfo { AllocationSize = memoryRequirements.Size, MemoryTypeIndex = this.FindMemoryType(memoryRequirements.MemoryTypeBits, properties) }); image.BindMemory(imageMemory, 0); }
public ImageCreateInfo ( StructureType sType = StructureType.ImageCreateInfo, void *pNext = default, ImageCreateFlags flags = default, ImageType imageType = default, Format format = default, Extent3D extent = default, uint mipLevels = default, uint arrayLayers = default, SampleCountFlags samples = default, ImageTiling tiling = default, ImageUsageFlags usage = default, SharingMode sharingMode = default, uint queueFamilyIndexCount = default, uint *pQueueFamilyIndices = default, ImageLayout initialLayout = default ) { SType = sType; PNext = pNext; Flags = flags; ImageType = imageType; Format = format; Extent = extent; MipLevels = mipLevels; ArrayLayers = arrayLayers; Samples = samples; Tiling = tiling; Usage = usage; SharingMode = sharingMode; QueueFamilyIndexCount = queueFamilyIndexCount; PQueueFamilyIndices = pQueueFamilyIndices; InitialLayout = initialLayout; }
internal bool IsFormatSupported(Format format, ImageTiling tiling, FormatFeatures features) { var properties = physicalDevice.GetFormatProperties(format); switch (tiling) { case ImageTiling.Linear: return((properties.LinearTilingFeatures & features) == features); case ImageTiling.Optimal: return((properties.OptimalTilingFeatures & features) == features); } return(false); }
private void CreateImage(uint width, uint height, Format format, ImageTiling imageTiling, ImageUsageFlags usage, MemoryPropertyFlags properties, bool isPreinitialized, out Image image, out DeviceMemory imageMemory, out DeviceSize memoryOffset, out DeviceSize memorySize) { image = this.device.CreateImage(ImageType.Image2d, format, new Extent3D(width, height, 1), 1, 1, SampleCountFlags.SampleCount1, imageTiling, usage, this.queueIndices.Indices.Count() == 1 ? SharingMode.Exclusive : SharingMode.Concurrent, this.queueIndices.Indices.ToArray(), isPreinitialized ? ImageLayout.Preinitialized : ImageLayout.Undefined); var memoryRequirements = image.GetMemoryRequirements(); memorySize = memoryRequirements.Size; imageMemory = this.device.AllocateMemory(memorySize, this.FindMemoryType(memoryRequirements.MemoryTypeBits, properties)); memoryOffset = 0; image.BindMemory(imageMemory, memoryOffset); }
private Image CreateImage(ImageCreateFlags flags = 0, ImageTiling tiling = ImageTiling.Optimal) { var createInfo = new ImageCreateInfo { ArrayLayers = 1, Extent = new Extent3D(DefaultWidth, DefaultHeight, 1), Format = Format.B8G8R8A8UNorm, ImageType = ImageType.Image2D, Usage = ImageUsages.TransferSrc | ImageUsages.Sampled, MipLevels = 1, Samples = SampleCounts.Count1, Flags = flags, Tiling = tiling }; return Device.CreateImage(createInfo); }
private Format FindSupportedFormat(IEnumerable <Format> candidates, ImageTiling tiling, FormatFeatureFlags features) { foreach (var format in candidates) { var props = this.physicalDevice.GetFormatProperties(format); if (tiling == ImageTiling.Linear && props.LinearTilingFeatures.HasFlag(features)) { return(format); } else if (tiling == ImageTiling.Optimal && props.OptimalTilingFeatures.HasFlag(features)) { return(format); } } throw new Exception("failed to find supported format!"); }
public PhysicalDeviceSparseImageFormatInfo2KHR ( StructureType sType = StructureType.PhysicalDeviceSparseImageFormatInfo2, void *pNext = default, Format format = default, ImageType type = default, SampleCountFlags samples = default, ImageUsageFlags usage = default, ImageTiling tiling = default ) { SType = sType; PNext = pNext; Format = format; Type = type; Samples = samples; Usage = usage; Tiling = tiling; }
public PhysicalDeviceImageFormatInfo2KHR ( StructureType sType = StructureType.PhysicalDeviceImageFormatInfo2, void *pNext = default, Format format = default, ImageType type = default, ImageTiling tiling = default, ImageUsageFlags usage = default, ImageCreateFlags flags = default ) { SType = sType; PNext = pNext; Format = format; Type = type; Tiling = tiling; Usage = usage; Flags = flags; }
internal static unsafe extern Result vkGetPhysicalDeviceImageFormatProperties(PhysicalDevice physicalDevice, Format format, ImageType type, ImageTiling tiling, ImageUsageFlags usage, ImageCreateFlags flags, ImageFormatProperties *ImageFormatProperties);
internal static unsafe extern void vkGetPhysicalDeviceSparseImageFormatProperties(PhysicalDevice physicalDevice, Format format, ImageType type, SampleCountFlags samples, ImageUsageFlags usage, ImageTiling tiling, out UInt32 *PropertyCount, SparseImageFormatProperties *Properties);
internal static unsafe extern Result vkGetPhysicalDeviceImageFormatProperties(PhysicalDevice physicalDevice, Format format, ImageType type, ImageTiling tiling, ImageUsageFlags usage, ImageCreateFlags flags, ImageFormatProperties* imageFormatProperties);
public unsafe SparseImageFormatProperties[] GetSparseImageFormatProperties(Format format, ImageType type, SampleCountFlags samples, ImageUsageFlags usage, ImageTiling tiling) { uint count = 0; GetSparseImageFormatProperties(format, type, samples, usage, tiling, ref count, null); var result = new SparseImageFormatProperties[count]; if (count > 0) { fixed(SparseImageFormatProperties *resultPointer = &result[0]) GetSparseImageFormatProperties(format, type, samples, usage, tiling, ref count, resultPointer); } return(result); }
/// <summary> /// Determine image capabilities compatible with external memory handle types. /// </summary> /// <param name="physicalDevice">The physical device from which to query the image capabilities.</param> /// <param name="format">The image format, corresponding to <see cref="ImageCreateInfo.Format"/>.</param> /// <param name="type">The image type, corresponding to <see cref="ImageCreateInfo.ImageType"/>.</param> /// <param name="tiling">The image tiling, corresponding to <see cref="ImageCreateInfo.Tiling"/>.</param> /// <param name="usage">The intended usage of the image, corresponding to <see cref="ImageCreateInfo.Usage"/>.</param> /// <param name="flags"> /// A bitmask describing additional parameters of the image, corresponding to <see cref="ImageCreateInfo.Flags"/>. /// </param> /// <param name="externalHandleType"> /// Either one of the bits from <see cref="ExternalMemoryHandleTypesNV"/>, or 0. /// </param> /// <returns>The structure in which capabilities are returned.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static ExternalImageFormatPropertiesNV GetExternalImageFormatPropertiesNV(this PhysicalDevice physicalDevice, Format format, ImageType type, ImageTiling tiling, ImageUsages usage, ImageCreateFlags flags, ExternalMemoryHandleTypesNV externalHandleType) { ExternalImageFormatPropertiesNV properties; Result result = vkGetPhysicalDeviceExternalImageFormatPropertiesNV(physicalDevice, format, type, tiling, usage, flags, externalHandleType, &properties); VulkanException.ThrowForInvalidResult(result); return(properties); }
public static extern unsafe Result vkGetPhysicalDeviceImageFormatProperties(IntPtr physicalDevice, Format format, ImageType type, ImageTiling tiling, ImageUsageFlags usage, ImageCreateFlags flags, ImageFormatProperties *pImageFormatProperties);
public unsafe SparseImageFormatProperties[] GetSparseImageFormatProperties(Format format, ImageType type, SampleCountFlags samples, ImageUsageFlags usage, ImageTiling tiling) { uint count = 0; GetSparseImageFormatProperties(format, type, samples, usage, tiling, ref count, null); var result = new SparseImageFormatProperties[count]; if (count > 0) { fixed (SparseImageFormatProperties* resultPointer = &result[0]) GetSparseImageFormatProperties(format, type, samples, usage, tiling, ref count, resultPointer); } return result; }
/// <summary> /// Retrieve properties of an image format applied to sparse images. /// </summary> public SparseImageFormatProperties[] GetSparseImageFormatProperties(Format format, ImageType type, SampleCountFlags samples, ImageUsageFlags usage, ImageTiling tiling) { unsafe { try { SparseImageFormatProperties[] result = default(SparseImageFormatProperties[]); uint propertyCount; SparseImageFormatProperties *marshalledProperties = null; Interop.Commands.vkGetPhysicalDeviceSparseImageFormatProperties(this.handle, format, type, samples, usage, tiling, &propertyCount, null); marshalledProperties = (SparseImageFormatProperties *)Interop.HeapUtil.Allocate <SparseImageFormatProperties>((uint)propertyCount); Interop.Commands.vkGetPhysicalDeviceSparseImageFormatProperties(this.handle, format, type, samples, usage, tiling, &propertyCount, marshalledProperties); result = new SparseImageFormatProperties[(uint)propertyCount]; for (int index = 0; index < (uint)propertyCount; index++) { result[index] = marshalledProperties[index]; } return(result); } finally { Interop.HeapUtil.FreeLog(); } } }
public VulkanImage CreateImage(uint width, uint height, Format format, ImageTiling imageTiling, ImageUsageFlags usage, MemoryPropertyFlags properties, bool isPreinitialized) { this.CreateImage(width, height, format, imageTiling, usage, properties, isPreinitialized, out var image, out var imageMemory, out DeviceSize offset, out DeviceSize size); return(new VulkanImage(this, image, imageMemory, offset, size, format)); }
public static bool GetHSolutionBestCasePallet( List <ContentItem> items, PalletProperties palletProperties, HConstraintSetPallet constraintSet, Vector3D cameraPosition, bool showCotations, float fontSizeRatio, Size sz, ref int palletCount, ref string algorithm, ref byte[] imageBytes, ref string[] errors) { List <string> lErrors = new List <string>(); try { var analysis = new HAnalysisPallet(null) { Pallet = palletProperties, ConstraintSet = constraintSet, Content = items, }; HSolver solver = new HSolver(); var solutions = solver.BuildSolutions(analysis); // get first solution (Sharp3DBin packing) if (solutions.Count > 0) { var sol = solutions[0]; algorithm = sol.Algorithm; palletCount = sol.SolItemCount; var tileSize = ImageTiling.TileSize(sz, palletCount); var listTiles = new List <Bitmap>(); for (int i = 0; i < palletCount; ++i) { Graphics3DImage graphics = new Graphics3DImage(tileSize) { FontSizeRatio = fontSizeRatio, CameraPosition = cameraPosition, ShowDimensions = showCotations }; ViewerHSolution sv = new ViewerHSolution(sol, i); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); listTiles.Add(graphics.Bitmap); } var bmp = ImageTiling.TileImage(sz, listTiles); ImageConverter converter = new ImageConverter(); imageBytes = (byte[])converter.ConvertTo(bmp, typeof(byte[])); } else { lErrors.Add("No valid solution found"); } } catch (Exception ex) { lErrors.Add(ex.Message); } errors = lErrors.ToArray(); return(0 == lErrors.Count); }
public VulkanImage CreateImage(uint width, uint height, Format format, ImageTiling imageTiling, ImageUsageFlags usage, MemoryPropertyFlags properties) { this.CreateImage(width, height, format, imageTiling, usage, properties, out var image, out var memory); return(new VulkanImage(this, image, memory, format)); }
internal unsafe void GetSparseImageFormatProperties(Format format, ImageType type, SampleCountFlags samples, ImageUsageFlags usage, ImageTiling tiling, ref uint propertyCount, SparseImageFormatProperties* properties) { fixed (uint* __propertyCount__ = &propertyCount) { vkGetPhysicalDeviceSparseImageFormatProperties(this, format, type, samples, usage, tiling, __propertyCount__, properties); } }
internal static unsafe extern void vkGetPhysicalDeviceSparseImageFormatProperties(PhysicalDevice physicalDevice, Format format, ImageType type, SampleCountFlags samples, ImageUsageFlags usage, ImageTiling tiling, uint* propertyCount, SparseImageFormatProperties* properties);
static void Main(string[] args) { string outputDir = @"D:\GitHub\StackBuilder\Sources\Test\treeDiM.StackBuilder.Engine.Heterogeneous3D.Test\Output"; DirectoryInfo directory = new DirectoryInfo(outputDir); directory.Empty(); var palletProperties = new PalletProperties(null, "EUR2", 1200.0, 1000.0, 140.0) { Color = Color.Yellow, Weight = 22.0 }; bool allowXY = false; var items = new List <ContentItem> { new ContentItem(new BoxProperties(null, 190, 200, 420, 10.0, Color.Red), 2) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, new ContentItem(new BoxProperties(null, 250, 200, 300, 10.0, Color.Blue), 1) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, new ContentItem(new BoxProperties(null, 250, 200, 250, 10.0, Color.Green), 1) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, new ContentItem(new BoxProperties(null, 250, 200, 290, 10.0, Color.Green), 1) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, new ContentItem(new BoxProperties(null, 80, 200, 210, 10.0, Color.White), 4) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, // 9 new ContentItem(new BoxProperties(null, 360, 460, 840, 10.0, Color.Purple), 1) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, new ContentItem(new BoxProperties(null, 160, 460, 100, 10.0, Color.AliceBlue), 2) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, new ContentItem(new BoxProperties(null, 160, 460, 320, 10.0, Color.Beige), 2) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, new ContentItem(new BoxProperties(null, 200, 300, 150, 10.0, Color.Brown), 1) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, new ContentItem(new BoxProperties(null, 200, 300, 690, 10.0, Color.Chartreuse), 1) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, // 7 new ContentItem(new BoxProperties(null, 200, 300, 210, 10.0, Color.Cyan), 4) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, new ContentItem(new BoxProperties(null, 120, 300, 70, 10.0, Color.LightPink), 12) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, new ContentItem(new BoxProperties(null, 520, 600, 420, 10.0, Color.LightGray), 2) { AllowedOrientations = new bool[] { allowXY, allowXY, true }, PriorityLevel = 0 }, new ContentItem(new BoxProperties(null, 260, 360, 210, 10.0, Color.Yellow), 4) { AllowedOrientations = new bool[] { allowXY, allowXY, true } }, new ContentItem(new BoxProperties(null, 260, 360, 840, 10.0, Color.Orange), 1) { AllowedOrientations = new bool[] { allowXY, allowXY, true } } // 23 }; var sortedItems = items.OrderBy(i => i.Pack.OuterDimensions.X * i.Pack.OuterDimensions.Y * i.Number).ToList(); var constraintSet = new HConstraintSetPallet() { MaximumHeight = 1300.0 }; var analysis = new HAnalysisPallet(null) { Pallet = palletProperties, ConstraintSet = constraintSet, Content = sortedItems }; HSolver solver = new HSolver(); var solutions = solver.BuildSolutions(analysis); int solIndex = 0; foreach (var sol in solutions) { Vector3D[] orientations = new Vector3D[] { Graphics3D.Corner_0, Graphics3D.Corner_90, Graphics3D.Corner_180, Graphics3D.Corner_270 }; for (int iOrientation = 0; iOrientation < 4; ++iOrientation) { List <Bitmap> images = new List <Bitmap>(); for (int binIndex = 0; binIndex < sol.SolItemCount; ++binIndex) { Vector3D bbGlob = sol.BBoxGlobal(binIndex).DimensionsVec; Vector3D bbLoad = sol.BBoxLoad(binIndex).DimensionsVec; double weightLoad = sol.LoadWeight(binIndex); double weightTotal = sol.Weight(binIndex); Graphics3DImage graphics = new Graphics3DImage(ImageTiling.TileSize(new Size(4000, 4000), sol.SolItemCount)) { FontSizeRatio = 0.02f, CameraPosition = orientations[iOrientation], ShowDimensions = false }; ViewerHSolution sv = new ViewerHSolution(sol, binIndex); sv.Draw(graphics, Transform3D.Identity); graphics.Flush(); images.Add(graphics.Bitmap); } Bitmap gBmp = ImageTiling.TileImage(new Size(2000, 2000), images); string sbSolutionName = $"sol_{sol.Algorithm}_{solIndex}_{iOrientation}.png"; gBmp.Save(Path.Combine(outputDir, sbSolutionName)); Console.WriteLine($"Saving {sbSolutionName}..."); } ++solIndex; } }
public FrameBufferAttachment CreateAttachment(string AttachmentLookupID, Format myFormat, ImageType myType, ImageViewType view2D, ImageUsageFlags myImageFlag, ImageAspectFlags color, ImageTiling myTiles, SampleCountFlags mySampleCount, uint levelCount, uint layercount) { //TODO: Write exception class if (Initialized) { throw new Exception("Attempted to add attachment to initialized Framebuffer!"); } if (myAttachments.ContainsKey(AttachmentLookupID)) { throw new Exception("A framebuffer attachment with ID: " + AttachmentLookupID + " was added to frame buffer twice."); } ImageCreateInfo myInfo = new ImageCreateInfo() { ImageType = myType, MipLevels = 1, Format = myFormat, Extent = new Extent3D() { Width = myFramebufferInfo.Width, Height = myFramebufferInfo.Height, Depth = 1 }, ArrayLayers = layercount, Samples = mySampleCount, Tiling = myTiles, Usage = myImageFlag }; myImage = new Image(myInfo); var Return = this.CreateAttachment(AttachmentLookupID, myFormat, view2D, myImage, color, levelCount, layercount); myAttachments[AttachmentLookupID] = Return; myInfo.Dispose(false); return(Return); }
/// <summary> /// Determine image capabilities compatible with external memory handle /// types. /// </summary> public ExternalImageFormatProperties GetExternalImageFormatProperties(Format format, ImageType type, ImageTiling tiling, ImageUsageFlags usage, ImageCreateFlags flags, ExternalMemoryHandleTypeFlags externalHandleType) { unsafe { try { var commandDelegate = this.commandCache.GetCommandDelegate <Interop.vkGetPhysicalDeviceExternalImageFormatPropertiesNV>("vkGetPhysicalDeviceExternalImageFormatPropertiesNV", "instance"); ExternalImageFormatProperties result = default(ExternalImageFormatProperties); Result commandResult; commandResult = commandDelegate(this.handle, format, type, tiling, usage, flags, externalHandleType, &result); if (SharpVkException.IsError(commandResult)) { throw SharpVkException.Create(commandResult); } return(result); } finally { Interop.HeapUtil.FreeLog(); } } }
/// <param name="Usage">Image usage flags</param> /// <param name="SharingMode">Cross-queue-family sharing mode</param> /// <param name="QueueFamilyIndices">Array of queue family indices to share across</param> /// <param name="InitialLayout">Initial image layout for all subresources</param> public ImageCreateInfo(ImageType ImageType, Format Format, Extent3D Extent, UInt32 MipLevels, UInt32 ArrayLayers, SampleCountFlags Samples, ImageTiling Tiling, ImageUsageFlags Usage, SharingMode SharingMode, UInt32[] QueueFamilyIndices, ImageLayout InitialLayout) : this() { this.ImageType = ImageType; this.Format = Format; this.Extent = Extent; this.MipLevels = MipLevels; this.ArrayLayers = ArrayLayers; this.Samples = Samples; this.Tiling = Tiling; this.Usage = Usage; this.SharingMode = SharingMode; this.QueueFamilyIndices = QueueFamilyIndices; this.InitialLayout = InitialLayout; }
public static extern unsafe void vkGetPhysicalDeviceSparseImageFormatProperties(IntPtr physicalDevice, Format format, ImageType type, SampleCountFlags samples, ImageUsageFlags usage, ImageTiling tiling, uint *pPropertyCount, SparseImageFormatProperties *pProperties);
/// <summary>To be documented.</summary> public static unsafe Result GetPhysicalDeviceExternalImageFormatProperties(this NVExternalMemoryCapabilities thisApi, [Count(Count = 0)] PhysicalDevice physicalDevice, [Count(Count = 0)] Format format, [Count(Count = 0)] ImageType type, [Count(Count = 0)] ImageTiling tiling, [Count(Count = 0)] ImageUsageFlags usage, [Count(Count = 0)] ImageCreateFlags flags, [Count(Count = 0)] ExternalMemoryHandleTypeFlagsNV externalHandleType, [Count(Count = 0), Flow(FlowDirection.Out)] Span <ExternalImageFormatPropertiesNV> pExternalImageFormatProperties) { // SpanOverloader return(thisApi.GetPhysicalDeviceExternalImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, externalHandleType, out pExternalImageFormatProperties.GetPinnableReference())); }
internal static unsafe extern Result vkGetPhysicalDeviceExternalImageFormatPropertiesNV(IntPtr physicalDevice, Format format, ImageType type, ImageTiling tiling, ImageUsageFlags usage, ImageCreateFlags flags, ExternalMemoryHandleTypeFlagsNv externalHandleType, ExternalImageFormatPropertiesNv *pExternalImageFormatProperties);
public unsafe void GetImageFormatProperties(Format format, ImageType type, ImageTiling tiling, ImageUsageFlags usage, ImageCreateFlags flags, out ImageFormatProperties imageFormatProperties) { fixed (ImageFormatProperties* __imageFormatProperties__ = &imageFormatProperties) { vkGetPhysicalDeviceImageFormatProperties(this, format, type, tiling, usage, flags, __imageFormatProperties__).CheckError(); } }
public partial Result GetPhysicalDeviceExternalImageFormatProperties([Count(Count = 0)] PhysicalDevice physicalDevice, [Count(Count = 0)] Format format, [Count(Count = 0)] ImageType type, [Count(Count = 0)] ImageTiling tiling, [Count(Count = 0)] ImageUsageFlags usage, [Count(Count = 0)] ImageCreateFlags flags, [Count(Count = 0)] ExternalMemoryHandleTypeFlagsNV externalHandleType, [Count(Count = 0), Flow(FlowDirection.Out)] out ExternalImageFormatPropertiesNV pExternalImageFormatProperties);
/// <summary> /// Lists physical device's image format capabilities. /// </summary> public ImageFormatProperties GetImageFormatProperties(Format format, ImageType type, ImageTiling tiling, ImageUsageFlags usage, ImageCreateFlags flags) { unsafe { try { ImageFormatProperties result = default(ImageFormatProperties); Result commandResult; commandResult = Interop.Commands.vkGetPhysicalDeviceImageFormatProperties(this.handle, format, type, tiling, usage, flags, &result); if (SharpVkException.IsError(commandResult)) { throw SharpVkException.Create(commandResult); } return(result); } finally { Interop.HeapUtil.FreeLog(); } } }