From 5a1a85885aef33fef121f84e165e9d38bc15214b Mon Sep 17 00:00:00 2001 From: Warwick New Date: Tue, 22 Apr 2025 00:10:36 +0100 Subject: [PATCH] Trying to fix no available video device :( --- flake.lock | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 9 ++++++--- shell.nix | 2 ++ src/main.c | 19 +++++++++++++++++++ 4 files changed, 78 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index 019392c..676acc1 100644 --- a/flake.lock +++ b/flake.lock @@ -1,6 +1,55 @@ { "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixgl": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1713543440, + "narHash": "sha256-lnzZQYG0+EXl/6NkGpyIz+FEOc/DSEG57AP1VsdeNrM=", + "owner": "nix-community", + "repo": "nixGL", + "rev": "310f8e49a149e4c9ea52f1adf70cdc768ec53f8a", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixGL", + "type": "github" + } + }, "nixpkgs": { + "locked": { + "lastModified": 1660551188, + "narHash": "sha256-a1LARMMYQ8DPx1BgoI/UN4bXe12hhZkCNqdxNi6uS0g=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "441dc5d512153039f19ef198e662e4f3dbb9fd65", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { "locked": { "lastModified": 1744463964, "narHash": "sha256-LWqduOgLHCFxiTNYi3Uj5Lgz0SR+Xhw3kr/3Xd0GPTM=", @@ -18,7 +67,8 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "nixgl": "nixgl", + "nixpkgs": "nixpkgs_2" } } }, diff --git a/flake.nix b/flake.nix index eed5e8e..d11b7d6 100644 --- a/flake.nix +++ b/flake.nix @@ -2,13 +2,16 @@ description = "Development Environment"; inputs = { + nixgl.url = "github:nix-community/nixGL"; nixpkgs.url= "github:nixos/nixpkgs/nixos-unstable"; }; - outputs = {self, nixpkgs, ...}: + outputs = {self, nixpkgs, nixgl,...}: let - system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ nixgl.overlay ]; + }; in { devShells.x86_64-linux.default = (import ./shell.nix { inherit pkgs; }); }; diff --git a/shell.nix b/shell.nix index 452856f..8fab0fe 100644 --- a/shell.nix +++ b/shell.nix @@ -8,6 +8,8 @@ pkgs.mkShell cglm sdl3 sdl3-image + nixgl.nixVulkanIntel + vulkan-headers ]; shellHook = '' export PS1="(webgpu) $PS1" diff --git a/src/main.c b/src/main.c index c270fa4..0b80650 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,11 @@ +#include +#include +#include #include #include #include +#include +#include #include static void OnRequestAdapter(WGPURequestAdapterStatus status, @@ -35,6 +40,20 @@ void requestAdapterSync(WGPUInstance instance, } int main() { + SDL_Window *window = NULL; + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + fprintf(stderr, "SDL failed to initialise: %s\n", SDL_GetError()); + return 1; + } + window = SDL_CreateWindow("SDL3 Example", 800, 600, SDL_WINDOW_VULKAN); + if (window == NULL) { + fprintf(stderr, "SDL window failed to initialise: %s\n", SDL_GetError()); + return 1; + } + + const char *driver = SDL_GetCurrentVideoDriver(); + printf("Driver: %s\n", driver); + // We create a descriptor WGPUInstanceDescriptor desc = {}; desc.nextInChain = NULL;