示例#1
0
        public DebugDrawPipeline(RenderPass renderPass, uint maxVertices = 100,
                                 VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1, PipelineCache pipelineCache = null) :
            base(renderPass, pipelineCache, "Debug draw pipeline")
        {
            vboLength = maxVertices * 6 * sizeof(float);

            using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.LineList, samples, false)) {
                cfg.rasterizationState.lineWidth = 1.0f;
                cfg.RenderPass = RenderPass;
                cfg.Layout     = new PipelineLayout(Dev, new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> () * 2));
                cfg.AddVertexBinding(0, 6 * sizeof(float));
                cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat);
                cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState(true);

                cfg.AddShaders(
                    new ShaderInfo(Dev, VkShaderStageFlags.Vertex, "#vke.debug.vert.spv"),
                    new ShaderInfo(Dev, VkShaderStageFlags.Fragment, "#vke.debug.frag.spv")
                    );

                layout = cfg.Layout;

                init(cfg);
            }

            Vertices = new HostBuffer(Dev, VkBufferUsageFlags.VertexBuffer, vboLength);
            Vertices.Map();
        }
示例#2
0
        /// <summary>
        /// load bitmap from pointer
        /// </summary>
        void load(Queue staggingQ, CommandPool staggingCmdPool, IntPtr bitmap, bool generateMipmaps = true)
        {
            long size = info.extent.width * info.extent.height * 4 * info.extent.depth;

            if (MemoryFlags.HasFlag(VkMemoryPropertyFlags.HostVisible))
            {
                Map();
                unsafe {
                    System.Buffer.MemoryCopy(bitmap.ToPointer(), MappedData.ToPointer(), size, size);
                }
                Unmap();

                if (generateMipmaps)
                {
                    BuildMipmaps(staggingQ, staggingCmdPool);
                }
            }
            else
            {
                using (HostBuffer stagging = new HostBuffer(Dev, VkBufferUsageFlags.TransferSrc, (UInt64)size, bitmap)) {
                    PrimaryCommandBuffer cmd = staggingCmdPool.AllocateAndStart(VkCommandBufferUsageFlags.OneTimeSubmit);

                    stagging.CopyTo(cmd, this);
                    if (generateMipmaps)
                    {
                        BuildMipmaps(cmd);
                    }

                    cmd.End();
                    staggingQ.Submit(cmd);
                    staggingQ.WaitIdle();
                    cmd.Free();
                }
            }
        }