public void Dispose() { dev.WaitIdle(); frameBuffers?.Dispose(); gbColorRough.Dispose(); gbEmitMetal.Dispose(); gbN_AO.Dispose(); gbPos.Dispose(); hdrImg.Dispose(); gBuffPipeline.Dispose(); composePipeline.Dispose(); toneMappingPipeline.Dispose(); debugPipeline.Dispose(); depthPrepassPipeline.Dispose(); descLayoutMain.Dispose(); descLayoutGBuff.Dispose(); uboMatrices.Dispose(); uboLights.Dispose(); model.Dispose(); envCube.Dispose(); shadowMapRenderer.Dispose(); descriptorPool.Dispose(); }
public void Dispose() { dev.WaitIdle(); for (int i = 0; i < swapChain.ImageCount; ++i) { frameBuffers[i]?.Dispose(); } gbColorRough.Dispose(); gbEmitMetal.Dispose(); gbN_AO.Dispose(); gbPos.Dispose(); hdrImg.Dispose(); gBuffPipeline.Dispose(); composePipeline.Dispose(); toneMappingPipeline.Dispose(); debugPipeline.Dispose(); descLayoutMain.Dispose(); descLayoutTextures?.Dispose(); descLayoutGBuff.Dispose(); uboMatrices.Dispose(); uboLights.Dispose(); model.Dispose(); envCube.Dispose(); #if WITH_SHADOWS shadowMapRenderer.Dispose(); #endif descriptorPool.Dispose(); }
protected override void Dispose(bool disposing) { if (disposing) { if (!isDisposed) { dev.WaitIdle(); for (int i = 0; i < swapChain.ImageCount; ++i) { frameBuffers[i]?.Dispose(); } model.Dispose(); pipeline.Dispose(); descLayoutMatrix.Dispose(); descLayoutTextures.Dispose(); descriptorPool.Dispose(); uboMats.Dispose(); vkvgSurf?.Dispose(); vkvgDev.Dispose(); timestampQPool.Dispose(); statPool.Dispose(); } } base.Dispose(disposing); }
public void Build() { DescriptorSetLayout?.Dispose(); PipelineLayout?.Dispose(); //UsingSamplers?.DisposeRange(); DescriptorPool?.Dispose(); RenderPass?.Dispose(); Pipeline?.Dispose(); DescriptorSetLayout = VKHelper.CreateDescriptorSetLayout(Graphics, DescriptorItems); PipelineLayout = VKHelper.CreatePipelineLayout(Graphics, DescriptorSetLayout); DescriptorPool = VKHelper.CreateDescriptorPool(Graphics, DescriptorItems); DescriptorSet = VKHelper.CreateDescriptorSet(DescriptorPool, DescriptorSetLayout, DescriptorItems, out UsingSamplers); RenderPass = VKHelper.CreateRenderPass(Graphics, ClearDepthOnBeginPass); Pipeline = VKHelper.CreateGraphicsPipeline(Graphics, PipelineLayout, RenderPass, Shaders, DepthTest, DepthWrite, Instancing, InstanceInfoType, BlendMode, PrimitiveType, PrimitiveRenderMode, PrimitiveCullMode, LineWidth, ViewportPos, ViewportSize); }
protected override void Dispose(bool disposing) { if (disposing) { if (!isDisposed) { dev.WaitIdle(); for (int i = 0; i < swapChain.ImageCount; ++i) { frameBuffers[i]?.Dispose(); } grPipeline.Dispose(); plCompute.Dispose(); plNormalize.Dispose(); dslCompute.Dispose(); dslImage.Dispose(); dsPool.Dispose(); inBuff.Dispose(); outBuff.Dispose(); stagingDataBuff.Dispose(); imgResult.Dispose(); dbgReport?.Dispose(); } } base.Dispose(disposing); }
public void Dispose() { dev.WaitIdle(); frameBuffer?.Dispose(); gbColorRough.Dispose(); gbEmitMetal.Dispose(); gbN_AO.Dispose(); gbPos.Dispose(); hdrImgResolved.Dispose(); gBuffPipeline.Dispose(); composePipeline.Dispose(); //toneMappingPipeline.Dispose (); debugPipeline?.Dispose(); descLayoutMain.Dispose(); descLayoutTextures?.Dispose(); descLayoutGBuff.Dispose(); uboMatrices.Dispose(); uboLights.Dispose(); model.Dispose(); envCube.Dispose(); #if WITH_SHADOWS shadowMapRenderer.Dispose(); #endif descriptorPool.Dispose(); dev.DestroySemaphore(DrawComplete); }
protected override void Dispose(bool disposing) { model.Dispose(); envCube.Dispose(); descLayoutMain.Dispose(); descLayoutTextures.Dispose(); descriptorPool.Dispose(); uboMats.Dispose(); base.Dispose(disposing); }
public void Dispose() { dev.WaitIdle(); plCompute.Dispose(); dsLayout.Dispose(); dsPool.Dispose(); inBuff.Dispose(); outBuff.Dispose(); dev.Dispose(); instance.Dispose(); }
public void Dispose() { if (_disposed) { return; } Output.Dispose(); Inputs.ForEach(input => input.Dispose()); _descriptorPool.Dispose(); _pipeline.Dispose(); _pipelineLayout.Dispose(); _descriptorSetLayout.Dispose(); _commandPool.Dispose(); _fence.Dispose(); _disposed = true; }
public void Dispose() { dev.WaitIdle(); plCompute.Dispose(); dsLayoutCompute.Dispose(); dsPool.Dispose(); inBuff.Dispose(); outBuff.Dispose(); dev.Dispose(); #if DEBUG dbgReport.Dispose(); #endif instance.Dispose(); }
protected override void Dispose(bool disposing) { if (disposing) { if (!isDisposed) { dev.WaitIdle(); for (int i = 0; i < swapChain.ImageCount; ++i) { frameBuffers[i]?.Dispose(); } gbColorRough.Dispose(); gbEmitMetal.Dispose(); gbN.Dispose(); gbPos.Dispose(); gBuffPipeline.Dispose(); composePipeline.Dispose(); descLayoutMain.Dispose(); descLayoutModelTextures.Dispose(); descLayoutGBuff.Dispose(); uboMats.Dispose(); model.Dispose(); envCube.Dispose(); descriptorPool.Dispose(); #if DEBUG foreach (Framebuffer fb in debugFB) { fb.Dispose(); } debugDraw.Dispose(); timestampQPool?.Dispose(); statPool?.Dispose(); #endif } } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { if (!isDisposed) { dev.WaitIdle(); pipeline.Dispose(); dsLayout.Dispose(); frameBuffers?.Dispose(); descriptorPool.Dispose(); fontTexture?.Dispose(); vbo.Dispose(); ibo.Dispose(); uboMats.Dispose(); } } base.Dispose(disposing); }
public void Cleanup() { /* * Clean up all Vulkan Resources. */ bufferMemory.Dispose(); buffer.Dispose(); computeShaderModule.Dispose(); descriptorPool.Dispose(); descriptorSetLayout.Dispose(); pipelineLayout.Dispose(); foreach (Pipeline pipeline in pipelines) { pipeline.Dispose(); } commandPool.Dispose(); device.Dispose(); instance.Dispose(); }
protected override void Dispose(bool disposing) { if (disposing) { if (!isDisposed) { dev.WaitIdle(); for (int i = 0; i < swapChain.ImageCount; ++i) { frameBuffers[i]?.Dispose(); } grPipeline.Dispose(); trianglesPipeline.Dispose(); plInit.Dispose(); plCompute.Dispose(); plNormalize.Dispose(); dslCompute.Dispose(); dslImage.Dispose(); dsPool.Dispose(); inBuff.Dispose(); outBuff.Dispose(); staggingVBO.Dispose(); vbo.Dispose(); ibo.Dispose(); imgResult.Dispose(); #if DEBUG dbgReport.Dispose(); #endif } } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { if (!isDisposed) { dev.WaitIdle(); pipeline.Dispose(); dsLayout.Dispose(); for (int i = 0; i < swapChain.ImageCount; i++) { frameBuffers[i].Dispose(); } descriptorPool.Dispose(); vbo.Dispose(); ibo.Dispose(); uboMats.Dispose(); } } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { if (!isDisposed) { dev.WaitIdle(); for (int i = 0; i < swapChain.ImageCount; ++i) { frameBuffers[i]?.Dispose(); } uiPipeline.Dispose(); descLayout.Dispose(); descriptorPool.Dispose(); vkvgImage?.Dispose(); vkvgSurf?.Dispose(); vkvgDev.Dispose(); } } base.Dispose(disposing); }
public Image generateCubeMap(Queue staggingQ, CommandPool cmdPool, CBTarget target) { const float deltaPhi = (2.0f * (float)Math.PI) / 180.0f; const float deltaTheta = (0.5f * (float)Math.PI) / 64.0f; VkFormat format = VkFormat.R32g32b32a32Sfloat; uint dim = 64; if (target == CBTarget.PREFILTEREDENV) { format = VkFormat.R16g16b16a16Sfloat; dim = 512; } uint numMips = (uint)Math.Floor(Math.Log(dim, 2)) + 1; Image imgFbOffscreen = new Image(Dev, format, VkImageUsageFlags.TransferSrc | VkImageUsageFlags.ColorAttachment, VkMemoryPropertyFlags.DeviceLocal, dim, dim); imgFbOffscreen.SetName("offscreenfb"); imgFbOffscreen.CreateView(); Image cmap = new Image(Dev, format, VkImageUsageFlags.TransferDst | VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, dim, dim, VkImageType.Image2D, VkSampleCountFlags.SampleCount1, VkImageTiling.Optimal, numMips, 6, 1, VkImageCreateFlags.CubeCompatible); if (target == CBTarget.PREFILTEREDENV) { cmap.SetName("prefilterenvmap"); } else { cmap.SetName("irradianceCube"); } cmap.CreateView(VkImageViewType.Cube, VkImageAspectFlags.Color, 6, 0); cmap.CreateSampler(VkSamplerAddressMode.ClampToEdge); DescriptorPool dsPool = new DescriptorPool(Dev, 2, new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler)); DescriptorSetLayout dsLayout = new DescriptorSetLayout(Dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)); GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1, false); cfg.Layout = new PipelineLayout(Dev, dsLayout); cfg.Layout.AddPushConstants( new VkPushConstantRange(VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, (uint)Marshal.SizeOf <Matrix4x4> () + 8)); cfg.RenderPass = new RenderPass(Dev); cfg.RenderPass.AddAttachment(format, VkImageLayout.ColorAttachmentOptimal); cfg.RenderPass.ClearValues.Add(new VkClearValue { color = new VkClearColorValue(0, 0, 0) }); cfg.RenderPass.AddSubpass(new SubPass(VkImageLayout.ColorAttachmentOptimal)); cfg.AddVertexBinding(0, 3 * sizeof(float)); cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat); cfg.AddShaders(new ShaderInfo(Dev, VkShaderStageFlags.Vertex, "#EnvironmentPipeline.filtercube.vert.spv")); if (target == CBTarget.PREFILTEREDENV) { cfg.AddShaders(new ShaderInfo(Dev, VkShaderStageFlags.Fragment, "#EnvironmentPipeline.prefilterenvmap.frag.spv")); } else { cfg.AddShaders(new ShaderInfo(Dev, VkShaderStageFlags.Fragment, "#EnvironmentPipeline.irradiancecube.frag.spv")); } Matrix4x4[] matrices = { // POSITIVE_X Matrix4x4.CreateRotationX(Utils.DegreesToRadians(180)) * Matrix4x4.CreateRotationY(Utils.DegreesToRadians(90)), // NEGATIVE_X Matrix4x4.CreateRotationX(Utils.DegreesToRadians(180)) * Matrix4x4.CreateRotationY(Utils.DegreesToRadians(-90)), // POSITIVE_Y Matrix4x4.CreateRotationX(Utils.DegreesToRadians(-90)), // NEGATIVE_Y Matrix4x4.CreateRotationX(Utils.DegreesToRadians(90)), // POSITIVE_Z Matrix4x4.CreateRotationX(Utils.DegreesToRadians(180)), // NEGATIVE_Z Matrix4x4.CreateRotationZ(Utils.DegreesToRadians(180)) }; VkImageSubresourceRange subRes = new VkImageSubresourceRange(VkImageAspectFlags.Color, 0, numMips, 0, 6); using (GraphicPipeline pl = new GraphicPipeline(cfg)) { cfg.Dispose(); DescriptorSet dset = dsPool.Allocate(dsLayout); DescriptorSetWrites dsUpdate = new DescriptorSetWrites(dsLayout); dsUpdate.Write(Dev, dset, cubemap.Descriptor); Dev.WaitIdle(); using (FrameBuffer fb = new FrameBuffer(pl.RenderPass, dim, dim, imgFbOffscreen)) { PrimaryCommandBuffer cmd = cmdPool.AllocateCommandBuffer(); cmd.Start(VkCommandBufferUsageFlags.OneTimeSubmit); cmap.SetLayout(cmd, VkImageLayout.Undefined, VkImageLayout.TransferDstOptimal, subRes); float roughness = 0; cmd.SetScissor(dim, dim); cmd.SetViewport((float)(dim), (float)dim); for (int m = 0; m < numMips; m++) { roughness = (float)m / ((float)numMips - 1f); for (int f = 0; f < 6; f++) { pl.RenderPass.Begin(cmd, fb); pl.Bind(cmd); float viewPortSize = (float)Math.Pow(0.5, m) * dim; cmd.SetViewport(viewPortSize, viewPortSize); cmd.PushConstant(pl.Layout, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, matrices[f] * Matrix4x4.CreatePerspectiveFieldOfView(Utils.DegreesToRadians(90), 1f, 0.1f, 512f)); if (target == CBTarget.IRRADIANCE) { cmd.PushConstant(pl.Layout, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, deltaPhi, (uint)Marshal.SizeOf <Matrix4x4> ()); cmd.PushConstant(pl.Layout, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, deltaTheta, (uint)Marshal.SizeOf <Matrix4x4> () + 4); } else { cmd.PushConstant(pl.Layout, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, roughness, (uint)Marshal.SizeOf <Matrix4x4> ()); cmd.PushConstant(pl.Layout, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, 64u, (uint)Marshal.SizeOf <Matrix4x4> () + 4); } cmd.BindDescriptorSet(pl.Layout, dset); cmd.BindVertexBuffer(vboSkybox); cmd.Draw(36); pl.RenderPass.End(cmd); imgFbOffscreen.SetLayout(cmd, VkImageAspectFlags.Color, VkImageLayout.ColorAttachmentOptimal, VkImageLayout.TransferSrcOptimal); VkImageCopy region = new VkImageCopy(); region.srcSubresource = new VkImageSubresourceLayers(VkImageAspectFlags.Color, 1); region.dstSubresource = new VkImageSubresourceLayers(VkImageAspectFlags.Color, 1, (uint)m, (uint)f); region.extent = new VkExtent3D { width = (uint)viewPortSize, height = (uint)viewPortSize, depth = 1 }; Vk.vkCmdCopyImage(cmd.Handle, imgFbOffscreen.Handle, VkImageLayout.TransferSrcOptimal, cmap.Handle, VkImageLayout.TransferDstOptimal, 1, region.Pin()); region.Unpin(); imgFbOffscreen.SetLayout(cmd, VkImageAspectFlags.Color, VkImageLayout.TransferSrcOptimal, VkImageLayout.ColorAttachmentOptimal); } } cmap.SetLayout(cmd, VkImageLayout.TransferDstOptimal, VkImageLayout.ShaderReadOnlyOptimal, subRes); cmd.End(); staggingQ.Submit(cmd); staggingQ.WaitIdle(); cmd.Free(); } } cmap.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal; dsLayout.Dispose(); imgFbOffscreen.Dispose(); dsPool.Dispose(); return(cmap); }
public void Dispose() { layout.Dispose(); pool.Dispose(); }