public ComputeShader(Vk vk, Instance instance, Device device, PhysicalDevice physicalDevice, PipelineLayout pipelineLayout, ReadOnlySpan <byte> data, string functionName, SpecializationInfo *specializationInfo) { var subgroupProperties = new PhysicalDeviceSubgroupProperties(pNext: null); var properties = new PhysicalDeviceProperties2(pNext: &subgroupProperties); vk.GetPhysicalDeviceProperties2(physicalDevice, &properties); var subgroupSize = subgroupProperties.SubgroupSize; Console.WriteLine($"Detected subgroup size {subgroupSize}"); var data2 = new byte[data.Length + 32]; data.CopyTo(data2); _vk = vk; _device = device; ShaderModule shaderModule; fixed(byte *pData = data2) _vk.CreateShaderModule(_device, new ShaderModuleCreateInfo(codeSize: (nuint)data.Length, pCode: (uint *)pData), null, out shaderModule).ThrowCode(); try { var pName = SilkMarshal.StringToPtr(functionName); try { PipelineCreateFlags flags = 0; _vk.CreateComputePipelines(_device, default, 1, new ComputePipelineCreateInfo(flags: flags , layout: pipelineLayout, stage: new PipelineShaderStageCreateInfo(stage: ShaderStageFlags.ShaderStageComputeBit, module: shaderModule, pName: (byte *)pName, pSpecializationInfo: specializationInfo)), null, out _pipeline).ThrowCode(); }
public Auto <DescriptorSetCollection> AllocateDescriptorSet(Vk api, DescriptorSetLayout layout) { Span <DescriptorSetLayout> layouts = stackalloc DescriptorSetLayout[1]; layouts[0] = layout; return(AllocateDescriptorSets(api, layouts)); }
public BindlessDescriptorSet(Vk vk, Device device, int pushConstantSize, int numSampledImages = 512 * 1024, int numStorageImages = 64 * 1024, int numSamplers = 4 * 1024) { _vk = vk; _device = device; _pushConstantSize = pushConstantSize; _numSampledImages = numSampledImages; _numStorageImages = numStorageImages; _numSamplers = numSamplers; var pBindings = stackalloc DescriptorSetLayoutBinding[] { new DescriptorSetLayoutBinding(SampledImageBinding, DescriptorType.SampledImage, (uint)numSampledImages, ShaderStageFlags.ShaderStageAll), new DescriptorSetLayoutBinding(StorageImageBinding, DescriptorType.StorageImage, (uint)numStorageImages, ShaderStageFlags.ShaderStageAll), new DescriptorSetLayoutBinding(SamplerBinding, DescriptorType.Sampler, (uint)numSamplers, ShaderStageFlags.ShaderStageAll), }; _vk.CreateDescriptorSetLayout(_device, new DescriptorSetLayoutCreateInfo(flags: DescriptorSetLayoutCreateFlags.DescriptorSetLayoutCreateUpdateAfterBindPoolBit, bindingCount: 3, pBindings: pBindings), null, out var layout).ThrowCode(); _descriptorSetLayout = layout; if (pushConstantSize > 0) { var pushConstantRange = new PushConstantRange(ShaderStageFlags.ShaderStageAll, 0, (uint)pushConstantSize); _vk.CreatePipelineLayout(_device, new PipelineLayoutCreateInfo(setLayoutCount: 1, pSetLayouts: &layout, pushConstantRangeCount: 1, pPushConstantRanges: &pushConstantRange), null, out _pipelineLayout).ThrowCode(); } else { _vk.CreatePipelineLayout(_device, new PipelineLayoutCreateInfo(setLayoutCount: 1, pSetLayouts: &layout, pushConstantRangeCount: 0, pPushConstantRanges: null), null, out _pipelineLayout).ThrowCode(); } }
public bool Create() { Vk.GetPhysicalDeviceMemoryProperties(Params.PhysicalDevice, out _physicalDeviceMemoryProperties); Shader = new Shader("SilkyNvg-Vulkan-Shader", EdgeAntiAlias, this); if (!Shader.Status) { return(false); } Shader.CreateLayout(); for (int i = 0; i < _frames.Length; i++) { _frames[i] = new Frame(this); } Shader.InitializeFragUniformBuffers(); InitializeImageTransition(); DummyTex = CreateTexture(Texture.Alpha, new Vector2D <uint>(1, 1), 0, null); return(true); }
public bool MayWait(Vk api, Device device, int offset, int size) { if (_fences.Count == 0) { return(false); } if (VulkanConfiguration.UseGranularBufferTracking) { lock (_fences) { foreach (var kv in _fences) { var fence = kv.Key; var ownerCbIndex = kv.Value; if (_rangeList.OverlapsWith(ownerCbIndex, offset, size)) { return(true); } } } return(false); } else { return(true); } }
public static uint FindSuitableQueueFamily(Vk api, PhysicalDevice physicalDevice, SurfaceKHR surface, out uint queueCount) { const QueueFlags RequiredFlags = QueueFlags.QueueGraphicsBit | QueueFlags.QueueComputeBit; var khrSurface = new KhrSurface(api.Context); uint propertiesCount; api.GetPhysicalDeviceQueueFamilyProperties(physicalDevice, &propertiesCount, null); QueueFamilyProperties[] properties = new QueueFamilyProperties[propertiesCount]; fixed(QueueFamilyProperties *pProperties = properties) { api.GetPhysicalDeviceQueueFamilyProperties(physicalDevice, &propertiesCount, pProperties); } for (uint index = 0; index < propertiesCount; index++) { var queueFlags = properties[index].QueueFlags; khrSurface.GetPhysicalDeviceSurfaceSupport(physicalDevice, index, surface, out var surfaceSupported).ThrowOnError(); if (queueFlags.HasFlag(RequiredFlags) && surfaceSupported) { queueCount = properties[index].QueueCount; return(index); } } queueCount = 0; return(InvalidIndex); }
public void update_shadow_map(CommandPool cmdPool) { update_light_matrices(); CommandBuffer cmd = cmdPool.AllocateAndStart(); shadowPass.Begin(cmd, fbShadowMap); cmd.SetViewport(SHADOWMAP_SIZE, SHADOWMAP_SIZE); cmd.SetScissor(SHADOWMAP_SIZE, SHADOWMAP_SIZE); cmd.BindDescriptorSet(shadowPipeline.Layout, dsShadow); Vk.vkCmdSetDepthBias(cmd.Handle, depthBiasConstant, 0.0f, depthBiasSlope); shadowPipeline.Bind(cmd); if (renderer.model != null) { renderer.model.Bind(cmd); renderer.model.DrawAll(cmd, shadowPipeline.Layout, true); } shadowPass.End(cmd); renderer.presentQueue.EndSubmitAndWait(cmd); updateShadowMap = false; }
public override void Update() { initGpuBuffers(); using (CommandPool cmdPoolCompute = new CommandPool(dev, computeQ.qFamIndex)) { CommandBuffer cmd = cmdPoolCompute.AllocateAndStart(VkCommandBufferUsageFlags.OneTimeSubmit); pong = false; uint stepSize = imgDim / 2; plCompute.Bind(cmd); cmd.PushConstant(plCompute.Layout, VkShaderStageFlags.Compute, imgDim, sizeof(int)); int pass = 0; while (stepSize > 0 && pass < invocationCount) { cmd.PushConstant(plCompute.Layout, VkShaderStageFlags.Compute, stepSize); if (pong) { plCompute.BindDescriptorSet(cmd, dsetPong); } else { plCompute.BindDescriptorSet(cmd, dsetPing); } cmd.Dispatch(imgDim, imgDim); VkMemoryBarrier memBar = VkMemoryBarrier.New(); memBar.srcAccessMask = VkAccessFlags.ShaderWrite; memBar.dstAccessMask = VkAccessFlags.ShaderRead; Vk.vkCmdPipelineBarrier(cmd.Handle, VkPipelineStageFlags.ComputeShader, VkPipelineStageFlags.ComputeShader, VkDependencyFlags.ByRegion, 1, ref memBar, 0, IntPtr.Zero, 0, IntPtr.Zero); pong = !pong; stepSize /= 2; pass++; } plNormalize.Bind(cmd); if (pong) { plNormalize.BindDescriptorSet(cmd, dsetPong); } else { plNormalize.BindDescriptorSet(cmd, dsetPing); } cmd.Dispatch(imgDim, imgDim); pong = !pong; cmd.End(); computeQ.Submit(cmd); computeQ.WaitIdle(); } printResults(); }
private unsafe void CreateDescriptorPool(uint maxSets) { Device device = _renderer.Params.Device; AllocationCallbacks *allocator = (AllocationCallbacks *)_renderer.Params.AllocationCallbacks.ToPointer(); Vk vk = _renderer.Vk; DescriptorPoolSize *descriptorPoolSizes = stackalloc DescriptorPoolSize[] { new DescriptorPoolSize() { DescriptorCount = 2, // vertex and fragment shader Type = DescriptorType.UniformBuffer }, new DescriptorPoolSize() { DescriptorCount = 1, // Image Type = DescriptorType.CombinedImageSampler } }; DescriptorPoolCreateInfo descriptorPoolCreateInfo = new() { SType = StructureType.DescriptorPoolCreateInfo, MaxSets = maxSets, PoolSizeCount = 2, PPoolSizes = descriptorPoolSizes }; _renderer.AssertVulkan(vk.CreateDescriptorPool(device, descriptorPoolCreateInfo, allocator, out _pool)); }
public MemoryAllocator(Vk api, Device device, uint maxMemoryAllocationCount) { _api = api; _device = device; _blockLists = new List <MemoryAllocatorBlockList>(); _blockAlignment = (int)Math.Min(int.MaxValue, MaxDeviceMemoryUsageEstimate / (ulong)maxMemoryAllocationCount); }
public unsafe CommandBufferPool(Vk api, Device device, Queue queue, object queueLock, uint queueFamilyIndex, bool isLight = false) { _api = api; _device = device; _queue = queue; _queueLock = queueLock; _owner = Thread.CurrentThread; var commandPoolCreateInfo = new CommandPoolCreateInfo() { SType = StructureType.CommandPoolCreateInfo, QueueFamilyIndex = queueFamilyIndex, Flags = CommandPoolCreateFlags.CommandPoolCreateTransientBit | CommandPoolCreateFlags.CommandPoolCreateResetCommandBufferBit }; api.CreateCommandPool(device, commandPoolCreateInfo, null, out _pool).ThrowOnError(); // We need at least 2 command buffers to get texture data in some cases. _totalCommandBuffers = isLight ? 2 : MaxCommandBuffers; _totalCommandBuffersMask = _totalCommandBuffers - 1; _commandBuffers = new ReservedCommandBuffer[_totalCommandBuffers]; _queuedIndexes = new int[_totalCommandBuffers]; _queuedIndexesPtr = 0; _queuedCount = 0; for (int i = 0; i < _totalCommandBuffers; i++) { _commandBuffers[i].Initialize(api, device, _pool); WaitAndDecrementRef(i); } }
public void BindIndexBuffer(Vk api, CommandBufferScoped cbs) { if (_buffer != null) { api.CmdBindIndexBuffer(cbs.CommandBuffer, _buffer.Get(cbs, _offset, _size).Value, (ulong)_offset, _type); } }
public unsafe CommandBufferPool(Vk api, Device device, Queue queue, uint queueFamilyIndex, bool isLight = false) { _api = api; _device = device; _queue = queue; _owner = Thread.CurrentThread; var commandPoolCreateInfo = new CommandPoolCreateInfo() { SType = StructureType.CommandPoolCreateInfo, QueueFamilyIndex = queueFamilyIndex, Flags = CommandPoolCreateFlags.CommandPoolCreateTransientBit | CommandPoolCreateFlags.CommandPoolCreateResetCommandBufferBit }; api.CreateCommandPool(device, commandPoolCreateInfo, null, out _pool).ThrowOnError(); _totalCommandBuffers = isLight ? 1 : MaxCommandBuffers; _totalCommandBuffersMask = _totalCommandBuffers - 1; _commandBuffers = new ReservedCommandBuffer[_totalCommandBuffers]; for (int i = 0; i < _totalCommandBuffers; i++) { _commandBuffers[i].Initialize(api, device, _pool); } }
internal static PhysicalDevice FindSuitablePhysicalDevice(Vk api, Instance instance, SurfaceKHR surface, string preferredGpuId) { uint physicalDeviceCount; api.EnumeratePhysicalDevices(instance, &physicalDeviceCount, null).ThrowOnError(); PhysicalDevice[] physicalDevices = new PhysicalDevice[physicalDeviceCount]; fixed(PhysicalDevice *pPhysicalDevices = physicalDevices) { api.EnumeratePhysicalDevices(instance, &physicalDeviceCount, pPhysicalDevices).ThrowOnError(); } // First we try to pick the the user preferred GPU. for (int i = 0; i < physicalDevices.Length; i++) { if (IsPreferredAndSuitableDevice(api, physicalDevices[i], surface, preferredGpuId)) { return(physicalDevices[i]); } } // If we fail to do that, just use the first compatible GPU. for (int i = 0; i < physicalDevices.Length; i++) { if (IsSuitableDevice(api, physicalDevices[i], surface)) { return(physicalDevices[i]); } } throw new VulkanException("Initialization failed, none of the available GPUs meets the minimum requirements."); }
private unsafe Image CreateImage(Rendering.Texture type) { Device device = _renderer.Params.Device; AllocationCallbacks *allocator = (AllocationCallbacks *)_renderer.Params.AllocationCallbacks.ToPointer(); Vk vk = _renderer.Vk; ImageCreateInfo imageCreateInfo = new() { SType = StructureType.ImageCreateInfo, ImageType = ImageType.ImageType2D, Extent = new Extent3D() { Width = Size.X, Height = Size.Y, Depth = 1 }, MipLevels = _mipLevelCount, ArrayLayers = 1, Format = _format, Tiling = ImageTiling.Optimal, InitialLayout = ImageLayout.Undefined, Usage = ImageUsageFlags.ImageUsageTransferDstBit | ImageUsageFlags.ImageUsageTransferSrcBit | ImageUsageFlags.ImageUsageSampledBit, SharingMode = SharingMode.Exclusive, Samples = SampleCountFlags.SampleCount1Bit, QueueFamilyIndexCount = 0, PQueueFamilyIndices = null }; _renderer.AssertVulkan(vk.CreateImage(device, imageCreateInfo, allocator, out Image image)); return(image); }
private unsafe void AllocDescriptorSets(uint n) { if (_count + n > _capacity) { Device device = _renderer.Params.Device; AllocationCallbacks *allocator = (AllocationCallbacks *)_renderer.Params.AllocationCallbacks.ToPointer(); Vk vk = _renderer.Vk; int cdescriptorSets = Math.Max(_count + (int)n, 16) + (_descriptorSets.Length / 2); Array.Resize(ref _descriptorSets, cdescriptorSets); _capacity = cdescriptorSets; vk.DestroyDescriptorPool(device, _pool, allocator); CreateDescriptorPool((uint)_capacity); DescriptorSetAllocateInfo descriptorSetAllocateInfo = new() { SType = StructureType.DescriptorSetAllocateInfo, DescriptorPool = _pool, DescriptorSetCount = 1 }; fixed(DescriptorSetLayout *ptr = &_layout) { descriptorSetAllocateInfo.PSetLayouts = ptr; } for (int i = 0; i < _capacity; i++) { _renderer.AssertVulkan(vk.AllocateDescriptorSets(device, descriptorSetAllocateInfo, out _descriptorSets[i])); } } }
private static bool IsSuitableDevice(Vk api, PhysicalDevice physicalDevice, SurfaceKHR surface) { int extensionMatches = 0; uint propertiesCount; api.EnumerateDeviceExtensionProperties(physicalDevice, (byte *)null, &propertiesCount, null).ThrowOnError(); ExtensionProperties[] extensionProperties = new ExtensionProperties[propertiesCount]; fixed(ExtensionProperties *pExtensionProperties = extensionProperties) { api.EnumerateDeviceExtensionProperties(physicalDevice, (byte *)null, &propertiesCount, pExtensionProperties).ThrowOnError(); for (int i = 0; i < propertiesCount; i++) { string extensionName = Marshal.PtrToStringAnsi((IntPtr)pExtensionProperties[i].ExtensionName); if (RequiredExtensions.Contains(extensionName)) { extensionMatches++; } } } return(extensionMatches == RequiredExtensions.Length && FindSuitableQueueFamily(api, physicalDevice, surface, out _) != InvalidIndex); }
Instance CreateInstance() { // There is no global state in Vulkan and all per-application state is stored in a // `Instance` object. Creating a `Instance` object initializes the Vulkan library // and allows the application to pass information about itself to the implementation. // For this example, we want Vulkan to act in a 'default' fashion, so we don't // pass and ApplicationInfo object and we don't request any layers or extensions String[] enabledLayers = new string[] { "VK_LAYER_LUNARG_standard_validation" }; var enabledExtensions = new[] { VulkanConstant.ExtDebugReportExtensionName, }; var instanceCreateInfo = new InstanceCreateInfo(enabledLayers, enabledExtensions); var instance = Vk.CreateInstance(instanceCreateInfo); debugCallback = DebugUtils.CreateDebugReportCallback(instance, DebugReport); return(instance); }
private void VerifyDeviceExtensionsAvailable(Vk vk, PhysicalDevice physicalDevice, List <string> extensions, ref List <string> layers) { var copy = extensions.ToList(); uint propertyCount = 0; vk.EnumerateDeviceExtensionProperties(physicalDevice, (byte *)null, ref propertyCount, null).ThrowCode(); var properties = (ExtensionProperties *)SilkMarshal.Allocate((int)(propertyCount * sizeof(ExtensionProperties))); vk.EnumerateDeviceExtensionProperties(physicalDevice, (byte *)null, ref propertyCount, properties).ThrowCode(); for (int i = 0; i < propertyCount; i++) { var name = SilkMarshal.PtrToString((nint)properties[i].ExtensionName); copy.Remove(name); } foreach (var ext in copy) { if (ext == KhrSynchronization2.ExtensionName) { layers.Add("VK_LAYER_KHRONOS_synchronization2"); Console.WriteLine("Attempting to enable VK_LAYER_KHRONOS_synchronization2"); } Console.WriteLine($"Missing {ext}"); } }
static void Main(string[] args) { VkInstance inst; using (VkApplicationInfo ai = new VkApplicationInfo()) { using (VkInstanceCreateInfo ci = new VkInstanceCreateInfo { pApplicationInfo = ai }){ CheckResult(vkCreateInstance(ci, IntPtr.Zero, out inst)); } } Vk.LoadInstanceFunctionPointers(inst); CheckResult(vkEnumeratePhysicalDevices(inst, out uint phyCount, IntPtr.Zero)); VkPhysicalDevice[] phys = new VkPhysicalDevice[phyCount]; CheckResult(vkEnumeratePhysicalDevices(inst, out phyCount, phys.Pin())); for (int i = 0; i < phys.Length; i++) { vkGetPhysicalDeviceProperties(phys[i], out VkPhysicalDeviceProperties props); Console.WriteLine($"{props.deviceName}"); Console.WriteLine($"\tdeviceType: {props.deviceType,20}"); Console.WriteLine($"\tapiVersion: {(Version)props.apiVersion,20}"); Console.WriteLine($"\tdriverVersion:{props.driverVersion,20}"); Console.WriteLine($"\tvendorID: {props.vendorID,20}"); } vkDestroyInstance(inst, IntPtr.Zero); }
public unsafe override void Run(Frame frame, CommandBuffer cmd) { Vk vk = renderer.Vk; Pipelines.Pipeline fPipeline = Pipelines.Pipeline.GetPipeline(renderPipeline, renderer); fPipeline.Bind(cmd); DescriptorSet descriptorSet = frame.DescriptorSetManager.GetDescriptorSet(); renderer.Shader.SetUniforms(frame, descriptorSet, uniformOffset, image); vk.CmdBindDescriptorSets(cmd, PipelineBindPoint.Graphics, renderer.Shader.PipelineLayout, 0, 1, descriptorSet, 0, 0); foreach (Path path in paths) { vk.CmdDraw(cmd, path.FillCount, 1, path.FillOffset, 0); } if (renderer.EdgeAntiAlias) { Pipelines.Pipeline aaPipeline = Pipelines.Pipeline.GetPipeline(antiAliasPipeline, renderer); aaPipeline.Bind(cmd); foreach (Path path in paths) { vk.CmdDraw(cmd, path.StrokeCount, 1, path.StrokeOffset, 0); } } }
public void Init(long _userId, Vk _vkApi, UserManager _userManager) { m_vkApi = _vkApi ?? throw new ArgumentNullException(nameof(_vkApi)); m_userManager = _userManager ?? throw new ArgumentNullException(nameof(_userManager)); m_userId = _userId; m_generalMarkup = KeyBoardBuilder.BuildMarkupKeyboard(new string[] { "Добавить группу", "Удалить группу" }); }
static AccountManager() { _vkontakte = ViewModelLocator.Vkontakte; _lastFm = ViewModelLocator.LastFm; Initialize(); }
public unsafe BufferedQuery(VulkanRenderer gd, Device device, PipelineFull pipeline, CounterType type, bool result32Bit) { _api = gd.Api; _device = device; _pipeline = pipeline; _type = type; _result32Bit = result32Bit; _isSupported = QueryTypeSupported(gd, type); if (_isSupported) { QueryPipelineStatisticFlags flags = type == CounterType.PrimitivesGenerated ? QueryPipelineStatisticFlags.QueryPipelineStatisticGeometryShaderPrimitivesBit : 0; var queryPoolCreateInfo = new QueryPoolCreateInfo() { SType = StructureType.QueryPoolCreateInfo, QueryCount = 1, QueryType = GetQueryType(type), PipelineStatistics = flags }; gd.Api.CreateQueryPool(device, queryPoolCreateInfo, null, out _queryPool).ThrowOnError(); } var buffer = gd.BufferManager.Create(gd, sizeof(long), forConditionalRendering: true); _bufferMap = buffer.Map(0, sizeof(long)); _defaultValue = result32Bit ? DefaultValueInt : DefaultValue; Marshal.WriteInt64(_bufferMap, _defaultValue); _buffer = buffer; }
public override void Auth() { SetCredentials(); bool isLoggedIn; try { Vk.Authorize(new ApiAuthParams { ApplicationId = 6634517, Login = _login, Password = _password, Settings = SettingFilters }); isLoggedIn = Vk.IsAuthorized; } catch (VkApiAuthorizationException) { isLoggedIn = false; Console.WriteLine("Authorization failed: Incorrect credentials"); SetCredentials(); } catch (VkApiException ex) { isLoggedIn = false; Console.WriteLine(ex.Message + "\n"); SetCredentials(); } if (isLoggedIn) { Console.Clear(); Console.Write("Вход выполнен успешно!"); } }
private static unsafe bool FindQueueFamilyIndices(PhysicalDevice physicalDevice, SurfaceKHR surface, out uint?graphicsQueueFamily, out uint?presentQueueFamily) { graphicsQueueFamily = presentQueueFamily = null; uint queueFamilyCount = 0; Vk.GetPhysicalDeviceQueueFamilyProperties(physicalDevice, ref queueFamilyCount, null); Span <QueueFamilyProperties> props = stackalloc QueueFamilyProperties[(int)queueFamilyCount]; Vk.GetPhysicalDeviceQueueFamilyProperties(physicalDevice, ref queueFamilyCount, out props[0]); for (int i = 0; i < queueFamilyCount; i++) { QueueFamilyProperties prop = props[i]; if (prop.QueueFlags.HasFlag(QueueFlags.QueueGraphicsBit) && !graphicsQueueFamily.HasValue) { graphicsQueueFamily = (uint)i; } AssertVulkan(KhrSurface.GetPhysicalDeviceSurfaceSupport(physicalDevice, (uint)i, surface, out Bool32 supported)); if (supported && !presentQueueFamily.HasValue) { presentQueueFamily = (uint)i; } if (graphicsQueueFamily.HasValue && presentQueueFamily.HasValue) { return(true); } } return(false); }
public unsafe DescriptorPoolHolder(Vk api, Device device) { Api = api; Device = device; var poolSizes = new DescriptorPoolSize[] { new DescriptorPoolSize(DescriptorType.UniformBuffer, (1 + Constants.MaxUniformBufferBindings) * DescriptorPoolMultiplier), new DescriptorPoolSize(DescriptorType.StorageBuffer, Constants.MaxStorageBufferBindings * DescriptorPoolMultiplier), new DescriptorPoolSize(DescriptorType.CombinedImageSampler, Constants.MaxTextureBindings * DescriptorPoolMultiplier), new DescriptorPoolSize(DescriptorType.StorageImage, Constants.MaxImageBindings * DescriptorPoolMultiplier), new DescriptorPoolSize(DescriptorType.UniformTexelBuffer, Constants.MaxTextureBindings * DescriptorPoolMultiplier), new DescriptorPoolSize(DescriptorType.StorageTexelBuffer, Constants.MaxImageBindings * DescriptorPoolMultiplier) }; uint maxSets = (uint)poolSizes.Length * DescriptorPoolMultiplier; _capacity = maxSets; fixed(DescriptorPoolSize *pPoolsSize = poolSizes) { var descriptorPoolCreateInfo = new DescriptorPoolCreateInfo() { SType = StructureType.DescriptorPoolCreateInfo, MaxSets = maxSets, PoolSizeCount = (uint)poolSizes.Length, PPoolSizes = pPoolsSize }; Api.CreateDescriptorPool(device, descriptorPoolCreateInfo, null, out _pool).ThrowOnError(); } }
public static PhysicalDevice FindSuitablePhysicalDevice(Vk api, Instance instance, SurfaceKHR surface) { uint physicalDeviceCount; api.EnumeratePhysicalDevices(instance, &physicalDeviceCount, null).ThrowOnError(); PhysicalDevice[] physicalDevices = new PhysicalDevice[physicalDeviceCount]; fixed(PhysicalDevice *pPhysicalDevices = physicalDevices) { api.EnumeratePhysicalDevices(instance, &physicalDeviceCount, pPhysicalDevices).ThrowOnError(); } if (physicalDevices.Length > 1) { return(physicalDevices[0]); } for (int i = 0; i < physicalDevices.Length; i++) { if (IsSuitableDevice(api, physicalDevices[i], surface)) { return(physicalDevices[i]); } } throw new VulkanException("Initialization failed, none of the available GPUs meets the minimum requirements."); }
public unsafe DepthImage(uint width, uint height, PhysicalDevice physicalDevice, Device device) { _width = width; _height = height; _vk = VkUtil.Vk; _physicalDevice = physicalDevice; _device = device; Format = FindFormat(FormatFeatureFlags.FormatFeatureDepthStencilAttachmentBit, Format.D32SfloatS8Uint, Format.D24UnormS8Uint); ImageCreateInfo imageCreateInfo = VkInit.ImageCreateInfo(ImageType.ImageType2D, Format, _width, _height); VkUtil.AssertVulkan(_vk.CreateImage(_device, imageCreateInfo, null, out _image)); _vk.GetImageMemoryRequirements(_device, _image, out MemoryRequirements memReqs); _vk.GetPhysicalDeviceMemoryProperties(_physicalDevice, out PhysicalDeviceMemoryProperties memoryProperties); uint index = VkUtil.FindMemoryTypeIndex(memReqs.MemoryTypeBits, MemoryPropertyFlags.MemoryPropertyDeviceLocalBit, memoryProperties); MemoryAllocateInfo memoryAllocateInfo = VkInit.MemoryAllocateInfo(memReqs.Size, index); VkUtil.AssertVulkan(_vk.AllocateMemory(_device, memoryAllocateInfo, null, out _memory)); VkUtil.AssertVulkan(_vk.BindImageMemory(_device, _image, _memory, 0)); ImageViewCreateInfo imageViewCreateInfo = VkInit.ImageViewCreateInfo(Format, _image, ImageAspectFlags.ImageAspectDepthBit); VkUtil.AssertVulkan(_vk.CreateImageView(_device, imageViewCreateInfo, null, out _imageView)); }
private unsafe ImageView CreateImageView() { Device device = _renderer.Params.Device; AllocationCallbacks *allocator = (AllocationCallbacks *)_renderer.Params.AllocationCallbacks.ToPointer(); Vk vk = _renderer.Vk; ImageViewCreateInfo imageViewCreateInfo = new() { SType = StructureType.ImageViewCreateInfo, Image = _image, ViewType = ImageViewType.ImageViewType2D, Format = _format, SubresourceRange = new ImageSubresourceRange() { AspectMask = ImageAspectFlags.ImageAspectColorBit, BaseArrayLayer = 0, LayerCount = 1, BaseMipLevel = 0, LevelCount = _mipLevelCount }, Components = new ComponentMapping() { R = ComponentSwizzle.Identity, G = ComponentSwizzle.Identity, B = ComponentSwizzle.Identity, A = ComponentSwizzle.Identity } }; _renderer.AssertVulkan(vk.CreateImageView(device, imageViewCreateInfo, allocator, out ImageView imageView)); return(imageView); }
private void AddKickButton(Vk.user user) { GUILayout.Label(user.texture, GUILayout.Width(50), GUILayout.Height(40)); if (Network.isServer && user.nwid != Network.player && GUILayout.Button(lc.kick.ToString())) { rpcwrite(user.nick + lc.kicked); Network.CloseConnection(user.nwid, true); RPCUserDisconnected(user.nwid.GetHashCode()); } }
private void PrintPlayer(Vk.user user) { const string table = "{0,15}{1,10}{2,10}{3,10}{4,10}"; GUILayout.Label(String.Format(table, "", lc.kills, lc.ping, lc.fps, lc.deaths)); GUILayout.BeginHorizontal(); GUILayout.Label(String.Format(table, user.nick, user.frags, user.ping, user.fps, user.deaths)); AddKickButton(user); GUILayout.EndHorizontal(); }