public VkFormat ConvertToVertexVkFormat(GAL.Format srcFormat) { var format = FormatTable.GetFormat(srcFormat); if (!BufferFormatSupports(FormatFeatureFlags.FormatFeatureVertexBufferBit, srcFormat) || (IsRGB16IntFloat(srcFormat) && VulkanConfiguration.ForceRGB16IntFloatUnsupported)) { // The format is not supported. Can we convert it to an alternative format? switch (srcFormat) { case GAL.Format.R16G16B16Float: format = VkFormat.R16G16B16A16Sfloat; break; case GAL.Format.R16G16B16Sint: format = VkFormat.R16G16B16A16Sint; break; case GAL.Format.R16G16B16Uint: format = VkFormat.R16G16B16A16Uint; break; default: Logger.Error?.Print(LogClass.Gpu, $"Format {srcFormat} is not supported by the host."); break; } } return(format); }
public TextureView GetView(GAL.Format format) { if (format == Info.Format) { return(this); } if (_selfManagedViews != null && _selfManagedViews.TryGetValue(format, out var view)) { return(view); } view = CreateViewImpl(new TextureCreateInfo( Info.Width, Info.Height, Info.Depth, Info.Levels, Info.Samples, Info.BlockWidth, Info.BlockHeight, Info.BytesPerPixel, format, Info.DepthStencilMode, Info.Target, Info.SwizzleR, Info.SwizzleG, Info.SwizzleB, Info.SwizzleA), 0, 0); (_selfManagedViews ??= new Dictionary <GAL.Format, TextureView>()).Add(format, view); return(view); }
public TextureStorage CreateAliasedStorageUnsafe(GAL.Format format) { if (_aliasedStorages == null || !_aliasedStorages.TryGetValue(format, out var storage)) { _aliasedStorages ??= new Dictionary <GAL.Format, TextureStorage>(); var info = NewCreateInfoWith(ref _info, format, _info.BytesPerPixel); storage = new TextureStorage(_gd, default, _device, info, ScaleFactor, _allocationAuto);
private GAL.Format GetCompatibleGalFormat(GAL.Format format) { if (NeedsD24S8Conversion()) { return(GAL.Format.D32FloatS8Uint); } return(format); }
public bool FormatSupports(GAL.Format format, FormatFeatureFlags flags) { var formatFeatureFlags = _table[(int)format]; if (formatFeatureFlags == 0) { _api.GetPhysicalDeviceFormatProperties(_physicalDevice, FormatTable.GetFormat(format), out var fp); formatFeatureFlags = fp.OptimalTilingFeatures; _table[(int)format] = formatFeatureFlags; } return((formatFeatureFlags & flags) == flags); }
public bool BufferFormatSupports(FormatFeatureFlags flags, GAL.Format format) { var formatFeatureFlags = _bufferTable[(int)format]; if (formatFeatureFlags == 0) { _api.GetPhysicalDeviceFormatProperties(_physicalDevice, FormatTable.GetFormat(format), out var fp); formatFeatureFlags = fp.BufferFeatures; _bufferTable[(int)format] = formatFeatureFlags; } return((formatFeatureFlags & flags) == flags); }
public TextureStorage CreateAliasedColorForDepthStorageUnsafe(GAL.Format format) { var colorFormat = format switch { GAL.Format.S8Uint => GAL.Format.R8Unorm, GAL.Format.D16Unorm => GAL.Format.R16Unorm, GAL.Format.S8UintD24Unorm => GAL.Format.R8G8B8A8Unorm, GAL.Format.D32Float => GAL.Format.R32Float, GAL.Format.D24UnormS8Uint => GAL.Format.R8G8B8A8Unorm, GAL.Format.D32FloatS8Uint => GAL.Format.R32G32Float, _ => throw new ArgumentException($"\"{format}\" is not a supported depth or stencil format.") }; return(CreateAliasedStorageUnsafe(colorFormat)); }
public void SetImage(int binding, ITexture image, GAL.Format imageFormat) { if (image == null) { return; } if (image is TextureBuffer imageBuffer) { _bufferImageRefs[binding] = imageBuffer; _bufferImageFormats[binding] = imageFormat; } else if (image is TextureView view) { _imageRefs[binding] = view.GetView(imageFormat).GetIdentityImageView(); } SignalDirty(DirtyFlags.Image); }
public static ImageAspectFlags ConvertAspectFlags(this GAL.Format format, DepthStencilMode depthStencilMode) { switch (format) { case GAL.Format.D16Unorm: case GAL.Format.D24X8Unorm: case GAL.Format.D32Float: return(ImageAspectFlags.ImageAspectDepthBit); case GAL.Format.S8Uint: return(ImageAspectFlags.ImageAspectStencilBit); case GAL.Format.D24UnormS8Uint: case GAL.Format.D32FloatS8Uint: return(depthStencilMode == DepthStencilMode.Stencil ? ImageAspectFlags.ImageAspectStencilBit : ImageAspectFlags.ImageAspectDepthBit); default: return(ImageAspectFlags.ImageAspectColorBit); } }
public BufferView GetBufferView(CommandBufferScoped cbs, GAL.Format format) { var vkFormat = FormatTable.GetFormat(format); if (vkFormat == VkFormat) { return GetBufferView(cbs); } if (_selfManagedViews != null && _selfManagedViews.TryGetValue(format, out var bufferView)) { return bufferView.Get(cbs, _offset, _size).Value; } bufferView = _gd.BufferManager.CreateView(_bufferHandle, vkFormat, _offset, _size); if (bufferView != null) { (_selfManagedViews ??= new Dictionary<GAL.Format, Auto<DisposableBufferView>>()).Add(format, bufferView); } return bufferView?.Get(cbs, _offset, _size).Value ?? default; }
public void SetImage(int binding, ITexture image, GAL.Format imageFormat) { if (image == null) { return; } if (image is TextureBuffer imageBuffer) { if (_bufferImages.Length <= binding) { Array.Resize(ref _bufferImages, binding + 1); Array.Resize(ref _bufferImageRefs, binding + 1); } _bufferImageRefs[binding] = imageBuffer; SignalDirty(DirtyFlags.BufferImage); } else { if (_images.Length <= binding) { Array.Resize(ref _images, binding + 1); Array.Resize(ref _imageRefs, binding + 1); } if (image != null) { _imageRefs[binding] = ((TextureView)image).GetIdentityImageView(); _images[binding] = new DescriptorImageInfo() { ImageLayout = ImageLayout.General }; } SignalDirty(DirtyFlags.Image); } }
public VkFormat ConvertToVkFormat(GAL.Format srcFormat) { var format = FormatTable.GetFormat(srcFormat); var requiredFeatures = FormatFeatureFlags.FormatFeatureSampledImageBit | FormatFeatureFlags.FormatFeatureTransferSrcBit | FormatFeatureFlags.FormatFeatureTransferDstBit; if (srcFormat.IsDepthOrStencil()) { requiredFeatures |= FormatFeatureFlags.FormatFeatureDepthStencilAttachmentBit; } else if (srcFormat.IsRtColorCompatible()) { requiredFeatures |= FormatFeatureFlags.FormatFeatureColorAttachmentBit; } if (srcFormat.IsImageCompatible()) { requiredFeatures |= FormatFeatureFlags.FormatFeatureStorageImageBit; } if (!FormatSupports(srcFormat, requiredFeatures)) { // The format is not supported. Can we convert it to a higher precision format? if (srcFormat == GAL.Format.D24UnormS8Uint) { format = VkFormat.D32SfloatS8Uint; } else { Logger.Error?.Print(LogClass.Gpu, $"Format {srcFormat} is not supported by the host."); } } return(format); }
public TextureStorage CreateAliasedStorageUnsafe(GAL.Format format) { if (_aliasedStorages == null || !_aliasedStorages.TryGetValue(format, out var storage)) { _aliasedStorages ??= new Dictionary <GAL.Format, TextureStorage>(); var info = new TextureCreateInfo( _info.Width, _info.Height, _info.Depth, _info.Levels, _info.Samples, _info.BlockWidth, _info.BlockHeight, _info.BytesPerPixel, format, _info.DepthStencilMode, _info.Target, _info.SwizzleR, _info.SwizzleG, _info.SwizzleB, _info.SwizzleA); storage = new TextureStorage(_gd, default, _device, info, ScaleFactor, _allocationAuto);
private static bool IsRGB16IntFloat(GAL.Format format) { return(format == GAL.Format.R16G16B16Float || format == GAL.Format.R16G16B16Sint || format == GAL.Format.R16G16B16Uint); }
public static bool IsD24S8(GAL.Format format) { return(format == GAL.Format.D24UnormS8Uint || format == GAL.Format.S8UintD24Unorm); }