コード例 #1
0
 public CommandBuffer(VkCommandBuffer cmd, VkCommandBufferLevel level, CommandPool src, bool transient)
 {
     Cmd        = cmd;
     Level      = level;
     SourcePool = src;
     Transient  = transient;
 }
コード例 #2
0
 internal CommandBuffer(Device device, CommandPool pool, VkCommandBuffer commandBuffer, VkCommandBufferLevel level)
 {
     Device             = device;
     Pool               = pool;
     this.commandBuffer = commandBuffer;
     Level              = level;
 }
コード例 #3
0
        public CommandBuffer[] Allocate(VkCommandBufferLevel level, int count)
        {
            var info = new VkCommandBufferAllocateInfo();

            info.sType              = VkStructureType.CommandBufferAllocateInfo;
            info.level              = level;
            info.commandPool        = commandPool;
            info.commandBufferCount = (uint)count;

            using (var commandBuffersMarshalled = new NativeArray <VkCommandBuffer>(count)) {
                CommandBuffer[] commandBuffers = new CommandBuffer[count];
                var             result         = Device.Commands.allocateCommandBuffers(Device.Native, ref info, commandBuffersMarshalled.Address);
                if (result != VkResult.Success)
                {
                    throw new CommandPoolException(string.Format("Error allocating command buffers: {0}", result));
                }

                for (int i = 0; i < count; i++)
                {
                    commandBuffers[i] = new CommandBuffer(Device, this, commandBuffersMarshalled[i], level);
                }

                return(commandBuffers);
            }
        }
コード例 #4
0
        private void GrowBuffers(VkCommandBufferLevel level, uint numBuffers)
        {
            NativeList <VkCommandBuffer> buffers =
                level == VkCommandBufferLevel.Primary ? primaryCmdBuffers : secondaryCmdBuffers;

            uint oldBuffers = buffers.Count;

            if (numBuffers <= oldBuffers)
            {
                return;
            }

            // Create one command buffer for each swap chain image and reuse for rendering
            buffers.Resize(numBuffers);
            buffers.Count = numBuffers;

            if (buffers.Count > MAX_BUFFERS)
            {
                throw new InvalidOperationException("Hit max buffer amount. Please check if buffers are not being reused correctly.");
            }

            VkCommandBufferAllocateInfo cmdBufAllocateInfo =
                Initializers.CommandBufferAllocateInfo(vkCmdPool, level, buffers.Count - oldBuffers);

            Util.CheckResult(vkAllocateCommandBuffers(device.device, ref cmdBufAllocateInfo, (VkCommandBuffer *)buffers.GetAddress(oldBuffers)));

            var queue =
                level == VkCommandBufferLevel.Primary ? freePrimaryBuffers : freeSecondaryBuffers;

            for (uint i = oldBuffers; i < buffers.Count; i++)
            {
                queue.Enqueue(buffers[i]);
            }
        }
コード例 #5
0
 public CommandBuffer Rent(VkCommandBufferLevel level = VkCommandBufferLevel.Primary)
 {
     if (level == VkCommandBufferLevel.Primary)
     {
         if (freePrimaryBuffers.TryDequeue(out var result))
         {
             return(new CommandBuffer(result, this, level));
         }
         else
         {
             GrowBuffers(level, primaryCmdBuffers.Count + 10);
             result = freePrimaryBuffers.Dequeue();
             return(new CommandBuffer(result, this, level));
         }
     }
     else
     {
         if (freeSecondaryBuffers.TryDequeue(out var result))
         {
             return(new CommandBuffer(result, this, level));
         }
         else
         {
             GrowBuffers(level, secondaryCmdBuffers.Count + 10);
             result = freeSecondaryBuffers.Dequeue();
             return(new CommandBuffer(result, this, level));
         }
     }
 }
コード例 #6
0
        public CommandBuffer AllocateAndStart(VkCommandBufferUsageFlags usage = 0, VkCommandBufferLevel level = VkCommandBufferLevel.Primary)
        {
            CommandBuffer cmd = AllocateCommandBuffer(level);

            cmd.Start(usage);
            return(cmd);
        }
コード例 #7
0
        public unsafe CommandBuffer AllocateCommandBuffer(VkCommandBufferLevel commandBufferLevel)
        {
            VkCommandBuffer cmdBuffer;

            Device.AllocateCommandBuffers(cmdPool, commandBufferLevel, 1, &cmdBuffer);
            return(new CommandBuffer(cmdBuffer));
        }
コード例 #8
0
        public unsafe CommandBuffer(
            CommandPool commandPool,
            VkCommandBufferLevel level = VkCommandBufferLevel.Primary,
            bool isFenceSignaled       = false
            )
        {
            _commandPool = commandPool;
            _level       = level;
            var allocateInfo = new VkCommandBufferAllocateInfo
            {
                sType              = VkStructureType.CommandBufferAllocateInfo,
                commandPool        = commandPool.Handle,
                level              = level,
                commandBufferCount = 1
            };

            VkCommandBuffer commandBuffer;

            if (VulkanNative.vkAllocateCommandBuffers(
                    commandPool.Device.Handle,
                    &allocateInfo,
                    &commandBuffer
                    ) != VkResult.Success)
            {
                throw new Exception("failed to allocate command buffers");
            }
            _handle = commandBuffer;
            _fence  = new Fence(commandPool.Device, isFenceSignaled);
        }
