Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wgpuInstanceRequestAdapter fails when called with a specific backend #337

Open
vehsakul opened this issue Dec 25, 2023 · 5 comments
Open

Comments

@vehsakul
Copy link

  WGPURequestAdapterOptions requestAdapterOptions;
  requestAdapterOptions.nextInChain = nullptr;
  requestAdapterOptions.compatibleSurface = surface_;
  requestAdapterOptions.powerPreference = WGPUPowerPreference_HighPerformance;
  requestAdapterOptions.forceFallbackAdapter = true;
  requestAdapterOptions.backendType = WGPUBackendType_D3D12;

result:

Validation Error

Caused by:
    No suitable adapter found

surface_ was created by SDL2 library, it used to work using the last wgpu-native release from github

@Capati
Copy link

Capati commented Jan 30, 2024

I had this issue too, forcing backendType = WGPUBackendType_D3D12 rises the same error.

@laurelkeys
Copy link
Contributor

Same error when updating from v0.18.1.4 to v0.19.1.1. As mentioned above, it's happening with WGPUBackendType_D3D12 (WGPUBackendType_Vulkan works fine).

@rajveermalviya
Copy link
Collaborator

Unfortunately I am unable to reproduce this behavior, does it fail if backendType is set to WGPUBackendType_Undefined?

@laurelkeys
Copy link
Contributor

WGPUBackendType_Undefined works ok, and ends up choosing the Vulkan backend.

Using wgpuInstanceEnumerateAdapters I have Vulkan, Dx12 and Gl backends. Passing .backendType = WGPUBackendType_D3D12, WGPUBackendType_OpenGL and WGPUBackendType_WebGPU (not sure what's expected for WebGPU, but I tried all values) will result in "No suitable adapter found".

This should be a minimal example that repros it:

int main(int argc, char **argv)
{
    WGPUInstance instance = wgpuCreateInstance(nullptr);
    assert(instance);

    // Note: uncomment to print available adapters (requires `wgpuSetLogLevel(WGPULogLevel_Info)`).
    // const WGPUInstanceEnumerateAdapterOptions options = { .backends = WGPUInstanceBackend_All };
    // const size_t count = wgpuInstanceEnumerateAdapters(instance, &options, nullptr);
    // assert(count > 0);

    const WGPURequestAdapterOptions options { .backendType = WGPUBackendType_D3D12 }; // !!
    WGPUAdapter adapter = nullptr;
    wgpuInstanceRequestAdapter(
        instance,
        &options,
        [](WGPURequestAdapterStatus status, WGPUAdapter adapter, char const *message, void *userdata) {
            if (status == WGPURequestAdapterStatus_Success) {
                *reinterpret_cast<WGPUAdapter *>(userdata) = adapter;
            }
        },
        /* userdata */ static_cast<void *>(&adapter));
    assert(adapter);
}

@rajveermalviya rajveermalviya changed the title On windows wgpuInstanceRequestAdapter returns nullptr after updating to https://github.com/gfx-rs/wgpu-native/actions/runs/7192422937 wgpuInstanceRequestAdapter fails when called with a specific backend Feb 24, 2024
@rajveermalviya
Copy link
Collaborator

rajveermalviya commented Feb 24, 2024

This is a bug upstream gfx-rs/wgpu#5289

Workaround for now is provide the desired backend flag/s when creating the instance rather than when requesting the adapter.

WGPUInstanceExtras instanceExtras = { 0 };
instanceExtras.chain.sType = (WGPUSType)WGPUSType_InstanceExtras;
instanceExtras.backends = WGPUInstanceBackend_DX12;

WGPUInstanceDescriptor instanceDescriptor = { 0 };
instanceDescriptor.nextInChain = &instanceExtras.chain;

WGPUInstance instance = wgpuCreateInstance(&instanceDescriptor);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants