From 5990cb8800d09c6a1357dba370afa829ed808a42 Mon Sep 17 00:00:00 2001 From: elwrcl Date: Fri, 5 Jun 2026 21:59:58 +0300 Subject: [PATCH] ffs --- flake.nix | 13 - .../hardware/graphics/hd4000-custom.patch | 369 ++++++++++++++++++ modules/nixos/hardware/graphics/intel.nix | 67 +++- 3 files changed, 418 insertions(+), 31 deletions(-) create mode 100644 modules/nixos/hardware/graphics/hd4000-custom.patch diff --git a/flake.nix b/flake.nix index f91c15b..bb80337 100755 --- a/flake.nix +++ b/flake.nix @@ -15,10 +15,6 @@ url = "github:0xc000022070/zen-browser-flake"; inputs.nixpkgs.follows = "nixpkgs"; }; - intel-mesa = { - url = "github:elwrcl/intel-hard-graphics"; - inputs.nixpkgs.follows = "nixpkgs"; - }; copetch = { url = "github:elwrcl/copetch"; inputs.nixpkgs.follows = "nixpkgs"; @@ -53,7 +49,6 @@ nix-darwin, home-manager, chaotic, - intel-mesa, ... }: let @@ -71,14 +66,6 @@ home-manager.nixosModules.home-manager chaotic.nixosModules.default { - nixpkgs.overlays = [ - (final: prev: { - mesa = intel-mesa.packages.${linuxSystem}.mesa-custom; - pkgsi686Linux = prev.pkgsi686Linux.overrideScope' (final32: prev32: { - mesa = intel-mesa.packages.${linuxSystem}.mesa-custom-32; - }); - }) - ]; nixpkgs.config.allowUnfree = true; home-manager = { useGlobalPkgs = true; diff --git a/modules/nixos/hardware/graphics/hd4000-custom.patch b/modules/nixos/hardware/graphics/hd4000-custom.patch new file mode 100644 index 0000000..5791b68 --- /dev/null +++ b/modules/nixos/hardware/graphics/hd4000-custom.patch @@ -0,0 +1,369 @@ +diff --git a/meson.options b/meson.options +index 8f3552c..51c97a3 100644 +--- a/meson.options ++++ b/meson.options +@@ -148,7 +148,7 @@ option( + 'gallium-rusticl-enable-drivers', + type : 'array', + value : ['auto'], +- choices : ['auto', 'asahi', 'freedreno', 'radeonsi'], ++ choices : ['auto', 'asahi', 'freedreno', 'radeonsi', 'crocus'], + description : 'List of gallium drivers for which rusticl will be enabled ' + + 'by default', + ) +diff --git a/src/gallium/auxiliary/util/u_threaded_context.c b/src/gallium/auxiliary/util/u_threaded_context.c +index 659a4f7..96aaa5b 100644 +--- a/src/gallium/auxiliary/util/u_threaded_context.c ++++ b/src/gallium/auxiliary/util/u_threaded_context.c +@@ -2366,6 +2366,19 @@ tc_set_global_binding(struct pipe_context *_pipe, unsigned first, + pipe->set_global_binding(pipe, first, count, resources, handles); + } + ++static void ++tc_get_compute_state_info(struct pipe_context *_pipe, void *state, ++ struct pipe_compute_state_object_info *info) ++{ ++ struct threaded_context *tc = threaded_context(_pipe); ++ struct pipe_context *pipe = tc->pipe; ++ ++ /* info is just retrieved, no need to sync if the state object is immutable, ++ * but just in case we sync for compute states. */ ++ tc_sync(tc); ++ pipe->get_compute_state_info(pipe, state, info); ++} ++ + + /******************************************************************** + * views +@@ -5684,6 +5697,7 @@ threaded_context_create(struct pipe_context *pipe, + CTX_INIT(create_video_codec); + CTX_INIT(create_video_buffer); + CTX_INIT(set_global_binding); ++ CTX_INIT(get_compute_state_info); + CTX_INIT(get_sample_position); + CTX_INIT(invalidate_resource); + CTX_INIT(resource_release); +diff --git a/src/gallium/drivers/crocus/crocus_context.c b/src/gallium/drivers/crocus/crocus_context.c +index 46893b3..2d19a4a 100644 +--- a/src/gallium/drivers/crocus/crocus_context.c ++++ b/src/gallium/drivers/crocus/crocus_context.c +@@ -331,13 +331,19 @@ crocus_create_context(struct pipe_screen *pscreen, void *priv, unsigned flags) + if (ice->batch_count > 1) + screen->vtbl.init_compute_context(&ice->batches[CROCUS_BATCH_COMPUTE]); + +- if (!(flags & PIPE_CONTEXT_PREFER_THREADED)) +- return ctx; ++ if (!(flags & PIPE_CONTEXT_PREFER_THREADED)) { ++ fprintf(stderr, "CROCUS unthreaded context: get_compute_state_info=%p, set_global_binding=%p\n", ++ ctx->get_compute_state_info, ctx->set_global_binding); ++ return ctx; ++ } + +- return threaded_context_create(ctx, &screen->transfer_pool, ++ struct pipe_context *tc = threaded_context_create(ctx, &screen->transfer_pool, + crocus_replace_buffer_storage, + NULL, /* TODO: asynchronous flushes? */ + &ice->thrctx); ++ fprintf(stderr, "CROCUS threaded context: get_compute_state_info=%p, set_global_binding=%p\n", ++ tc->get_compute_state_info, tc->set_global_binding); ++ return tc; + } + + bool +diff --git a/src/gallium/drivers/crocus/crocus_context.h b/src/gallium/drivers/crocus/crocus_context.h +index df8f43c..3efc069 100644 +--- a/src/gallium/drivers/crocus/crocus_context.h ++++ b/src/gallium/drivers/crocus/crocus_context.h +@@ -49,6 +49,7 @@ struct blorp_params; + #define CROCUS_MAX_SSBOS 16 + #define CROCUS_MAX_VIEWPORTS 16 + #define CROCUS_MAX_CLIP_PLANES 8 ++#define CROCUS_MAX_GLOBAL_BINDINGS 128 + + enum crocus_param_domain { + ELK_PARAM_DOMAIN_BUILTIN = 0, +@@ -605,6 +606,8 @@ struct crocus_context { + uint32_t last_grid[3]; + /** Reference to the BO containing the compute grid size */ + struct crocus_state_ref grid_size; ++ /** Global bindings for compute */ ++ struct pipe_resource *global_bindings[CROCUS_MAX_GLOBAL_BINDINGS]; + + /** + * Array of aux usages for drawing, altered to account for any +diff --git a/src/gallium/drivers/crocus/crocus_program.c b/src/gallium/drivers/crocus/crocus_program.c +index b6882d9..b17ed02 100644 +--- a/src/gallium/drivers/crocus/crocus_program.c ++++ b/src/gallium/drivers/crocus/crocus_program.c +@@ -3107,15 +3107,29 @@ crocus_bind_cs_state(struct pipe_context *ctx, void *state) + bind_shader_state((void *) ctx, state, MESA_SHADER_COMPUTE); + } + ++static void ++crocus_get_compute_state_info(struct pipe_context *ctx, void *state, ++ struct pipe_compute_state_object_info *info) ++{ ++ struct crocus_screen *screen = (void *) ctx->screen; ++ info->max_threads = screen->devinfo.max_cs_threads * ++ screen->devinfo.subslice_total; ++ info->private_memory = 0; ++ info->preferred_simd_size = 16; ++ info->simd_sizes = 8 | 16; ++} ++ + void + crocus_init_program_functions(struct pipe_context *ctx) + { ++ + ctx->create_vs_state = crocus_create_vs_state; + ctx->create_tcs_state = crocus_create_tcs_state; + ctx->create_tes_state = crocus_create_tes_state; + ctx->create_gs_state = crocus_create_gs_state; + ctx->create_fs_state = crocus_create_fs_state; + ctx->create_compute_state = crocus_create_compute_state; ++ ctx->get_compute_state_info = crocus_get_compute_state_info; + + ctx->delete_vs_state = crocus_delete_vs_state; + ctx->delete_tcs_state = crocus_delete_tcs_state; +diff --git a/src/gallium/drivers/crocus/crocus_screen.c b/src/gallium/drivers/crocus/crocus_screen.c +index 6476727..f336aa7 100644 +--- a/src/gallium/drivers/crocus/crocus_screen.c ++++ b/src/gallium/drivers/crocus/crocus_screen.c +@@ -180,7 +180,7 @@ crocus_init_shader_caps(struct crocus_screen *screen) + caps->integers = true; + caps->max_texture_samplers = + caps->max_sampler_views = +- (devinfo->verx10 >= 75) ? CROCUS_MAX_TEXTURE_SAMPLERS : 16; ++ (devinfo->ver >= 7) ? CROCUS_MAX_TEXTURE_SAMPLERS : 16; + + if (devinfo->ver >= 7 && + (i == MESA_SHADER_FRAGMENT || i == MESA_SHADER_COMPUTE)) +@@ -320,7 +320,7 @@ crocus_init_screen_caps(struct crocus_screen *screen) + caps->alpha_to_coverage_dither_control = devinfo->ver >= 7; + + caps->query_buffer_object = +- caps->robust_buffer_access_behavior = devinfo->verx10 >= 75; ++ caps->robust_buffer_access_behavior = devinfo->ver >= 7; + + caps->cull_distance = + caps->query_pipeline_statistics_single = +@@ -352,8 +352,8 @@ crocus_init_screen_caps(struct crocus_screen *screen) + ELK_MAX_SOL_BINDINGS / CROCUS_MAX_SOL_BUFFERS; + caps->max_stream_output_interleaved_components = ELK_MAX_SOL_BINDINGS; + caps->glsl_feature_level_compatibility = +- caps->glsl_feature_level = devinfo->verx10 >= 75 ? 460 : +- (devinfo->ver >= 7 ? 420 : (devinfo->ver >= 6 ? 330 : 140)); ++ caps->glsl_feature_level = devinfo->ver >= 7 ? 460 : ++ (devinfo->ver >= 6 ? 330 : 140); + caps->clip_planes = devinfo->verx10 < 45 ? 6 : 1; // defaults to MAX (8) + /* 3DSTATE_CONSTANT_XS requires the start of UBOs to be 32B aligned */ + caps->constant_buffer_offset_alignment = 32; +diff --git a/src/gallium/drivers/crocus/crocus_state.c b/src/gallium/drivers/crocus/crocus_state.c +index ca57498..b47d38e 100644 +--- a/src/gallium/drivers/crocus/crocus_state.c ++++ b/src/gallium/drivers/crocus/crocus_state.c +@@ -8282,6 +8282,32 @@ crocus_upload_compute_state(struct crocus_context *ice, + batch->contains_draw = true; + } + ++static void ++crocus_set_global_binding(struct pipe_context *ctx, ++ unsigned start_slot, unsigned count, ++ struct pipe_resource **resources, ++ uint32_t **handles) ++{ ++ struct crocus_context *ice = (struct crocus_context *) ctx; ++ assert(start_slot + count <= CROCUS_MAX_GLOBAL_BINDINGS); ++ for (unsigned i = 0; i < count; i++) { ++ if (resources && resources[i]) { ++ pipe_resource_reference(&ice->state.global_bindings[start_slot + i], ++ resources[i]); ++ struct crocus_resource *res = (struct crocus_resource *) resources[i]; ++ assert(res->base.b.target == PIPE_BUFFER); ++ uint32_t addr = 0; ++ memcpy(&addr, handles[i], sizeof(addr)); ++ addr += res->bo->gtt_offset; ++ memcpy(handles[i], &addr, sizeof(addr)); ++ } else { ++ pipe_resource_reference(&ice->state.global_bindings[start_slot + i], ++ NULL); ++ } ++ } ++ ice->state.stage_dirty |= CROCUS_STAGE_DIRTY_BINDINGS_CS; ++} ++ + #endif /* GFX_VER >= 7 */ + + /** +@@ -9292,6 +9318,9 @@ genX(crocus_init_state)(struct crocus_context *ice) + ctx->resource_release = u_default_resource_release; + ctx->draw_vbo = crocus_draw_vbo; + ctx->launch_grid = crocus_launch_grid; ++#if GFX_VER >= 7 ++ ctx->set_global_binding = crocus_set_global_binding; ++#endif + + ctx->set_frontend_noop = crocus_set_frontend_noop; + +diff --git a/src/gallium/targets/rusticl/meson.build b/src/gallium/targets/rusticl/meson.build +index 2b214ad..84ca2fe 100644 +--- a/src/gallium/targets/rusticl/meson.build ++++ b/src/gallium/targets/rusticl/meson.build +@@ -34,6 +34,7 @@ librusticl = shared_library( + ], + dependencies : [ + driver_asahi, ++ driver_crocus, + driver_freedreno, + driver_iris, + driver_nouveau, +diff --git a/src/intel/vulkan_hasvk/anv_device.c b/src/intel/vulkan_hasvk/anv_device.c +index 9000e9b..b91a1d9 100644 +--- a/src/intel/vulkan_hasvk/anv_device.c ++++ b/src/intel/vulkan_hasvk/anv_device.c +@@ -767,7 +767,11 @@ get_properties_1_2(const struct anv_physical_device *pdevice, + else { + p->conformanceVersion = (VkConformanceVersion) { + .major = 1, +- .minor = pdevice->use_softpin ? 3 : 2, ++#ifdef HASVK_FORCE_VK_1_3 ++ .minor = 3, ++#else ++ .minor = pdevice->use_softpin ? 3 : 2, ++#endif + .subminor = 0, + .patch = 0, + }; +@@ -979,6 +983,8 @@ get_properties(const struct anv_physical_device *pdevice, + *props = (struct vk_properties) { + #if DETECT_OS_ANDROID + .apiVersion = ANV_API_VERSION, ++#elif defined(HASVK_FORCE_VK_1_3) ++ .apiVersion = ANV_API_VERSION_1_3, + #else + .apiVersion = (pdevice->use_softpin || pdevice->instance->report_vk_1_3) ? + ANV_API_VERSION_1_3 : ANV_API_VERSION_1_2, +diff --git a/src/intel/vulkan_hasvk/meson.build b/src/intel/vulkan_hasvk/meson.build +index 2e34cd6..4b292eb 100644 +--- a/src/intel/vulkan_hasvk/meson.build ++++ b/src/intel/vulkan_hasvk/meson.build +@@ -208,6 +208,119 @@ if with_symbols_check + ) + endif + ++# ============================================================================= ++# Experimental Vulkan 1.3 variant for Gen7 (HD 4000) hardware. ++# This builds the same HasVK driver but with -DHASVK_FORCE_VK_1_3=1, ++# which forces the driver to always report Vulkan 1.3 API version and ++# conformance regardless of softpin support. This is experimental and ++# intended for applications that require VK 1.3 to run. ++# ============================================================================= ++ ++icd_file_name_13 = libname_prefix + 'vulkan_intel_hasvk13.' + libname_suffix ++ ++intel_hasvk13_icd = custom_target( ++ 'intel_hasvk13_icd', ++ input : [vk_icd_gen, vk_api_xml], ++ output : 'intel_hasvk13_icd.' + vulkan_manifest_suffix, ++ command : [ ++ prog_python, '@INPUT0@', ++ '--api-version', '1.3', '--xml', '@INPUT1@', ++ '--sizeof-pointer', sizeof_pointer, ++ '--icd-lib-path', vulkan_icd_lib_path, ++ '--icd-filename', icd_file_name_13, ++ '--out', '@OUTPUT@', ++ ], ++ build_by_default : true, ++ install_dir : with_vulkan_icd_dir, ++ install_tag : 'runtime', ++ install : true, ++) ++ ++_dev_icdname_13 = 'intel_hasvk13_devenv_icd.@0@.json'.format(host_machine.cpu()) ++_dev_icd_13 = custom_target( ++ 'intel_hasvk13_devenv_icd', ++ input : [vk_icd_gen, vk_api_xml], ++ output : _dev_icdname_13, ++ command : [ ++ prog_python, '@INPUT0@', ++ '--api-version', '1.3', '--xml', '@INPUT1@', ++ '--sizeof-pointer', sizeof_pointer, ++ '--icd-lib-path', meson.current_build_dir(), ++ '--icd-filename', icd_file_name_13, ++ '--out', '@OUTPUT@', ++ ], ++ build_by_default : true, ++) ++ ++# Build per-hw-ver static libs with VK 1.3 force flag ++libanv_per_hw_ver_libs_13 = [] ++foreach g : [['70', ['gfx7_cmd_buffer.c']], ++ ['75', ['gfx7_cmd_buffer.c']], ++ ['80', ['gfx8_cmd_buffer.c']]] ++ _gfx_ver = g[0] ++ libanv_per_hw_ver_libs_13 += static_library( ++ 'anv_per_hw_ver@0@_vk13'.format(_gfx_ver), ++ [anv_per_hw_ver_files, g[1], anv_hasvk_entrypoints[0]], ++ include_directories : [ ++ inc_include, inc_src, inc_intel, ++ ], ++ c_args : [ ++ no_override_init_args, sse2_args, ++ '-DGFX_VERx10=@0@'.format(_gfx_ver), ++ '-DHASVK_FORCE_VK_1_3=1', ++ ], ++ gnu_symbol_visibility : 'hidden', ++ dependencies : [ ++ dep_libdrm, dep_valgrind, idep_nir_headers, idep_genxml, ++ idep_vulkan_util_headers, idep_vulkan_wsi_headers, ++ idep_vulkan_runtime_headers, idep_intel_driver_ds_headers, ++ idep_intel_blorp_elk, idep_mesautil, ++ ], ++ ) ++endforeach ++ ++# Build common static lib with VK 1.3 force flag ++libanv_hasvk13_common = static_library( ++ 'anv_hasvk13_common', ++ [ ++ libanv_files, anv_hasvk_entrypoints, sha1_h, ++ gen_xml_pack, ++ ], ++ include_directories : [ ++ inc_include, inc_src, inc_intel, ++ inc_util, ++ ], ++ c_args : anv_flags + ['-DHASVK_FORCE_VK_1_3=1'], ++ cpp_args : anv_cpp_flags, ++ gnu_symbol_visibility : 'hidden', ++ dependencies : anv_deps, ++) ++ ++libvulkan_intel_hasvk13 = shared_library( ++ 'vulkan_intel_hasvk13', ++ [files('anv_gem.c'), anv_hasvk_entrypoints[0]], ++ include_directories : [ ++ inc_include, inc_src, inc_intel, ++ ], ++ link_whole : [libanv_hasvk13_common, libanv_per_hw_ver_libs_13], ++ link_with : [ ++ libisl, libintel_perf, ++ ], ++ dependencies : [ ++ dep_thread, dep_dl, dep_m, anv_deps, idep_libintel_common, ++ idep_nir, idep_genxml, idep_vulkan_util, idep_vulkan_wsi, ++ idep_vulkan_runtime, idep_mesautil, idep_xmlconfig, ++ idep_intel_driver_ds, idep_intel_dev, idep_intel_blorp_elk, ++ idep_intel_decoder_elk, idep_intel_compiler_elk, ++ ], ++ c_args : anv_flags + ['-DHASVK_FORCE_VK_1_3=1'], ++ gnu_symbol_visibility : 'hidden', ++ link_args : [vulkan_icd_link_args, ld_args_build_id, ++ ld_args_bsymbolic, ld_args_gc_sections], ++ link_depends : vulkan_icd_link_depends, ++ install : true, ++) ++ + # HasVK and its tests can only run on x86 + if with_tests and host_machine.cpu_family().startswith('x86') + libvulkan_intel_hasvk_test = static_library( diff --git a/modules/nixos/hardware/graphics/intel.nix b/modules/nixos/hardware/graphics/intel.nix index 35367d1..fdcdde3 100755 --- a/modules/nixos/hardware/graphics/intel.nix +++ b/modules/nixos/hardware/graphics/intel.nix @@ -3,33 +3,64 @@ ... }: +let + wayland-intel-vaapi-driver = pkgs.intel-vaapi-driver.overrideAttrs (oldAttrs: { + version = "2.4.4-wayland-fix"; + src = pkgs.fetchFromGitHub { + owner = "irql-notlessorequal"; + repo = "intel-vaapi-driver"; + rev = "929e936ec1f451a5daa12b0c7367687b712b8c2c"; + hash = "sha256-tZ1rZ+4bRxarcFQhP8V2Mfz0sJ5rBgHYLu2ulrQwL+U="; + }; + }); + + wayland-intel-vaapi-driver-32 = pkgs.pkgsi686Linux.intel-vaapi-driver.overrideAttrs (oldAttrs: { + version = "2.4.4-wayland-fix"; + src = pkgs.fetchFromGitHub { + owner = "irql-notlessorequal"; + repo = "intel-vaapi-driver"; + rev = "929e936ec1f451a5daa12b0c7367687b712b8c2c"; + hash = "sha256-tZ1rZ+4bRxarcFQhP8V2Mfz0sJ5rBgHYLu2ulrQwL+U="; + }; + }); + + custom-mesa-drivers = pkgs.mesa.overrideAttrs (oldAttrs: { + patches = (oldAttrs.patches or []) ++ [ + ./hd4000-custom.patch + ]; + mesonFlags = (oldAttrs.mesonFlags or []) ++ [ + "-Dgallium-rusticl=true" + ]; + }); + custom-mesa-drivers-32 = pkgs.pkgsi686Linux.mesa.overrideAttrs (oldAttrs: { + patches = (oldAttrs.patches or []) ++ [ + ./hd4000-custom.patch + ]; + mesonFlags = (oldAttrs.mesonFlags or []) ++ [ + "-Dgallium-rusticl=true" + ]; + }); + +in { hardware.graphics = { + package = custom-mesa-drivers; + package32 = custom-mesa-drivers-32; + extraPackages = [ - (pkgs.intel-vaapi-driver.overrideAttrs (oldAttrs: { - src = pkgs.fetchFromGitHub { - owner = "irql-notlessorequal"; - repo = "intel-vaapi-driver"; - rev = "929e936ec1f451a5daa12b0c7367687b712b8c2c"; - hash = "sha256-tZ1rZ+4bRxarcFQhP8V2Mfz0sJ5rBgHYLu2ulrQwL+U="; - }; - })) + wayland-intel-vaapi-driver pkgs.libvdpau-va-gl ]; extraPackages32 = [ - (pkgs.pkgsi686Linux.intel-vaapi-driver.overrideAttrs (oldAttrs: { - src = pkgs.fetchFromGitHub { - owner = "irql-notlessorequal"; - repo = "intel-vaapi-driver"; - rev = "929e936ec1f451a5daa12b0c7367687b712b8c2c"; - hash = "sha256-tZ1rZ+4bRxarcFQhP8V2Mfz0sJ5rBgHYLu2ulrQwL+U="; - }; - })) + wayland-intel-vaapi-driver-32 pkgs.pkgsi686Linux.libvdpau-va-gl ]; }; services.xserver.videoDrivers = [ "modesetting" ]; - environment.variables.LIBVA_DRIVER_NAME = "i965"; -} \ No newline at end of file + + environment.variables = { + LIBVA_DRIVER_NAME = "i965"; + }; +}