コード例 #9
0
        public VkCommandBuffer[] AllocateCommandBuffers(VkCommandBufferLevel level, UInt32 commandBufferCount)
        {
            VkCommandBufferAllocateInfo commandBufferAllocateInfo = new VkCommandBufferAllocateInfo();

            commandBufferAllocateInfo.commandBufferCount = commandBufferCount;
            commandBufferAllocateInfo.level = level;
            return(AllocateCommandBuffers(ref commandBufferAllocateInfo));
        }
コード例 #10
0
 public CommandBuffer(VkCommandBuffer internalBuffer, CommandPool pool, VkCommandBufferLevel level)
 {
     vkCmd        = internalBuffer;
     this.pool    = pool;
     this.level   = level;
     begun        = false;
     inRenderPass = false;
     ended        = false;
     renderPassUseSecondaryBuffers = false;
 }
コード例 #11
0
ファイル: Device.cs プロジェクト: Gaiaxis/SharpGame
        public static void AllocateCommandBuffers(VkCommandPool cmdPool, VkCommandBufferLevel level, uint count, VkCommandBuffer *cmdBuffers)
        {
            VkCommandBufferAllocateInfo cmdBufAllocateInfo = new VkCommandBufferAllocateInfo
            {
                sType = VkStructureType.CommandBufferAllocateInfo
            };

            cmdBufAllocateInfo.commandPool        = cmdPool;
            cmdBufAllocateInfo.level              = level;
            cmdBufAllocateInfo.commandBufferCount = count;

            VulkanUtil.CheckResult(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, cmdBuffers));
        }
コード例 #12
0
        public CommandBuffer AllocateCommandBuffer(VkCommandBufferLevel level = VkCommandBufferLevel.Primary)
        {
            VkCommandBuffer             buff;
            VkCommandBufferAllocateInfo infos = VkCommandBufferAllocateInfo.New();

            infos.commandPool        = handle;
            infos.level              = level;
            infos.commandBufferCount = 1;

            Utils.CheckResult(vkAllocateCommandBuffers(Dev.VkDev, ref infos, out buff));

            return(new CommandBuffer(Dev.VkDev, this, buff));
        }
コード例 #13
0
ファイル: Initializers.cs プロジェクト: gomson/vk
        public static VkCommandBufferAllocateInfo CommandBufferAllocateInfo(
            VkCommandPool commandPool,
            VkCommandBufferLevel level,
            uint bufferCount)
        {
            VkCommandBufferAllocateInfo commandBufferAllocateInfo = new VkCommandBufferAllocateInfo();

            commandBufferAllocateInfo.sType              = VkStructureType.CommandBufferAllocateInfo;
            commandBufferAllocateInfo.commandPool        = commandPool;
            commandBufferAllocateInfo.level              = level;
            commandBufferAllocateInfo.commandBufferCount = bufferCount;
            return(commandBufferAllocateInfo);
        }
コード例 #14
0
        public unsafe void Allocate(VkCommandBufferLevel commandBufferLevel, uint count)
        {
            if (cmdBuffers.Count > 0)
            {
                Free();
            }

            cmdBuffers.Resize(count);
            Device.AllocateCommandBuffers(cmdPool, commandBufferLevel, count, (VkCommandBuffer *)cmdBuffers.Data);

            CommandBuffers = new CommandBuffer[count];
            for (int i = 0; i < count; i++)
            {
                CommandBuffers[i] = new CommandBuffer(cmdBuffers[i]);
            }
        }
コード例 #15
0
        protected VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, bool begin)
        {
            VkCommandBuffer cmdBuffer;

            VkCommandBufferAllocateInfo cmdBufAllocateInfo = Initializers.CommandBufferAllocateInfo(cmdPool, level, 1);

            Util.CheckResult(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, out cmdBuffer));

            // If requested, also start the new command buffer
            if (begin)
            {
                VkCommandBufferBeginInfo cmdBufInfo = Initializers.commandBufferBeginInfo();
                Util.CheckResult(vkBeginCommandBuffer(cmdBuffer, &cmdBufInfo));
            }

            return(cmdBuffer);
        }
コード例 #16
0
        public CommandBuffer[] AllocateCommandBuffer(uint count, VkCommandBufferLevel level = VkCommandBufferLevel.Primary)
        {
            VkCommandBufferAllocateInfo infos = VkCommandBufferAllocateInfo.New();

            infos.commandPool        = handle;
            infos.level              = level;
            infos.commandBufferCount = count;
            VkCommandBuffer[] buffs = new VkCommandBuffer[count];
            Utils.CheckResult(vkAllocateCommandBuffers(Dev.VkDev, ref infos, buffs.Pin()));
            buffs.Unpin();
            CommandBuffer[] cmds = new CommandBuffer[count];
            for (int i = 0; i < count; i++)
            {
                cmds[i] = new CommandBuffer(Dev.VkDev, this, buffs[i]);
            }

            return(cmds);
        }
