Example #1
0
 protected override void InitializeFrame()
 {
     _depthStencilBuffer = ToDispose(VulkanImage.DepthStencil(Context, Host.Width, Host.Height));
     _renderPass         = ToDispose(CreateRenderPass());
     _imageViews         = ToDispose(CreateImageViews());
     _framebuffers       = ToDispose(CreateFramebuffers());
     _pipeline           = ToDispose(CreateGraphicsPipeline());
     SetViewProjection();
 }
        protected override void InitializeFrame()
        {
            _depthStencil = ToDispose(VulkanImage.DepthStencil(Context, Host.Width, Host.Height));
            _renderPass   = ToDispose(CreateRenderPass());
            _imageViews   = ToDispose(CreateImageViews());
            _framebuffers = ToDispose(CreateFramebuffers());

            _graphicsPipeline = ToDispose(CreateGraphicsPipeline());

            _computePipeline = ToDispose(CreateComputePipeline());
            RecordComputeCommandBuffer();
        }
Example #3
0
        protected override void InitializePermanent()
        {
            var cube = GeometricPrimitive.Box(1.0f, 1.0f, 1.0f);

            _cubeTexture         = Content.Load <VulkanImage>("IndustryForgedDark512.ktx");
            _cubeVertices        = ToDispose(VulkanBuffer.Vertex(Context, cube.Vertices));
            _cubeIndices         = ToDispose(VulkanBuffer.Index(Context, cube.Indices));
            _sampler             = ToDispose(CreateSampler());
            _uniformBuffer       = ToDispose(VulkanBuffer.DynamicUniform <WorldViewProjection>(Context, 1));
            _descriptorSetLayout = ToDispose(CreateDescriptorSetLayout());
            _pipelineLayout      = ToDispose(CreatePipelineLayout());
            _descriptorPool      = ToDispose(CreateDescriptorPool());
            _descriptorSet       = CreateDescriptorSet(); // Will be freed when pool is destroyed.
        }
        protected override void InitializePermanent()
        {
            _descriptorPool = ToDispose(CreateDescriptorPool());

            _sampler                     = ToDispose(CreateSampler());
            _particleDiffuseMap          = Content.Load <VulkanImage>("ParticleDiffuse.ktx");
            _graphicsDescriptorSetLayout = ToDispose(CreateGraphicsDescriptorSetLayout());
            _graphicsPipelineLayout      = ToDispose(CreateGraphicsPipelineLayout());
            _graphicsDescriptorSet       = CreateGraphicsDescriptorSet();

            _storageBuffer = ToDispose(CreateStorageBuffer());
            _uniformBuffer = ToDispose(VulkanBuffer.DynamicUniform <UniformBufferObject>(Context, 1));
            _computeDescriptorSetLayout = ToDispose(CreateComputeDescriptorSetLayout());
            _computePipelineLayout      = ToDispose(CreateComputePipelineLayout());
            _computeDescriptorSet       = CreateComputeDescriptorSet();
            _computeCmdBuffer           = Context.ComputeCommandPool.AllocateBuffers(new CommandBufferAllocateInfo(CommandBufferLevel.Primary, 1))[0];
            _computeFence = ToDispose(Context.Device.CreateFence());
        }
        protected override void InitializeFrame()
        {
            _depthStencilBuffer = ToDispose(VulkanImage.DepthStencil(Context, Host.Width, Host.Height));
            var renderPass = CreateRenderPass();

            _renderPass = renderPass;
            ToDispose(new ActionDisposable(() =>
            {
                vkDestroyRenderPass(Context.Device, renderPass, null);
            }));
            var imageViews = CreateImageViews();

            _imageViews = imageViews;
            ToDispose(new ActionDisposable(() =>
            {
                foreach (var imageView in imageViews)
                {
                    vkDestroyImageView(Context.Device, imageView, null);
                }
            }));
            var frameBuffers = CreateFramebuffers();

            _framebuffers = frameBuffers;
            ToDispose(new ActionDisposable(() =>
            {
                foreach (var frameBuffer in frameBuffers)
                {
                    vkDestroyFramebuffer(Context.Device, frameBuffer, null);
                }
            }));
            var pipeline = CreateGraphicsPipeline();

            _pipeline = pipeline;
            ToDispose(new ActionDisposable(() =>
            {
                vkDestroyPipeline(Context.Device, pipeline, null);
            }));
            SetViewProjection();
        }
        protected override void InitializePermanent()
        {
            var cube = GeometricPrimitive.Box(1.0f, 1.0f, 1.0f);

            _cubeTexture  = Content.LoadVulkanImage("IndustryForgedDark512.ktx");
            _cubeVertices = ToDispose(VulkanBuffer.Vertex(Context, cube.Vertices));
            _cubeIndices  = ToDispose(VulkanBuffer.Index(Context, cube.Indices));
            var sampler = CreateSampler();

            _sampler = sampler;
            ToDispose(new ActionDisposable(() =>
            {
                vkDestroySampler(Context.Device, sampler, null);
            }));
            _uniformBuffer = ToDispose(VulkanBuffer.DynamicUniform <WorldViewProjection>(Context, 1));
            var descriptorSetLayout = CreateDescriptorSetLayout();

            _descriptorSetLayout = descriptorSetLayout;
            ToDispose(new ActionDisposable(() =>
            {
                vkDestroyDescriptorSetLayout(Context.Device, descriptorSetLayout, null);
            }));
            var pipelineLayout = CreatePipelineLayout();

            _pipelineLayout = pipelineLayout;
            ToDispose(new ActionDisposable(() =>
            {
                vkDestroyPipelineLayout(Context.Device, pipelineLayout, null);
            }));
            var descriptorPool = CreateDescriptorPool();

            _descriptorPool = descriptorPool;
            ToDispose(new ActionDisposable(() =>
            {
                vkDestroyDescriptorPool(Context.Device, descriptorPool, null);
            }));
            _descriptorSet = CreateDescriptorSet(_descriptorPool); // Will be freed when pool is destroyed.
        }
