Esempio n. 1
0
        protected virtual void CreateResources()
        {
            query_count_ = (uint)QUERY_HSIZE * 2;
            for (int i = 0; i < 3; i++)
            {
                query_pool[i] = new VkQueryPool(VkQueryType.Timestamp, query_count_);
            }

            uint[] queue_families = null;

            VkSharingMode sharingMode = VkSharingMode.Exclusive;

            if (Device.QFGraphics != Device.QFCompute)
            {
                sharingMode    = VkSharingMode.Concurrent;
                queue_families = new[] { Device.QFGraphics, Device.QFCompute };
            }

            uboCluster = new SharedBuffer(VkBufferUsageFlags.UniformBuffer, VkMemoryPropertyFlags.HostVisible | VkMemoryPropertyFlags.HostCoherent,
                                          (uint)Utilities.SizeOf <ClusterUBO>(), sharingMode, queue_families);

            uint max_grid_count = ((MAX_WIDTH - 1) / TILE_WIDTH + 1) * ((MAX_HEIGHT - 1) / TILE_HEIGHT + 1) * TILE_COUNT_Z;

            gridFlags = Buffer.CreateTexelBuffer(VkBufferUsageFlags.TransferDst, max_grid_count, VkFormat.R8UInt, sharingMode, queue_families);

            clusterLayout1 = new DescriptorSetLayout
            {
                new DescriptorSetLayoutBinding(0, VkDescriptorType.UniformBuffer, VkShaderStageFlags.Fragment),
                new DescriptorSetLayoutBinding(1, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Fragment),
            };

            clusterSet1 = new DescriptorSet(clusterLayout1, uboCluster, gridFlags);
        }
Esempio n. 2
0
        public Terrain()
        {
            batch   = new TerrainBatch();
            batches = new[] { batch };

            material = new Material("shaders/Terrain.shader");

            uboTess = new TessUBO
            {
                lightPos            = new vec4(-48.0f, -40.0f, 46.0f, 0.0f),
                displacementFactor  = 32.0f,
                tessellationFactor  = 0.75f,
                tessellatedEdgeSize = 20.0f
            };

            batch.material = material;

            ubTess = new SharedBuffer(VkBufferUsageFlags.UniformBuffer, (uint)Utilities.SizeOf <TessUBO>());

            dsLayout = new DescriptorSetLayout
            {
                new DescriptorSetLayoutBinding(0, VkDescriptorType.UniformBuffer, VkShaderStageFlags.Fragment | VkShaderStageFlags.TessellationControl | VkShaderStageFlags.TessellationEvaluation),
                new DescriptorSetLayoutBinding(1, VkDescriptorType.CombinedImageSampler, VkShaderStageFlags.Fragment | VkShaderStageFlags.TessellationControl | VkShaderStageFlags.TessellationEvaluation),
                new DescriptorSetLayoutBinding(2, VkDescriptorType.CombinedImageSampler, VkShaderStageFlags.Fragment | VkShaderStageFlags.TessellationControl | VkShaderStageFlags.TessellationEvaluation),
            };

            dsTess = new DescriptorSet(dsLayout);
            dsTess.Bind(0, ubTess);
        }
Esempio n. 3
0
        private DescriptorSet BindTexel(uint dstBinding, SharedBuffer buffer)
        {
            var descriptorType = resourceLayout.Bindings[(int)dstBinding].descriptorType;

            for (int img = 0; img < Swapchain.IMAGE_COUNT; img++)
            {
                AddWriteDescriptorSet(img, new VkWriteDescriptorSet(dstBinding, descriptorSet[img], descriptorType, ref buffer.Buffer.descriptor, ref buffer.Buffer.view.HandleRef));
            }

            return(this);
        }
Esempio n. 4
0
        public DescriptorSet Bind(uint dstBinding, SharedBuffer buffer)
        {
            var descriptorType = resourceLayout.Bindings[(int)dstBinding].descriptorType;

            for (int img = 0; img < Swapchain.IMAGE_COUNT; img++)
            {
                AddWriteDescriptorSet(img, new VkWriteDescriptorSet(dstBinding, descriptorSet[img], descriptorType, ref buffer[img].descriptor, 1));
            }

            return(this);
        }