コード例 #17
0
 public CommandBuffer(CommandPool pool, VkCommandBufferLevel level)
 {
     CommandPool = pool;
     unsafe
     {
         VkCommandBuffer             handle = VkCommandBuffer.Null;
         VkCommandBufferAllocateInfo info   = new VkCommandBufferAllocateInfo()
         {
             SType              = VkStructureType.CommandBufferAllocateInfo,
             PNext              = IntPtr.Zero,
             CommandPool        = pool.Handle,
             CommandBufferCount = 1,
             Level              = level
         };
         VkException.Check(VkDevice.vkAllocateCommandBuffers(Device.Handle, &info, &handle));
         Debug.Assert(handle != VkCommandBuffer.Null);
         Handle = handle;
         _state = State.Allocated;
     }
 }
コード例 #18
0
        public CommandBuffer Allocate(VkCommandBufferLevel level)
        {
            var info = new VkCommandBufferAllocateInfo();

            info.sType              = VkStructureType.CommandBufferAllocateInfo;
            info.level              = level;
            info.commandPool        = commandPool;
            info.commandBufferCount = 1;

            using (var commandBufferMarshalled = new Native <VkCommandBuffer>()) {
                var result = Device.Commands.allocateCommandBuffers(Device.Native, ref info, commandBufferMarshalled.Address);
                if (result != VkResult.Success)
                {
                    throw new CommandPoolException(string.Format("Error allocating command buffer: {0}", result));
                }

                CommandBuffer commandBuffer = new CommandBuffer(Device, this, commandBufferMarshalled.Value, level);

                return(commandBuffer);
            }
        }
コード例 #19
0
ファイル: VulkanDevice.cs プロジェクト: gomson/vk
        public VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, bool begin = false)
        {
            VkCommandBufferAllocateInfo cmdBufAllocateInfo = VkCommandBufferAllocateInfo.New();

            cmdBufAllocateInfo.commandPool        = CommandPool;
            cmdBufAllocateInfo.level              = level;
            cmdBufAllocateInfo.commandBufferCount = 1;

            VkCommandBuffer cmdBuffer;

            Util.CheckResult(vkAllocateCommandBuffers(_logicalDevice, ref cmdBufAllocateInfo, out cmdBuffer));

            // If requested, also start recording for the new command buffer
            if (begin)
            {
                VkCommandBufferBeginInfo cmdBufInfo = VkCommandBufferBeginInfo.New();
                Util.CheckResult(vkBeginCommandBuffer(cmdBuffer, ref cmdBufInfo));
            }

            return(cmdBuffer);
        }
コード例 #20
0
        protected VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, bool begin)
        {
            VkCommandBuffer cmdBuffer;

            VkCommandBufferAllocateInfo cmdBufAllocateInfo = new VkCommandBufferAllocateInfo();

            cmdBufAllocateInfo.sType              = CommandBufferAllocateInfo;
            cmdBufAllocateInfo.commandPool        = cmdPool;
            cmdBufAllocateInfo.level              = level;
            cmdBufAllocateInfo.commandBufferCount = 1;

            vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, &cmdBuffer);

            // If requested, also start the new command buffer
            if (begin)
            {
                VkCommandBufferBeginInfo cmdBufInfo = new VkCommandBufferBeginInfo();
                cmdBufInfo.sType = CommandBufferBeginInfo;
                vkBeginCommandBuffer(cmdBuffer, &cmdBufInfo);
            }

            return(cmdBuffer);
        }
コード例 #21
0
        public VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, bool begin = false)
        {
            VkCommandBufferAllocateInfo cmdBufAllocateInfo = new VkCommandBufferAllocateInfo();

            cmdBufAllocateInfo.sType              = CommandBufferAllocateInfo;
            cmdBufAllocateInfo.commandPool        = CommandPool;
            cmdBufAllocateInfo.level              = level;
            cmdBufAllocateInfo.commandBufferCount = 1;

            VkCommandBuffer cmdBuffer;

            vkAllocateCommandBuffers(_logicalDevice, &cmdBufAllocateInfo, &cmdBuffer);

            // If requested, also start recording for the new command buffer
            if (begin)
            {
                VkCommandBufferBeginInfo cmdBufInfo = new VkCommandBufferBeginInfo();
                cmdBufInfo.sType = CommandBufferBeginInfo;
                vkBeginCommandBuffer(cmdBuffer, &cmdBufInfo);
            }

            return(cmdBuffer);
        }
コード例 #22
0
ファイル: CommandPool.cs プロジェクト: Equinox-/CSharpVulkan
 public CommandBuffer BuildCommandBuffer(VkCommandBufferLevel level)
 {
     return(new CommandBuffer(this, level));
 }
コード例 #23
0
 public VkCommandBuffer AllocateCommandBuffer(VkCommandBufferLevel level)
 {
     return(AllocateCommandBuffers(level, 1)[0]);
 }