Example #7
0
        public static VulkanImage LoadKtxVulkanImage(IVulkanAppHost host, VulkanContext ctx, string path)
        {
            using (var reader = new BinaryReader(host.Open(path)))
            {
                byte[] identifier = reader.ReadBytes(12);

                if (!identifier.SequenceEqual(KtxIdentifier))
                {
                    throw new InvalidOperationException("File is not in Khronos Texture format.");
                }

                int endienness            = reader.ReadInt32();
                int glType                = reader.ReadInt32();
                int glTypeSize            = reader.ReadInt32();
                int glFormat              = reader.ReadInt32();
                int glInternalFormat      = reader.ReadInt32();
                int glBaseInternalFormat  = reader.ReadInt32();
                int pixelWidth            = reader.ReadInt32();
                int pixelHeight           = reader.ReadInt32();
                int pixelDepth            = reader.ReadInt32();
                int numberOfArrayElements = reader.ReadInt32();
                int numberOfFaces         = reader.ReadInt32();
                int numberOfMipmapLevels  = reader.ReadInt32();
                int bytesOfKeyValueData   = reader.ReadInt32();

                // Skip key-value data.
                reader.ReadBytes(bytesOfKeyValueData);

                // Some of the values may be 0 - ensure at least 1.
                pixelWidth            = Math.Max(pixelWidth, 1);
                pixelHeight           = Math.Max(pixelHeight, 1);
                pixelDepth            = Math.Max(pixelDepth, 1);
                numberOfArrayElements = Math.Max(numberOfArrayElements, 1);
                numberOfFaces         = Math.Max(numberOfFaces, 1);
                numberOfMipmapLevels  = Math.Max(numberOfMipmapLevels, 1);

                int numberOfSlices = Math.Max(numberOfFaces, numberOfArrayElements);

                if (!_glInternalFormatToVkFormat.TryGetValue(glInternalFormat, out Format format))
                {
                    throw new NotImplementedException("glInternalFormat not mapped to VkFormat.");
                }

                var data = new TextureData
                {
                    Mipmaps = new TextureData.Mipmap[numberOfMipmapLevels],
                    Format  = format
                };

                for (int i = 0; i < numberOfMipmapLevels; i++)
                {
                    var mipmap = new TextureData.Mipmap();
                    mipmap.Size     = reader.ReadInt32();
                    mipmap.Extent   = new Extent3D(pixelWidth, pixelHeight, pixelDepth);
                    mipmap.Data     = reader.ReadBytes(mipmap.Size);
                    data.Mipmaps[i] = mipmap;
                    break; // TODO: impl
                    //for (int j = 0; j < numberOfArrayElements; j++)
                    //{
                    //    for (int k = 0; k < numberOfFaces; k++)
                    //    {
                    //        for (int l = 0; l < pixelDepth; l++)
                    //        {
                    //            //for (int row = 0;
                    //            //    row < )
                    //        }
                    //    }
                    //}
                }

                return(VulkanImage.Texture2D(ctx, data));
            }
        }
        private void CreateImage()
        {
            Size = Display.Size;

            Image = new VulkanImage(Device, _platformInterface.PhysicalDevice, Display.CommandBufferPool, ImageFormat, Size);
        }