Ejemplo n.º 1
0
        //in the main vulkan thread
        void updateTextureSet()
        {
            nextTexture.CreateView(VkImageViewType.Cube, VkImageAspectFlags.Color, 6);
            nextTexture.CreateSampler();

            nextTexture.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;
            DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descriptorSet, dsLayout.Bindings[1]);

            uboUpdate.Write(dev, nextTexture.Descriptor);

            texture?.Dispose();
            texture     = nextTexture;
            nextTexture = null;
        }
Ejemplo n.º 2
0
        //in the main vulkan thread
        void updateTextureSet()
        {
            nextTexture.CreateView();
            nextTexture.CreateSampler();
            nextTexture.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;

            dev.WaitIdle();

            DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descriptorSet, dsLayout.Bindings[1]);

            uboUpdate.Write(dev, nextTexture.Descriptor);

            texture?.Dispose();
            texture     = nextTexture;
            nextTexture = null;
        }
Ejemplo n.º 3
0
 //in the thread of the keyboard
 void loadTexture(string path)
 {
     try {
         if (path.EndsWith("ktx", StringComparison.OrdinalIgnoreCase))
         {
             nextTexture = KTX.KTX.Load(presentQueue, cmdPool, path,
                                        VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, true);
         }
         else
         {
             nextTexture = Image.Load(dev, path);
         }
         updateViewRequested = true;
     } catch (Exception ex) {
         Console.WriteLine(ex);
         nextTexture = null;
     }
 }
Ejemplo n.º 4
0
 //in the thread of the keyboard
 void loadTexture(string path)
 {
     try {
         Console.WriteLine($"Loading:{path}");
         if (path.EndsWith("ktx", StringComparison.OrdinalIgnoreCase))
         {
             nextTexture = KTX.KTX.Load(presentQueue, cmdPool, path,
                                        VkImageUsageFlags.Sampled, imgProp, genMipMaps, tiling);
         }
         else
         {
             nextTexture = Image.Load(dev, presentQueue, cmdPool, path, VkFormat.R8g8b8a8Unorm, imgProp, tiling, genMipMaps);
         }
         updateViewRequested = true;
     } catch (Exception ex) {
         Console.WriteLine(ex);
         nextTexture = null;
     }
 }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        protected override void initVulkan()
        {
            base.initVulkan();

            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(dev, VkShaderStageFlags.Vertex, "#vke.FullScreenQuad.vert.spv");
            cfg.AddShader(dev, VkShaderStageFlags.Fragment, "#shaders.simpletexture.frag.spv");

            cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState(true);

            grPipeline = new GraphicPipeline(cfg);

            cfg.DisposeShaders();

            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;
        }