public List <SpecializationInfo> GetSpecialization() { List <SpecializationInfo> SpecializationList = new List <SpecializationInfo>(); DataTable dt = _sqlHelper.ExecuteDataTable(null, Storeprocedures.spdrpSpecialization.ToString(), CommandType.StoredProcedure); foreach (DataRow dr in dt.Rows) { SpecializationInfo specialization = new SpecializationInfo(); if (!dr.IsNull("SpecializationId")) { specialization.SpecializationId = Convert.ToInt32(dr["SpecializationId"]); } if (!dr.IsNull("Specializationname")) { specialization.Specializationname = Convert.ToString(dr["Specializationname"]); } SpecializationList.Add(specialization); } return(SpecializationList); }
public SpecializationInfo GetSpecializationInfo() { SpecializationInfo specializationInfo = null; List <ShaderConstant> specializationConstants = GetSpecializationConstants(); if (specializationConstants.Any()) { int[] values = specializationConstants.Select(sc => specializationConstantValues[sc.Name]).ToArray(); fixed(void *p = &values[0]) { specializationInfo = new SpecializationInfo() { MapEntries = specializationConstants .Select(sc => new SpecializationMapEntry() { ConstantId = sc.Id, Offset = sc.Offset, Size = new UIntPtr(sc.Size), }).ToArray(), Data = new IntPtr(p), DataSize = new UIntPtr((uint)(values.Length * sizeof(int))) }; } } return(specializationInfo); }
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 Preprocess() { Shader shader = Resources.Load <Shader>("shaders/brdf.shader"); { Pass pass = shader.GetPass("SpMap"); uint numMipTailLevels = (uint)kEnvMapLevels - 1; // Compute pre-filtered specular environment map. var specializationInfo = new SpecializationInfo(new VkSpecializationMapEntry(0, 0, sizeof(uint))); specializationInfo.Write(0, numMipTailLevels); pass.ComputeShader.SpecializationInfo = specializationInfo; DescriptorSetLayout resLayout = pass.GetResourceLayout(0); spSet = new DescriptorSet(resLayout); CommandBuffer commandBuffer = Graphics.BeginPrimaryCmd(); // Copy base mipmap level into destination environment map. { Span <VkImageMemoryBarrier> preCopyBarriers = stackalloc[] { new VkImageMemoryBarrier(cubeMap.image, 0, VkAccessFlags.TransferRead, VkImageLayout.ShaderReadOnlyOptimal, VkImageLayout.TransferSrcOptimal, VkImageAspectFlags.Color, 0, 1), new VkImageMemoryBarrier(envMap.image, 0, VkAccessFlags.TransferWrite, VkImageLayout.Undefined, VkImageLayout.TransferDstOptimal), }; Span <VkImageMemoryBarrier> postCopyBarriers = stackalloc[] { new VkImageMemoryBarrier(cubeMap.image, VkAccessFlags.TransferRead, VkAccessFlags.ShaderRead, VkImageLayout.TransferSrcOptimal, VkImageLayout.ShaderReadOnlyOptimal, VkImageAspectFlags.Color, 0, 1), new VkImageMemoryBarrier(envMap.image, VkAccessFlags.TransferWrite, VkAccessFlags.ShaderWrite, VkImageLayout.TransferDstOptimal, VkImageLayout.General), }; commandBuffer.PipelineBarrier(VkPipelineStageFlags.TopOfPipe, VkPipelineStageFlags.Transfer, preCopyBarriers); VkImageCopy copyRegion = new VkImageCopy { extent = new VkExtent3D(envMap.width, envMap.height, 1) }; copyRegion.srcSubresource.aspectMask = VkImageAspectFlags.Color; copyRegion.srcSubresource.layerCount = envMap.layers; copyRegion.dstSubresource = copyRegion.srcSubresource; commandBuffer.CopyImage(cubeMap.image, VkImageLayout.TransferSrcOptimal, envMap.image, VkImageLayout.TransferDstOptimal, ref copyRegion); commandBuffer.PipelineBarrier(VkPipelineStageFlags.Transfer, VkPipelineStageFlags.ComputeShader, postCopyBarriers); // Pre-filter rest of the mip-chain. List <ImageView> envTextureMipTailViews = new List <ImageView>(); var inputTexture = new VkDescriptorImageInfo(computeSampler, cubeMap.imageView, VkImageLayout.ShaderReadOnlyOptimal); spSet.Bind(0, ref inputTexture); Span <VkDescriptorImageInfo> envTextureMipTailDescriptors = stackalloc VkDescriptorImageInfo[(int)numMipTailLevels]; for (uint level = 0; level < numMipTailLevels; ++level) { var view = ImageView.Create(envMap.image, VkImageViewType.ImageCube, VkFormat.R16G16B16A16SFloat, VkImageAspectFlags.Color, level + 1, 1, 0, envMap.image.arrayLayers); envTextureMipTailViews.Add(view); envTextureMipTailDescriptors[(int)level] = new VkDescriptorImageInfo(VkSampler.Null, view, VkImageLayout.General); } spSet.Bind(1, envTextureMipTailDescriptors); spSet.UpdateSets(); commandBuffer.BindComputePipeline(pass); commandBuffer.BindComputeResourceSet(pass.PipelineLayout, 0, spSet); float deltaRoughness = 1.0f / Math.Max((float)numMipTailLevels, 1.0f); for (uint level = 1, size = kEnvMapSize / 2; level < kEnvMapLevels; ++level, size /= 2) { uint numGroups = Math.Max(1, size / 32); var pushConstants = new SpecularFilterPushConstants { level = level - 1, roughness = level * deltaRoughness }; commandBuffer.PushConstants(pass.PipelineLayout, VkShaderStageFlags.Compute, 0, ref pushConstants); commandBuffer.Dispatch(numGroups, numGroups, 6); } var barrier = new VkImageMemoryBarrier(envMap.image, VkAccessFlags.ShaderWrite, 0, VkImageLayout.General, VkImageLayout.ShaderReadOnlyOptimal); commandBuffer.PipelineBarrier(VkPipelineStageFlags.ComputeShader, VkPipelineStageFlags.BottomOfPipe, ref barrier); } Graphics.EndPrimaryCmd(commandBuffer); } // Compute diffuse irradiance cubemap { Pass pass = shader.GetPass("IrMap"); DescriptorSetLayout resLayout = pass.GetResourceLayout(0); irSet = new DescriptorSet(resLayout, cubeMap, irMap); CommandBuffer commandBuffer = Graphics.BeginPrimaryCmd(); { Span <VkImageMemoryBarrier> barriers = stackalloc [] { new VkImageMemoryBarrier(irMap.image, 0, VkAccessFlags.ShaderWrite, VkImageLayout.Undefined, VkImageLayout.General) }; commandBuffer.PipelineBarrier(VkPipelineStageFlags.TopOfPipe, VkPipelineStageFlags.ComputeShader, barriers); commandBuffer.BindComputePipeline(pass); commandBuffer.BindComputeResourceSet(pass.PipelineLayout, 0, irSet); commandBuffer.Dispatch(kIrradianceMapSize / 32, kIrradianceMapSize / 32, 6); Span <VkImageMemoryBarrier> postDispatchBarrier = stackalloc [] { new VkImageMemoryBarrier(irMap.image, VkAccessFlags.ShaderWrite, 0, VkImageLayout.General, VkImageLayout.ShaderReadOnlyOptimal) }; commandBuffer.PipelineBarrier(VkPipelineStageFlags.ComputeShader, VkPipelineStageFlags.BottomOfPipe, postDispatchBarrier); } Graphics.EndPrimaryCmd(commandBuffer); } // Compute Cook-Torrance BRDF 2D LUT for split-sum approximation. { var pass = shader.GetPass("BrdfLUT"); DescriptorSetLayout resLayout = pass.GetResourceLayout(0); brdfLUTSet = new DescriptorSet(resLayout, brdfLUT); CommandBuffer commandBuffer = Graphics.BeginPrimaryCmd(); { Span <VkImageMemoryBarrier> barriers = stackalloc [] { new VkImageMemoryBarrier(brdfLUT.image, 0, VkAccessFlags.ShaderWrite, VkImageLayout.Undefined, VkImageLayout.General) }; commandBuffer.PipelineBarrier(VkPipelineStageFlags.TopOfPipe, VkPipelineStageFlags.ComputeShader, barriers); commandBuffer.BindComputePipeline(pass); commandBuffer.BindComputeResourceSet(pass.PipelineLayout, 0, brdfLUTSet); commandBuffer.Dispatch(kBRDF_LUT_Size / 32, kBRDF_LUT_Size / 32, 6); Span <VkImageMemoryBarrier> postDispatchBarrier = stackalloc [] { new VkImageMemoryBarrier(brdfLUT.image, VkAccessFlags.ShaderWrite, 0, VkImageLayout.General, VkImageLayout.ShaderReadOnlyOptimal) }; commandBuffer.PipelineBarrier(VkPipelineStageFlags.ComputeShader, VkPipelineStageFlags.BottomOfPipe, postDispatchBarrier); } Graphics.EndPrimaryCmd(commandBuffer); } } int selected = 0;
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); }