public void update_shadow_map(CommandPool cmdPool, vke.Buffer instanceBuf, params Model.InstancedCmd[] instances)
        {
            update_light_matrices();

            PrimaryCommandBuffer 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.Draw(cmd, shadowPipeline.Layout, instanceBuf, true, instances);
            }

            shadowPass.End(cmd);

            renderer.presentQueue.EndSubmitAndWait(cmd);
            updateShadowMap = false;
        }
        public void recordDraw(PrimaryCommandBuffer cmd, int imageIndex, vke.Buffer instanceBuf = null, params Model.InstancedCmd[] instances)
        {
            FrameBuffer fb = frameBuffers[imageIndex];

            renderPass.Begin(cmd, fb);

            cmd.SetViewport(fb.Width, fb.Height);
            cmd.SetScissor(fb.Width, fb.Height);

            cmd.BindDescriptorSet(gBuffPipeline.Layout, dsMain);

            envCube.RecordDraw(cmd);
            renderPass.BeginSubPass(cmd);

            if (model != null)
            {
                model.Bind(cmd);

                depthPrepassPipeline.Bind(cmd);
                if (instanceBuf != null)
                {
                    model.Draw(cmd, gBuffPipeline.Layout, instanceBuf, false, instances);
                }

                renderPass.BeginSubPass(cmd);
                gBuffPipeline.Bind(cmd);

                if (instanceBuf != null)
                {
                    model.Draw(cmd, gBuffPipeline.Layout, instanceBuf, false, instances);
                }
            }
            renderPass.BeginSubPass(cmd);

            cmd.BindDescriptorSet(composePipeline.Layout, dsGBuff, 1);

            if (currentDebugView == DebugView.none)
            {
                composePipeline.Bind(cmd);
            }
            else
            {
                debugPipeline.Bind(cmd);
                uint debugValue = (uint)currentDebugView - 1;
                if (currentDebugView == DebugView.shadowMap)
                {
                    debugValue += (uint)((lightNumDebug << 8));
                }
                else
                {
                    debugValue += (uint)((debugFace << 8) + (debugMip << 16));
                }
                cmd.PushConstant(debugPipeline.Layout, VkShaderStageFlags.Fragment, debugValue, (uint)Marshal.SizeOf <Matrix4x4>());
            }

            cmd.Draw(3, 1, 0, 0);

            renderPass.BeginSubPass(cmd);
            toneMappingPipeline.Bind(cmd);
            cmd.Draw(3, 1, 0, 0);

            renderPass.End(cmd);
        }