Beispiel #1
0
        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));
        }
Beispiel #2
0
        private unsafe ShaderModule CreateShader(byte[] code)
        {
            Device device = _renderer.Params.Device;
            AllocationCallbacks *allocator = (AllocationCallbacks *)_renderer.Params.AllocationCallbacks.ToPointer();
            Vk vk = _renderer.Vk;

            ShaderModuleCreateInfo shaderModuleCreateInfo = new()
            {
                SType = StructureType.ShaderModuleCreateInfo,

                CodeSize = (nuint)(code.Length * sizeof(byte))
            };

            fixed(byte *ptr = &code[0])
            {
                shaderModuleCreateInfo.PCode = (uint *)ptr;
            }

            Result result = vk.CreateShaderModule(device, shaderModuleCreateInfo, allocator, out ShaderModule module);

            if (result != Result.Success)
            {
                Status = false;
                _renderer.AssertVulkan(result);
            }
            return(module);
        }
Beispiel #3
0
        private unsafe DeviceMemory BindImageMemory()
        {
            Device device = _renderer.Params.Device;
            AllocationCallbacks *allocator = (AllocationCallbacks *)_renderer.Params.AllocationCallbacks.ToPointer();
            Vk vk = _renderer.Vk;

            vk.GetImageMemoryRequirements(device, _image, out MemoryRequirements memReqs);

            MemoryAllocateInfo memoryAllocateInfo = new()
            {
                SType = StructureType.MemoryAllocateInfo,

                AllocationSize  = memReqs.Size,
                MemoryTypeIndex = _renderer.FindMemoryTypeIndex(memReqs.MemoryTypeBits, MemoryPropertyFlags.MemoryPropertyDeviceLocalBit)
            };

            _renderer.AssertVulkan(vk.AllocateMemory(device, memoryAllocateInfo, allocator, out DeviceMemory memory));
            _renderer.AssertVulkan(vk.BindImageMemory(device, _image, memory, 0));
            return(memory);
        }