void init(VkSampleCountFlags samples = VkSampleCountFlags.SampleCount4) { descriptorPool = new DescriptorPool(dev, 2, new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler) ); descLayout = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, samples); cfg.Layout = new PipelineLayout(dev, descLayout); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), samples); cfg.ResetShadersAndVerticesInfos(); cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/FullScreenQuad.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/simpletexture.frag.spv"); cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState(true); uiPipeline = new GraphicPipeline(cfg); dsVkvg = descriptorPool.Allocate(descLayout); }
Program() : base(false) { vbo = new HostBuffer <Vertex> (dev, VkBufferUsageFlags.VertexBuffer, vertices); ibo = new HostBuffer <ushort> (dev, VkBufferUsageFlags.IndexBuffer, indices); uboMats = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, matrices); descriptorPool = new DescriptorPool(dev, 1, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer)); dsLayout = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer)); GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1); cfg.Layout = new PipelineLayout(dev, dsLayout); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), cfg.Samples); cfg.AddVertexBinding <Vertex> (0); cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat); cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/triangle.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/triangle.frag.spv"); pipeline = new GraphicPipeline(cfg); descriptorSet = descriptorPool.Allocate(dsLayout); DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descriptorSet, dsLayout); uboUpdate.Write(dev, uboMats.Descriptor); uboMats.Map(); }
public PBRPipeline(Queue staggingQ, RenderPass renderPass, string cubeMapPath, PipelineCache pipelineCache = null) : base(renderPass, pipelineCache, "pbr pipeline") { descriptorPool = new DescriptorPool(Dev, 2, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer, 2), new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler, 8) ); descLayoutMain = new DescriptorSetLayout(Dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer)); descLayoutTextures = new DescriptorSetLayout(Dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, renderPass.Samples)) { cfg.Layout = new PipelineLayout(Dev, descLayoutMain, descLayoutTextures); cfg.Layout.AddPushConstants( new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> ()), new VkPushConstantRange(VkShaderStageFlags.Fragment, sizeof(int), 64) ); cfg.RenderPass = renderPass; cfg.AddVertexBinding <PbrModel.Vertex> (0); cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat, VkFormat.R32g32Sfloat); cfg.AddShader(Dev, VkShaderStageFlags.Vertex, "#shaders.pbr.vert.spv"); cfg.AddShader(Dev, VkShaderStageFlags.Fragment, "#shaders.pbr_khr.frag.spv"); layout = cfg.Layout; init(cfg); } dsMain = descriptorPool.Allocate(descLayoutMain); envCube = new EnvironmentCube(cubeMapPath, layout, staggingQ, RenderPass); matrices.prefilteredCubeMipLevels = envCube.prefilterCube.CreateInfo.mipLevels; uboMats = new HostBuffer(Dev, VkBufferUsageFlags.UniformBuffer, matrices, true); DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descLayoutMain.Bindings.GetRange(0, 4).ToArray()); uboUpdate.Write(Dev, dsMain, uboMats.Descriptor, envCube.irradianceCube.Descriptor, envCube.prefilterCube.Descriptor, envCube.lutBrdf.Descriptor); }
void initUIPipeline() { GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, samples, false); cfg.RenderPass = pbrPipeline.RenderPass; cfg.Layout = pbrPipeline.Layout; cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/FullScreenQuad.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/simpletexture.frag.spv"); cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState(true); uiPipeline = new GraphicPipeline(cfg); }
protected override void initVulkan() { base.initVulkan(); cmds = cmdPool.AllocateCommandBuffer(swapChain.ImageCount); loadTexture(imgPathes[currentImgIndex]); vbo = new GPUBuffer <float> (presentQueue, cmdPool, VkBufferUsageFlags.VertexBuffer, vertices); ibo = new GPUBuffer <ushort> (presentQueue, cmdPool, VkBufferUsageFlags.IndexBuffer, indices); descriptorPool = new DescriptorPool(dev, 1, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer), new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler) ); dsLayout = new DescriptorSetLayout(dev, 0, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex, VkDescriptorType.UniformBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)); using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount4)) { cfg.Layout = new PipelineLayout(dev, dsLayout); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), cfg.Samples); cfg.AddVertexBinding(0, 5 * sizeof(float)); cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat); cfg.AddShader(dev, VkShaderStageFlags.Vertex, "#shaders.main.vert.spv"); cfg.AddShader(dev, VkShaderStageFlags.Fragment, "#shaders.main.frag.spv"); pipeline = new GraphicPipeline(cfg); } uboMats = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, matrices); uboMats.Map(); //permanent map descriptorSet = descriptorPool.Allocate(dsLayout); updateTextureSet(); DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descriptorSet, dsLayout.Bindings[0]); uboUpdate.Write(dev, uboMats.Descriptor); }
Vector4 outlineColor = new Vector4(1.0f, 0.0f, 0.0f, 0.6f); //alpha => 0:disabled 1:enabled protected override void initVulkan() { base.initVulkan(); cmds = cmdPool.AllocateCommandBuffer(swapChain.ImageCount); font = new BMFont(vke.samples.Utils.GetDataFile("font.fnt")); vbo = new GPUBuffer <float> (dev, VkBufferUsageFlags.VertexBuffer | VkBufferUsageFlags.TransferDst, 1024); ibo = new GPUBuffer <ushort> (dev, VkBufferUsageFlags.IndexBuffer | VkBufferUsageFlags.TransferDst, 2048); descriptorPool = new DescriptorPool(dev, 1, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer), new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler) ); dsLayout = new DescriptorSetLayout(dev, 0, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex, VkDescriptorType.UniformBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)); using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount4, false)) { cfg.Layout = new PipelineLayout(dev, dsLayout); cfg.Layout.AddPushConstants(new VkPushConstantRange(VkShaderStageFlags.Fragment, (uint)Marshal.SizeOf <Vector4> () * 2)); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, cfg.Samples); cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState( true, VkBlendFactor.One, VkBlendFactor.OneMinusSrcAlpha, VkBlendOp.Add, VkBlendFactor.One, VkBlendFactor.Zero); cfg.AddVertexBinding(0, 5 * sizeof(float)); cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat); cfg.AddShader(dev, VkShaderStageFlags.Vertex, "#shaders.main.vert.spv"); cfg.AddShader(dev, VkShaderStageFlags.Fragment, "#shaders.main.frag.spv"); pipeline = new GraphicPipeline(cfg); } uboMats = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, matrices); uboMats.Map(); //permanent map descriptorSet = descriptorPool.Allocate(dsLayout); fontTexture = font.GetPageTexture(0, presentQueue, cmdPool); fontTexture.CreateView(); fontTexture.CreateSampler(); fontTexture.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal; DescriptorSetWrites dsUpdate = new DescriptorSetWrites(descriptorSet, dsLayout); dsUpdate.Write(dev, uboMats.Descriptor, fontTexture.Descriptor); generateText("Vulkan", out HostBuffer <Vertex> staggingVbo, out HostBuffer <ushort> staggingIbo); PrimaryCommandBuffer cmd = cmdPool.AllocateAndStart(VkCommandBufferUsageFlags.OneTimeSubmit); staggingVbo.CopyTo(cmd, vbo); staggingIbo.CopyTo(cmd, ibo); presentQueue.EndSubmitAndWait(cmd); staggingVbo.Dispose(); staggingIbo.Dispose(); UpdateFrequency = 10; }
void init(float nearPlane, float farPlane) { init_renderpass(); descLayoutMain = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer),//matrices and params new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer), //lights new VkDescriptorSetLayoutBinding(5, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer)); //materials #if WITH_SHADOWS descLayoutMain.Bindings.Add(new VkDescriptorSetLayoutBinding(6, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)); #endif if (TEXTURE_ARRAY) { descLayoutMain.Bindings.Add(new VkDescriptorSetLayoutBinding(7, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)); //texture array //descLayoutMain.Bindings.Add (new VkDescriptorSetLayoutBinding (8, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler));//down sampled hdr } else { descLayoutTextures = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); } descLayoutGBuff = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment), //color + roughness new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment), //emit + metal new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment), //normals + AO new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment)); //Pos + depth GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, NUM_SAMPLES); cfg.rasterizationState.cullMode = VkCullModeFlags.Back; if (NUM_SAMPLES != VkSampleCountFlags.SampleCount1) { cfg.multisampleState.sampleShadingEnable = true; cfg.multisampleState.minSampleShading = 0.5f; } cfg.Cache = pipelineCache; if (TEXTURE_ARRAY) { cfg.Layout = new PipelineLayout(dev, descLayoutMain, descLayoutGBuff); } else { cfg.Layout = new PipelineLayout(dev, descLayoutMain, descLayoutGBuff, descLayoutTextures); } cfg.Layout.AddPushConstants( new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> ()), new VkPushConstantRange(VkShaderStageFlags.Fragment, sizeof(int), 64) ); cfg.RenderPass = renderPass; cfg.SubpassIndex = SP_MODELS; cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false)); cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false)); cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false)); //cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false)); cfg.AddVertex <PbrModelTexArray.Vertex> (); using (SpecializationInfo constants = new SpecializationInfo( new SpecializationConstant <float> (0, nearPlane), new SpecializationConstant <float> (1, farPlane), new SpecializationConstant <float> (2, MAX_MATERIAL_COUNT))) { cfg.AddShaders(new ShaderInfo(dev, VkShaderStageFlags.Vertex, "#shaders.GBuffPbr.vert.spv")); if (TEXTURE_ARRAY) { cfg.AddShaders(new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#shaders.GBuffPbrTexArray.frag.spv", constants)); } else { cfg.AddShaders(new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#shaders.GBuffPbr.frag.spv", constants)); } gBuffPipeline = new GraphicPipeline(cfg); } cfg.rasterizationState.cullMode = VkCullModeFlags.Front; //COMPOSE PIPELINE cfg.blendAttachments.Clear(); cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false)); cfg.ResetShadersAndVerticesInfos(); cfg.SubpassIndex = SP_COMPOSE; cfg.Layout = gBuffPipeline.Layout; cfg.depthStencilState.depthTestEnable = false; cfg.depthStencilState.depthWriteEnable = false; using (SpecializationInfo constants = new SpecializationInfo( new SpecializationConstant <uint> (0, (uint)lights.Length))) { cfg.AddShaders(new ShaderInfo(dev, VkShaderStageFlags.Vertex, "#vke.FullScreenQuad.vert.spv")); #if WITH_SHADOWS cfg.AddShaders(new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#shaders.compose_with_shadows.frag.spv", constants)); #else cfg.AddShader(VkShaderStageFlags.Fragment, "#shaders.compose.frag.spv", constants); #endif composePipeline = new GraphicPipeline(cfg); } cfg.Shaders[1].Dispose(); //DEBUG DRAW use subpass of compose cfg.Shaders[1] = new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#shaders.show_gbuff.frag.spv"); cfg.SubpassIndex = SP_COMPOSE; debugPipeline = new GraphicPipeline(cfg); cfg.DisposeShaders(); ////TONE MAPPING //cfg.shaders[1] = new ShaderInfo (VkShaderStageFlags.Fragment, "#shaders.tone_mapping.frag.spv"); //cfg.SubpassIndex = SP_TONE_MAPPING; //toneMappingPipeline = new GraphicPipeline (cfg); dsMain = descriptorPool.Allocate(descLayoutMain); dsGBuff = descriptorPool.Allocate(descLayoutGBuff); envCube = new EnvironmentCube(cubemapPath, gBuffPipeline.Layout, gQueue, renderPass); matrices.prefilteredCubeMipLevels = envCube.prefilterCube.CreateInfo.mipLevels; DescriptorSetWrites dsMainWrite = new DescriptorSetWrites(dsMain, descLayoutMain.Bindings.GetRange(0, 5).ToArray()); dsMainWrite.Write(dev, uboMatrices.Descriptor, envCube.irradianceCube.Descriptor, envCube.prefilterCube.Descriptor, envCube.lutBrdf.Descriptor, uboLights.Descriptor); #if WITH_SHADOWS dsMainWrite = new DescriptorSetWrites(dsMain, descLayoutMain.Bindings[6]); dsMainWrite.Write(dev, shadowMapRenderer.shadowMap.Descriptor); #endif }
void init(float nearPlane, float farPlane, string cubemapPath) { init_renderpass(); descLayoutMain = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer), //matrices and params new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), //irradiance new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), //prefil new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), //lut brdf new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer), //lights new VkDescriptorSetLayoutBinding(5, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer), //materials new VkDescriptorSetLayoutBinding(6, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), //shadow map new VkDescriptorSetLayoutBinding(7, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), //texture array new VkDescriptorSetLayoutBinding(8, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)); //uiImage descLayoutGBuff = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment), //color + roughness new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment), //emit + metal new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment), //normals + AO new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment), //Pos + depth new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment)); //hdr descLayoutMain.SetName("main"); descLayoutGBuff.SetName("GBuff"); using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, NUM_SAMPLES)) { cfg.rasterizationState.cullMode = VkCullModeFlags.Back; if (NUM_SAMPLES != VkSampleCountFlags.SampleCount1) { cfg.multisampleState.sampleShadingEnable = true; cfg.multisampleState.minSampleShading = 0.5f; } cfg.Cache = pipelineCache; cfg.Layout = new PipelineLayout(dev, new VkPushConstantRange[] { new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> ()), new VkPushConstantRange(VkShaderStageFlags.Fragment, sizeof(int), 64) }, descLayoutMain, descLayoutGBuff); cfg.RenderPass = renderPass; //cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false)); cfg.AddVertexBinding <PbrModelTexArray.Vertex> (0); cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat, VkFormat.R32g32Sfloat); cfg.AddVertexBinding <VkChess.InstanceData> (1, VkVertexInputRate.Instance); cfg.AddVertexAttributes(1, VkFormat.R32g32b32a32Sfloat, VkFormat.R32g32b32a32Sfloat, VkFormat.R32g32b32a32Sfloat, VkFormat.R32g32b32a32Sfloat, VkFormat.R32g32b32a32Sfloat); using (SpecializationInfo constants = new SpecializationInfo( new SpecializationConstant <float> (0, nearPlane), new SpecializationConstant <float> (1, farPlane), new SpecializationConstant <int> (2, MAX_MATERIAL_COUNT))) { cfg.AddShader(dev, VkShaderStageFlags.Vertex, "#vkChess.net.GBuffPbrInstanced.vert.spv"); cfg.SubpassIndex = SP_DEPTH_PREPASS; depthPrepassPipeline = new GraphicPipeline(cfg, "Depth prepass"); cfg.depthStencilState.depthCompareOp = VkCompareOp.Equal; cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false)); cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false)); cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false)); cfg.SubpassIndex = SP_MODELS; cfg.AddShader(dev, VkShaderStageFlags.Fragment, "#vkChess.net.GBuffPbrTexArray.frag.spv", constants); gBuffPipeline = new GraphicPipeline(cfg, "GBuff"); } cfg.rasterizationState.cullMode = VkCullModeFlags.Front; //COMPOSE PIPELINE cfg.blendAttachments.Clear(); cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false)); cfg.ResetShadersAndVerticesInfos(); cfg.SubpassIndex = SP_COMPOSE; cfg.Layout = gBuffPipeline.Layout; cfg.depthStencilState.depthTestEnable = false; cfg.depthStencilState.depthWriteEnable = false; using (SpecializationInfo constants = new SpecializationInfo( new SpecializationConstant <uint> (0, (uint)lights.Length), new SpecializationConstant <float> (1, 0.25f))) { cfg.AddShader(dev, VkShaderStageFlags.Vertex, "#vke.FullScreenQuad.vert.spv"); cfg.AddShader(dev, VkShaderStageFlags.Fragment, "#vkChess.net.compose_with_shadows.frag.spv", constants); composePipeline = new GraphicPipeline(cfg, "compose"); } //DEBUG DRAW use subpass of compose cfg.ReplaceShader(1, new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#vkChess.net.show_gbuff.frag.spv")); cfg.SubpassIndex = SP_COMPOSE; debugPipeline = new GraphicPipeline(cfg, "debug"); //TONE MAPPING cfg.ReplaceShader(1, new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#vkChess.net.tone_mapping.frag.spv")); cfg.SubpassIndex = SP_TONE_MAPPING; toneMappingPipeline = new GraphicPipeline(cfg, "tonne mapping"); } dsMain = descriptorPool.Allocate(descLayoutMain); dsGBuff = descriptorPool.Allocate(descLayoutGBuff); envCube = new vke.Environment.EnvironmentCube(cubemapPath, gBuffPipeline.Layout, presentQueue, renderPass); matrices.prefilteredCubeMipLevels = envCube.prefilterCube.CreateInfo.mipLevels; DescriptorSetWrites dsMainWrite = new DescriptorSetWrites(dsMain, descLayoutMain.Bindings.GetRange(0, 5).ToArray()); dsMainWrite.Write(dev, uboMatrices.Descriptor, envCube.irradianceCube.Descriptor, envCube.prefilterCube.Descriptor, envCube.lutBrdf.Descriptor, uboLights.Descriptor); dsMainWrite = new DescriptorSetWrites(dsMain, descLayoutMain.Bindings[6]); dsMainWrite.Write(dev, shadowMapRenderer.shadowMap.Descriptor); }
void init() { //Shadow map renderpass shadowPass = new RenderPass(dev, VkSampleCountFlags.SampleCount1); shadowPass.AddAttachment(SHADOWMAP_FORMAT, VkImageLayout.DepthStencilReadOnlyOptimal, SHADOWMAP_NUM_SAMPLES); shadowPass.ClearValues.Add(new VkClearValue { depthStencil = new VkClearDepthStencilValue(1.0f, 0) }); SubPass subpass0 = new SubPass(); subpass0.SetDepthReference(0); shadowPass.AddSubpass(subpass0); shadowPass.AddDependency(Vk.SubpassExternal, 0, VkPipelineStageFlags.FragmentShader, VkPipelineStageFlags.EarlyFragmentTests, VkAccessFlags.ShaderRead, VkAccessFlags.DepthStencilAttachmentWrite); shadowPass.AddDependency(0, Vk.SubpassExternal, VkPipelineStageFlags.LateFragmentTests, VkPipelineStageFlags.FragmentShader, VkAccessFlags.DepthStencilAttachmentWrite, VkAccessFlags.ShaderRead); descLayoutShadow = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Geometry, VkDescriptorType.UniformBuffer), //matrices new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Geometry, VkDescriptorType.UniformBuffer)); //lights GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList); cfg.rasterizationState.cullMode = VkCullModeFlags.Back; cfg.rasterizationState.depthBiasEnable = true; cfg.dynamicStates.Add(VkDynamicState.DepthBias); cfg.RenderPass = shadowPass; cfg.Layout = new PipelineLayout(dev, descLayoutShadow); cfg.Layout.AddPushConstants( new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> ()) ); cfg.AddVertexBinding <PbrModel.Vertex> (0); cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat); cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/shadow.vert.spv"); cfg.AddShader(VkShaderStageFlags.Geometry, "shaders/shadow.geom.spv"); shadowPipeline = new GraphicPipeline(cfg); //shadow map image shadowMap = new Image(dev, SHADOWMAP_FORMAT, VkImageUsageFlags.DepthStencilAttachment | VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, SHADOWMAP_SIZE, SHADOWMAP_SIZE, VkImageType.Image2D, SHADOWMAP_NUM_SAMPLES, VkImageTiling.Optimal, 1, (uint)renderer.lights.Length); shadowMap.CreateView(VkImageViewType.ImageView2DArray, VkImageAspectFlags.Depth, shadowMap.CreateInfo.arrayLayers); shadowMap.CreateSampler(VkSamplerAddressMode.ClampToBorder); shadowMap.Descriptor.imageLayout = VkImageLayout.DepthStencilReadOnlyOptimal; fbShadowMap = new Framebuffer(shadowPass, SHADOWMAP_SIZE, SHADOWMAP_SIZE, (uint)renderer.lights.Length); fbShadowMap.attachments.Add(shadowMap); fbShadowMap.Activate(); dsShadow = descriptorPool.Allocate(descLayoutShadow); DescriptorSetWrites dsWrite = new DescriptorSetWrites(dsShadow, descLayoutShadow); dsWrite.Write(dev, renderer.uboMatrices.Descriptor, renderer.uboLights.Descriptor); }
void init() { renderPass = new RenderPass(dev); renderPass.AddAttachment(swapChain.ColorFormat, VkImageLayout.ColorAttachmentOptimal, VkSampleCountFlags.SampleCount1); renderPass.AddAttachment(dev.GetSuitableDepthFormat(), VkImageLayout.DepthStencilAttachmentOptimal, samples); renderPass.AddAttachment(VkFormat.R8g8b8a8Unorm, VkImageLayout.ColorAttachmentOptimal); renderPass.AddAttachment(VkFormat.R8g8b8a8Unorm, VkImageLayout.ColorAttachmentOptimal); renderPass.AddAttachment(VkFormat.R16g16b16a16Sfloat, VkImageLayout.ColorAttachmentOptimal); renderPass.AddAttachment(VkFormat.R16g16b16a16Sfloat, VkImageLayout.ColorAttachmentOptimal); renderPass.ClearValues.Add(new VkClearValue { color = new VkClearColorValue(0.0f, 0.0f, 0.0f) }); renderPass.ClearValues.Add(new VkClearValue { depthStencil = new VkClearDepthStencilValue(1.0f, 0) }); renderPass.ClearValues.Add(new VkClearValue { color = new VkClearColorValue(0.0f, 0.0f, 0.0f) }); renderPass.ClearValues.Add(new VkClearValue { color = new VkClearColorValue(0.0f, 0.0f, 0.0f) }); renderPass.ClearValues.Add(new VkClearValue { color = new VkClearColorValue(0.0f, 0.0f, 0.0f) }); renderPass.ClearValues.Add(new VkClearValue { color = new VkClearColorValue(0.0f, 0.0f, 0.0f) }); SubPass[] subpass = { new SubPass(), new SubPass() }; subpass[0].AddColorReference(new VkAttachmentReference(2, VkImageLayout.ColorAttachmentOptimal), new VkAttachmentReference(3, VkImageLayout.ColorAttachmentOptimal), new VkAttachmentReference(4, VkImageLayout.ColorAttachmentOptimal), new VkAttachmentReference(5, VkImageLayout.ColorAttachmentOptimal)); subpass[0].SetDepthReference(1, VkImageLayout.DepthStencilAttachmentOptimal); subpass[1].AddColorReference(0, VkImageLayout.ColorAttachmentOptimal); subpass[1].AddInputReference(new VkAttachmentReference(2, VkImageLayout.ShaderReadOnlyOptimal), new VkAttachmentReference(3, VkImageLayout.ShaderReadOnlyOptimal), new VkAttachmentReference(4, VkImageLayout.ShaderReadOnlyOptimal), new VkAttachmentReference(5, VkImageLayout.ShaderReadOnlyOptimal)); renderPass.AddSubpass(subpass); renderPass.AddDependency(Vk.SubpassExternal, 0, VkPipelineStageFlags.BottomOfPipe, VkPipelineStageFlags.ColorAttachmentOutput, VkAccessFlags.MemoryRead, VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite); renderPass.AddDependency(0, 1, VkPipelineStageFlags.ColorAttachmentOutput, VkPipelineStageFlags.FragmentShader, VkAccessFlags.ColorAttachmentWrite, VkAccessFlags.ShaderRead); renderPass.AddDependency(1, Vk.SubpassExternal, VkPipelineStageFlags.ColorAttachmentOutput, VkPipelineStageFlags.BottomOfPipe, VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite, VkAccessFlags.MemoryRead); descriptorPool = new DescriptorPool(dev, 3, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer, 2), new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler, 3), new VkDescriptorPoolSize(VkDescriptorType.InputAttachment, 4) ); descLayoutMain = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)); descLayoutModelTextures = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); descLayoutGBuff = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment), new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment), new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment)); dsMain = descriptorPool.Allocate(descLayoutMain); dsGBuff = descriptorPool.Allocate(descLayoutGBuff); GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, samples); cfg.Layout = new PipelineLayout(dev, descLayoutMain, descLayoutModelTextures, descLayoutGBuff); cfg.Layout.AddPushConstants( new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> ()), new VkPushConstantRange(VkShaderStageFlags.Fragment, sizeof(int), 64) ); cfg.RenderPass = renderPass; cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false)); cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false)); cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false)); cfg.AddVertexBinding <Model.Vertex> (0); cfg.SetVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat); cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/pbrtest.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/GBuffPbr.frag.spv"); gBuffPipeline = new GraphicPipeline(cfg); cfg.blendAttachments.Clear(); cfg.blendAttachments.Add(new VkPipelineColorBlendAttachmentState(false)); cfg.ResetShadersAndVerticesInfos(); cfg.SubpassIndex = 1; cfg.Layout = gBuffPipeline.Layout; cfg.depthStencilState.depthTestEnable = false; cfg.depthStencilState.depthWriteEnable = false; cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/FullScreenQuad.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/pbrtest.frag.spv"); composePipeline = new GraphicPipeline(cfg); envCube = new EnvironmentCube(presentQueue, renderPass); uboMats = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, (ulong)Marshal.SizeOf <Matrices> () * 2); uboMats.Map(); //permanent map DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descLayoutMain); uboUpdate.Write(dev, dsMain, uboMats.Descriptor, envCube.lutBrdf.Descriptor, envCube.irradianceCube.Descriptor, envCube.prefilterCube.Descriptor); uboMats.Descriptor.offset = (ulong)Marshal.SizeOf <Matrices> (); envCube.WriteDesc(uboMats.Descriptor); #if DEBUG debugDraw = new DebugDrawPipeline(dev, descLayoutMain, swapChain.ColorFormat); debugDraw.AddLine(Vector3.Zero, new Vector3(matrices.lightPos.X, matrices.lightPos.Y, matrices.lightPos.Z) * 3, 1, 1, 1); debugDraw.AddLine(Vector3.Zero, Vector3.UnitX, 1, 0, 0); debugDraw.AddLine(Vector3.Zero, Vector3.UnitY, 0, 1, 0); debugDraw.AddLine(Vector3.Zero, Vector3.UnitZ, 0, 0, 1); #endif model = new Model(presentQueue, "../data/models/DamagedHelmet/glTF/DamagedHelmet.gltf"); //model = new Model (presentQueue, "../data/models/chess.gltf"); //model = new Model (presentQueue, "../data/models/Sponza/glTF/Sponza.gltf"); //model = new Model (dev, presentQueue, "../data/models/icosphere.gltf"); //model = new Model (dev, presentQueue, cmdPool, "../data/models/cube.gltf"); model.WriteMaterialsDescriptorSets(descLayoutModelTextures, VK.AttachmentType.Color, VK.AttachmentType.Normal, VK.AttachmentType.AmbientOcclusion, VK.AttachmentType.PhysicalProps, VK.AttachmentType.Emissive); }
void init(VkSampleCountFlags samples = VkSampleCountFlags.SampleCount4) { descriptorPool = new DescriptorPool(dev, 2, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer), new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler) ); descLayoutMatrix = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); descLayoutTextures = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); dsMats = descriptorPool.Allocate(descLayoutMatrix); GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, samples); cfg.Layout = new PipelineLayout(dev, descLayoutMatrix, descLayoutTextures); cfg.Layout.AddPushConstants( new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> ()), new VkPushConstantRange(VkShaderStageFlags.Fragment, (uint)Marshal.SizeOf <Model.PbrMaterial> (), 64) ); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), samples); cfg.AddVertexBinding <Model.Vertex> (0); cfg.SetVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat); cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/pbrtest.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/pbrtest.frag.spv"); pipeline = new GraphicPipeline(cfg); cfg.ResetShadersAndVerticesInfos(); cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/FullScreenQuad.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/simpletexture.frag.spv"); cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState(true); uiPipeline = new GraphicPipeline(cfg); uboMats = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, (ulong)Marshal.SizeOf <Matrices>()); uboMats.Map(); //permanent map DescriptorSetWrites uboUpdate = new DescriptorSetWrites(dsMats, descLayoutMatrix.Bindings[0]); uboUpdate.Write(dev, uboMats.Descriptor); cfg.Layout.SetName("Main Pipeline layout"); uboMats.SetName("uboMats"); descriptorPool.SetName("main pool"); descLayoutTextures.SetName("descLayoutTextures"); statPool = new PipelineStatisticsQueryPool(dev, VkQueryPipelineStatisticFlags.InputAssemblyVertices | VkQueryPipelineStatisticFlags.InputAssemblyPrimitives | VkQueryPipelineStatisticFlags.ClippingInvocations | VkQueryPipelineStatisticFlags.ClippingPrimitives | VkQueryPipelineStatisticFlags.FragmentShaderInvocations); timestampQPool = new TimestampQueryPool(dev); }
public Program() : base() { if (Instance.DEBUG_UTILS) { dbgReport = new DebugReport(instance, VkDebugReportFlagsEXT.ErrorEXT | VkDebugReportFlagsEXT.DebugEXT | VkDebugReportFlagsEXT.WarningEXT | VkDebugReportFlagsEXT.PerformanceWarningEXT ); } imgResult = new Image(dev, VkFormat.R32g32b32a32Sfloat, VkImageUsageFlags.TransferDst | VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, imgDim, imgDim); imgResult.CreateView(); imgResult.CreateSampler(VkFilter.Nearest, VkFilter.Nearest, VkSamplerMipmapMode.Nearest, VkSamplerAddressMode.ClampToBorder); imgResult.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal; datas = new float[data_size]; addSeed(imgDim / 2 - 1, imgDim / 2 - 1); stagingDataBuff = new HostBuffer <float> (dev, VkBufferUsageFlags.TransferSrc, datas); stagingDataBuff.Map(); inBuff = new GPUBuffer <float> (dev, VkBufferUsageFlags.StorageBuffer | VkBufferUsageFlags.TransferSrc | VkBufferUsageFlags.TransferDst, (int)data_size); outBuff = new GPUBuffer <float> (dev, VkBufferUsageFlags.StorageBuffer | VkBufferUsageFlags.TransferSrc, (int)data_size); dsPool = new DescriptorPool(dev, 3, new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler), new VkDescriptorPoolSize(VkDescriptorType.StorageBuffer, 4)); dslImage = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); dslCompute = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer) ); GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1); cfg.Layout = new PipelineLayout(dev, dslImage); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), VkSampleCountFlags.SampleCount1); cfg.RenderPass.ClearValues[0] = new VkClearValue { color = new VkClearColorValue(0.0f, 0.1f, 0.0f) }; cfg.ResetShadersAndVerticesInfos(); cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/FullScreenQuad.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/simpletexture.frag.spv"); cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState(true); grPipeline = new GraphicPipeline(cfg); plCompute = new ComputePipeline( new PipelineLayout(dev, new VkPushConstantRange(VkShaderStageFlags.Compute, 2 * sizeof(int)), dslCompute), "shaders/computeTest.comp.spv"); plNormalize = new ComputePipeline( plCompute.Layout, "shaders/normalize.comp.spv"); dsImage = dsPool.Allocate(dslImage); dsetPing = dsPool.Allocate(dslCompute); dsetPong = dsPool.Allocate(dslCompute); DescriptorSetWrites dsUpdate = new DescriptorSetWrites(dsetPing, dslCompute); dsUpdate.Write(dev, inBuff.Descriptor, outBuff.Descriptor); dsUpdate.Write(dev, dsetPong, outBuff.Descriptor, inBuff.Descriptor); dsUpdate = new DescriptorSetWrites(dsImage, dslImage); dsUpdate.Write(dev, imgResult.Descriptor); UpdateFrequency = 5; }
public Program() : base() { #if DEBUG dbgReport = new DebugReport(instance, VkDebugReportFlagsEXT.ErrorEXT | VkDebugReportFlagsEXT.DebugEXT | VkDebugReportFlagsEXT.WarningEXT | VkDebugReportFlagsEXT.PerformanceWarningEXT ); #endif imgResult = new Image(dev, VkFormat.R32g32b32a32Sfloat, VkImageUsageFlags.TransferDst | VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, IMG_DIM, IMG_DIM); imgResult.CreateView(); imgResult.CreateSampler(VkFilter.Nearest, VkFilter.Nearest, VkSamplerMipmapMode.Nearest, VkSamplerAddressMode.ClampToBorder); imgResult.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal; staggingVBO = new HostBuffer <Vector2> (dev, VkBufferUsageFlags.TransferSrc, MAX_VERTICES); staggingVBO.Map(); vbo = new GPUBuffer <Vector2> (dev, VkBufferUsageFlags.VertexBuffer | VkBufferUsageFlags.StorageBuffer | VkBufferUsageFlags.TransferDst, MAX_VERTICES); ibo = new GPUBuffer <uint> (dev, VkBufferUsageFlags.IndexBuffer | VkBufferUsageFlags.StorageBuffer, MAX_VERTICES * 3); inBuff = new GPUBuffer <float> (dev, VkBufferUsageFlags.StorageBuffer | VkBufferUsageFlags.TransferSrc | VkBufferUsageFlags.TransferDst, (int)data_size); outBuff = new GPUBuffer <float> (dev, VkBufferUsageFlags.StorageBuffer | VkBufferUsageFlags.TransferSrc | VkBufferUsageFlags.TransferDst, (int)data_size); dsPool = new DescriptorPool(dev, 4, new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler), new VkDescriptorPoolSize(VkDescriptorType.StorageBuffer, 6)); dslImage = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) ); dslCompute = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer) ); dslVAO = new DescriptorSetLayout(dev, new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer), new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer) ); plInit = new ComputePipeline( new PipelineLayout(dev, new VkPushConstantRange(VkShaderStageFlags.Compute, 3 * sizeof(int)), dslCompute, dslVAO), "shaders/init.comp.spv"); plCompute = new ComputePipeline(plInit.Layout, "shaders/computeTest.comp.spv"); plNormalize = new ComputePipeline(plInit.Layout, "shaders/normalize.comp.spv"); GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1); cfg.Layout = new PipelineLayout(dev, dslImage); cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), VkSampleCountFlags.SampleCount1); cfg.RenderPass.ClearValues[0] = new VkClearValue { color = new VkClearColorValue(0.1f, 0.1f, 0.1f) }; cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/FullScreenQuad.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/simpletexture.frag.spv"); cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState(true); grPipeline = new GraphicPipeline(cfg); cfg.ResetShadersAndVerticesInfos(); cfg.Layout = new PipelineLayout(dev, new VkPushConstantRange(VkShaderStageFlags.Vertex, 4 * sizeof(int))); cfg.inputAssemblyState.topology = VkPrimitiveTopology.LineStrip; cfg.AddVertexBinding <Vector2> (0); cfg.SetVertexAttributes(0, VkFormat.R32g32Sfloat); cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/triangle.vert.spv"); cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/triangle.frag.spv"); trianglesPipeline = new GraphicPipeline(cfg); dsImage = dsPool.Allocate(dslImage); dsPing = dsPool.Allocate(dslCompute); dsPong = dsPool.Allocate(dslCompute); dsVAO = dsPool.Allocate(dslCompute); DescriptorSetWrites dsUpdate = new DescriptorSetWrites(dsPing, dslCompute); dsUpdate.Write(dev, inBuff.Descriptor, outBuff.Descriptor); dsUpdate.Write(dev, dsPong, outBuff.Descriptor, inBuff.Descriptor); dsUpdate = new DescriptorSetWrites(dsImage, dslImage); dsUpdate.Write(dev, imgResult.Descriptor); dsUpdate = new DescriptorSetWrites(dsVAO, dslVAO); dsUpdate.Write(dev, vbo.Descriptor, ibo.Descriptor); UpdateFrequency = 5; addPoint(IMG_DIM / 2 - 1, IMG_DIM / 2 - 1); }