Esempio n. 5
0
        public ShadowPass() : base(SubmitQueue.EarlyGraphics)
        {
            var depthFormat = Device.GetSupportedDepthFormat();

            for (uint i = 0; i < SHADOW_MAP_CASCADE_COUNT; i++)
            {
                cascades[i].view = ImageView.Create(DepthRT.image, VkImageViewType.Image2DArray, depthFormat, VkImageAspectFlags.Depth, 0, 1, i, 1);
            }

            ubShadow = new SharedBuffer(VkBufferUsageFlags.UniformBuffer, (uint)(SHADOW_MAP_CASCADE_COUNT * Utilities.SizeOf <mat4>()));

            depthShader = Resources.Instance.Load <Shader>("shaders/shadow.shader");

            vsSet = new DescriptorSet(depthShader.Main.GetResourceLayout(0), ubShadow, FrameGraph.TransformBuffer);
        }
        private void InitLightCompute()
        {
            uint[] queue_families = null;

            VkSharingMode sharingMode = VkSharingMode.Exclusive;

            if (Device.QFGraphics != Device.QFCompute)
            {
                sharingMode    = VkSharingMode.Concurrent;
                queue_families = new[] { Device.QFGraphics, Device.QFCompute };
            }

            uint max_grid_count = ((MAX_WIDTH - 1) / TILE_WIDTH + 1) * ((MAX_HEIGHT - 1) / TILE_HEIGHT + 1) * TILE_COUNT_Z;

            light_pos_ranges = new SharedBuffer(VkBufferUsageFlags.StorageTexelBuffer, VkMemoryPropertyFlags.HostVisible | VkMemoryPropertyFlags.HostCoherent,
                                                MAX_NUM_LIGHTS * 4 * sizeof(float), VkSharingMode.Exclusive, queue_families);
            light_pos_ranges.CreateView(VkFormat.R32G32B32A32SFloat);

            light_colors = new SharedBuffer(VkBufferUsageFlags.StorageTexelBuffer, VkMemoryPropertyFlags.HostVisible | VkMemoryPropertyFlags.HostCoherent,
                                            MAX_NUM_LIGHTS * sizeof(uint), sharingMode, queue_families);
            light_colors.CreateView(VkFormat.R8G8B8A8UNorm);

            lightBounds            = Buffer.CreateTexelBuffer(VkBufferUsageFlags.TransferDst, MAX_NUM_LIGHTS * 6 * sizeof(uint), VkFormat.R32UInt, sharingMode, queue_families); // max tile count 1d (z 256)
            gridLightCounts        = Buffer.CreateTexelBuffer(VkBufferUsageFlags.TransferDst, max_grid_count * sizeof(uint), VkFormat.R32UInt, sharingMode, queue_families);     // light count / grid
            gridLightCountTotal    = Buffer.CreateTexelBuffer(VkBufferUsageFlags.TransferDst, sizeof(uint), VkFormat.R32UInt, sharingMode, queue_families);                      // light count total * max grid count
            gridLightCountOffsets  = Buffer.CreateTexelBuffer(VkBufferUsageFlags.TransferDst, max_grid_count * sizeof(uint), VkFormat.R32UInt, sharingMode, queue_families);     // same as above
            lightList              = Buffer.CreateTexelBuffer(VkBufferUsageFlags.TransferDst, 1024 * 1024 * sizeof(uint), VkFormat.R32UInt, sharingMode, queue_families);        // light idx
            gridLightCountsCompare = Buffer.CreateTexelBuffer(VkBufferUsageFlags.TransferDst, max_grid_count * sizeof(uint), VkFormat.R32UInt, sharingMode, queue_families);     // light count / grid

            resourceLayout0 = new DescriptorSetLayout(1)
            {
                new DescriptorSetLayoutBinding(0, VkDescriptorType.UniformBuffer, VkShaderStageFlags.Fragment),
                new DescriptorSetLayoutBinding(1, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Fragment),
                new DescriptorSetLayoutBinding(2, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Fragment),
            };

            resourceLayout1 = new DescriptorSetLayout(2)
            {
                new DescriptorSetLayoutBinding(0, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Fragment),
                new DescriptorSetLayoutBinding(1, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Fragment),
                new DescriptorSetLayoutBinding(2, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Fragment),
                new DescriptorSetLayoutBinding(3, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Fragment),
                new DescriptorSetLayoutBinding(4, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Fragment),
                new DescriptorSetLayoutBinding(5, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Fragment),
                new DescriptorSetLayoutBinding(6, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Fragment),
            };

            resourceSet1 = new DescriptorSet(resourceLayout0, uboCluster, light_pos_ranges, light_colors);
            resourceSet2 = new DescriptorSet(resourceLayout1, gridFlags, lightBounds, gridLightCounts, gridLightCountTotal,
                                             gridLightCountOffsets, lightList, gridLightCountsCompare);


            clusterLight = Resources.Instance.Load <Shader>("Shaders/ClusterLight.shader");

            computeLayout0 = new DescriptorSetLayout
            {
                new DescriptorSetLayoutBinding(0, VkDescriptorType.UniformBuffer, VkShaderStageFlags.Compute),
                new DescriptorSetLayoutBinding(1, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Compute),
                new DescriptorSetLayoutBinding(2, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Compute),
            };

            computeLayout1 = new DescriptorSetLayout
            {
                new DescriptorSetLayoutBinding(0, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Compute),
                new DescriptorSetLayoutBinding(1, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Compute),
                new DescriptorSetLayoutBinding(2, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Compute),
                new DescriptorSetLayoutBinding(3, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Compute),
                new DescriptorSetLayoutBinding(4, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Compute),
                new DescriptorSetLayoutBinding(5, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Compute),
                new DescriptorSetLayoutBinding(6, VkDescriptorType.StorageTexelBuffer, VkShaderStageFlags.Compute),
            };

            computeSet0 = new DescriptorSet(computeLayout0, uboCluster, light_pos_ranges, light_colors);
            computeSet1 = new DescriptorSet(computeLayout1, gridFlags, lightBounds, gridLightCounts, gridLightCountTotal,
                                            gridLightCountOffsets, lightList, gridLightCountsCompare);
        }