Exemplo n.º 1
0
        public void VkGpuSurfaceIsCreated()
        {
            using var ctx = CreateVkContext();

            using var grVkBackendContext = new GRVkBackendContext
                  {
                      VkInstance          = (IntPtr)ctx.Instance.RawHandle.ToUInt64(),
                      VkPhysicalDevice    = (IntPtr)ctx.PhysicalDevice.RawHandle.ToUInt64(),
                      VkDevice            = (IntPtr)ctx.Device.RawHandle.ToUInt64(),
                      VkQueue             = (IntPtr)ctx.GraphicsQueue.RawHandle.ToUInt64(),
                      GraphicsQueueIndex  = ctx.GraphicsFamily,
                      GetProcedureAddress = ctx.GetProc
                  };

            Assert.NotNull(grVkBackendContext);

            using var grContext = GRContext.CreateVulkan(grVkBackendContext);

            using var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100));

            Assert.NotNull(surface);

            var canvas = surface.Canvas;

            Assert.NotNull(canvas);

            canvas.Clear(SKColors.Transparent);

            canvas.Flush();
        }
Exemplo n.º 2
0
        public VulkanContext()
        {
            // Try everything in separate try-catch blocks to provide some accuracy in error reporting
            try
            {
                _vulkanContext = new Win32VkContext();
            }
            catch (Exception e)
            {
                throw new ArtemisGraphicsContextException("Failed to create Vulkan context", e);
            }

            try
            {
                _vulkanBackendContext = new GRVkBackendContext
                {
                    VkInstance          = (IntPtr)_vulkanContext.Instance.RawHandle.ToUInt64(),
                    VkPhysicalDevice    = (IntPtr)_vulkanContext.PhysicalDevice.RawHandle.ToUInt64(),
                    VkDevice            = (IntPtr)_vulkanContext.Device.RawHandle.ToUInt64(),
                    VkQueue             = (IntPtr)_vulkanContext.GraphicsQueue.RawHandle.ToUInt64(),
                    GraphicsQueueIndex  = _vulkanContext.GraphicsFamily,
                    GetProcedureAddress = _vulkanContext.GetProc
                };
            }
            catch (Exception e)
            {
                throw new ArtemisGraphicsContextException("Failed to create Vulkan backend context", e);
            }

            try
            {
                GraphicsContext = GRContext.CreateVulkan(_vulkanBackendContext);
                if (GraphicsContext == null)
                {
                    throw new ArtemisGraphicsContextException("GRContext.CreateVulkan returned null");
                }
            }
            catch (Exception e)
            {
                throw new ArtemisGraphicsContextException("Failed to create Vulkan graphics context", e);
            }

            GraphicsContext.Flush();
        }
Exemplo n.º 3
0
        public void CreateVkContextIsValid()
        {
            using var ctx = CreateVkContext();

            using var grVkBackendContext = new GRVkBackendContext
                  {
                      VkInstance          = (IntPtr)ctx.Instance.RawHandle.ToUInt64(),
                      VkPhysicalDevice    = (IntPtr)ctx.PhysicalDevice.RawHandle.ToUInt64(),
                      VkDevice            = (IntPtr)ctx.Device.RawHandle.ToUInt64(),
                      VkQueue             = (IntPtr)ctx.GraphicsQueue.RawHandle.ToUInt64(),
                      GraphicsQueueIndex  = ctx.GraphicsFamily,
                      GetProcedureAddress = ctx.GetProc
                  };

            Assert.NotNull(grVkBackendContext);

            using var grContext = GRContext.CreateVulkan(grVkBackendContext);

            Assert.NotNull(grContext);
        }
Exemplo n.º 4
0
        private void Initialize()
        {
            GRVkGetProcedureAddressDelegate getProc = GetVulkanProcAddress;

            _grVkBackend = new GRVkBackendContext()
            {
                VkInstance          = _surface.Device.Handle,
                VkPhysicalDevice    = _vulkanPlatformInterface.PhysicalDevice.Handle,
                VkDevice            = _surface.Device.Handle,
                VkQueue             = _surface.Device.Queue.Handle,
                GraphicsQueueIndex  = _vulkanPlatformInterface.PhysicalDevice.QueueFamilyIndex,
                GetProcedureAddress = getProc
            };

            GrContext = GRContext.CreateVulkan(_grVkBackend);

            var gpu = AvaloniaLocator.Current.GetService <VulkanSkiaGpu>();

            if (gpu.MaxResourceBytes.HasValue)
            {
                GrContext.SetResourceCacheLimit(gpu.MaxResourceBytes.Value);
            }
        }