这是indexloc提供的服务,不要输入任何密码
Skip to content

[BUG] Failed to obtain vulkan context #3312

@shitake2333

Description

@shitake2333

Description

I'm trying to make skiasharp and godot work together. I want them to share gpu textures. When I use GRContext.CreateVulkan it keeps returning null.

I use the following code to create a SKSurface

        GRVkImageInfo vkImageInfo = new GRVkImageInfo
        {
            Alloc = new GRVkAlloc(),
            Image = textureHandle,
            ImageLayout = 7, // VK_IMAGE_LAYOUT_GENERAL
            Format = 37, // VK_FORMAT_R8G8B8A8_UNORM
            LevelCount = 1,
            SampleCount = 1,
            Protected = false
        };

        GRBackendTexture backendTexture = new GRBackendTexture(Width, Height, vkImageInfo);
        GRVkBackendContext vkBackendContext = new GRVkBackendContext
        {
            VkDevice = VkDevice,
            VkPhysicalDevice = VkPhysicalDevice,
            VkInstance = VkInstance,
            VkQueue = VkQueue,
            GraphicsQueueIndex = 0
        };
        
        var context = GRContext.CreateVulkan(vkBackendContext);
        
        if (context == null)
        {
            backendTexture.Dispose();
            throw new InvalidOperationException("Vulkan GRContext creation failed");
        }
        
        SKSurface surface = SKSurface.Create(context, backendTexture, GRSurfaceOrigin.TopLeft, SKColorType.Rgba8888);
        if (surface == null)
        {
            backendTexture.Dispose();
            context.Dispose();
            throw new InvalidOperationException("Vulkan SKSurface creation failed");
        }
        

Code

The best way to share code for larger projects is a link to a GitHub repository: https://github.com/user/repo/tree/bug-123

But, you can also share a short block of code here:

// some C# code here

You can also share some XAML:

<!-- xaml code here -->

Expected Behavior

No response

Actual Behavior

No response

Version of SkiaSharp

3.116.0 (Current)

Last Known Good Version of SkiaSharp

Other (Please indicate in the description)

IDE / Editor

Other (Please indicate in the description)

Platform / Operating System

Windows

Platform / Operating System Version

No response

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions