nix-community / kde2nix

Provisional, experimental Plasma 6 (and friends) pre-release packaging [maintainer=@K900]
MIT License
66 stars 6 forks source link

Include VK_hdr_layer? #20

Closed jansol closed 9 months ago

jansol commented 9 months ago

While it's not exactly part of KDE it would be interesting to have VK_hdr_layer (temporarily) packaged alongside plasma6, since AFAIK kwin implements the relevant (temporary/experimental) wayland protocols.

AIUI this layer + kwin6 should allow mpv and other capable vulkan apps to output HDR frames.

(this is mostly for my personal interest in playing around with it ahead of full support in kwin, so no problem if you're not interested in dragging the layer along with the KDE stuff)

jansol commented 9 months ago

Hmm, I guess I misinterpreted some of the commit messages over at the kwin repo. Gamescope running as a wayland client even explicitly prints that the compositor does not support hdr. Guess I'll just look into upstreaming the gamescope update and put this on the backburner again.

jansol commented 9 months ago

Ah, got it to work! It just needs this fork rather than the original, since the original implements the WIP color management wayland protocol and the fork implements the unofficial "frog color management protocol" that the kwin_wayland beta supports for testing.

anthr76 commented 9 months ago

Hey @jansol mind sharing how you got this to work? I'm also interested in testing this as well

jansol commented 9 months ago

I just added a package for it it to my local nixpkgs, basing the derivation on the existing one from vulkan-extension-layer. Then I added that package to my systemPackages and that's it.

anthr76 commented 9 months ago

Thanks for the tip @jansol

I've tried this:

{ lib, stdenv, fetchFromGitHub, cmake, pkg-config, writeText, vulkan-headers, vulkan-utility-libraries,  jq, libX11, libXrandr, libxcb, wayland }:

stdenv.mkDerivation rec {
  pname = "vulkan-hdr-layer";
  version = "63d2eec";

  src = fetchFromGitHub {
    owner = "Drakulix";
    repo = "VK_hdr_layer";
    rev = "63d2eeccb962824c90e158a06900ae1abec9c49e";
    fetchSubmodules = true;
    hash = "sha256-rSKPTeTDOz6IeJGRt9aIu1VH8VfVzXNYZfjdiSXEJxg=";
  };

  nativeBuildInputs = [ cmake pkg-config jq ];

  buildInputs = [ vulkan-headers vulkan-utility-libraries libX11 libXrandr libxcb wayland ];

  # Help vulkan-loader find the validation layers
  setupHook = writeText "setup-hook" ''
    addToSearchPath XDG_DATA_DIRS @out@/share
  '';

  # Tests are not for gpu-less and headless environments
  cmakeFlags = [
    "-DBUILD_TESTS=false"
  ];

  # Include absolute paths to layer libraries in their associated
  # layer definition json files.
  preFixup = ''
    for f in "$out"/share/vulkan/explicit_layer.d/*.json "$out"/share/vulkan/implicit_layer.d/*.json; do
      jq <"$f" >tmp.json ".layer.library_path = \"$out/lib/\" + .layer.library_path"
      mv tmp.json "$f"
    done
  '';

  meta = with lib; {
    description = "Layers providing Vulkan HDR";
    homepage = "https://github.com/Drakulix/VK_hdr_layer";
    platforms = platforms.linux;
    license = licenses.mit;
  };
}

But I'm not seeing the JSON VkLayer_hdr_wsi.json in ls /run/current-system/sw/share/vulkan/explicit_layer.d/ or in the derivation which is making me suspect I did something wrong. I'm trying to run moonlight with HDR

anthr76 commented 9 months ago

It turns out I was caching vulkan-extension-layer because I forgot to update the hash.. Oops :) this actually show's what's expected.. Let's see if it works.

{ lib, stdenv, fetchFromGitHub, meson, pkg-config, vulkan-loader, ninja, writeText, vulkan-headers, vulkan-utility-libraries,  jq, libX11, libXrandr, libxcb, wayland }:

stdenv.mkDerivation rec {
  pname = "vulkan-hdr-layer";
  version = "63d2eec";

  src = (fetchFromGitHub {
    owner = "Drakulix";
    repo = "VK_hdr_layer";
    rev = "63d2eeccb962824c90e158a06900ae1abec9c49e";
    fetchSubmodules = true;
    hash = "sha256-IwHrMTiOzITMsGMZN/AuUN3PF/oMhENw9d7kX2VnDGM=";
  }).overrideAttrs (_: {
    GIT_CONFIG_COUNT = 1;
    GIT_CONFIG_KEY_0 = "url.https://github.com/.insteadOf";
    GIT_CONFIG_VALUE_0 = "git@github.com:";
  });

  nativeBuildInputs = [ vulkan-headers meson ninja pkg-config jq ];

  buildInputs = [ vulkan-headers vulkan-loader vulkan-utility-libraries libX11 libXrandr libxcb wayland ];

  # Help vulkan-loader find the validation layers
  setupHook = writeText "setup-hook" ''
    addToSearchPath XDG_DATA_DIRS @out@/share
  '';

  meta = with lib; {
    description = "Layers providing Vulkan HDR";
    homepage = "https://github.com/Drakulix/VK_hdr_layer";
    platforms = platforms.linux;
    license = licenses.mit;
  };
}
bglebrun commented 8 months ago

From what I recall you need to use Zamundaaa's branch here. This is the derivation that eventually got me up and running for HDR in Quake II RTX.

For my own curiosity I also tested on Cyberpunk 2077 and EA Sports WRC to no luck, as expected outside of a gamescope session. MPV is working brilliantly ENABLE_HDR_WSI=1 mpv --vo=gpu-next --target-colorspace-hint --gpu-api=vulkan --gpu-context=waylandvk ./video

{ lib, stdenv, fetchFromGitHub, meson, pkg-config, vulkan-loader, ninja, writeText, vulkan-headers, vulkan-utility-libraries,  jq, libX11, libXrandr, libxcb, wayland }:

stdenv.mkDerivation rec {
  pname = "vulkan-hdr-layer";
  version = "63d2eec";

  src = (fetchFromGitHub {
    owner = "Zamundaaa";
    repo = "VK_hdr_layer";
    rev = "869199cd2746e7f69cf19955153080842b6dacfc";
    fetchSubmodules = true;
    hash = "sha256-xfVYI+Aajmnf3BTaY2Ysg5fyDO6SwDFGyU0L+F+E3is=";
  }).overrideAttrs (_: {
    GIT_CONFIG_COUNT = 1;
    GIT_CONFIG_KEY_0 = "url.https://github.com/.insteadOf";
    GIT_CONFIG_VALUE_0 = "git@github.com:";
  });

  nativeBuildInputs = [ vulkan-headers meson ninja pkg-config jq ];

  buildInputs = [ vulkan-headers vulkan-loader vulkan-utility-libraries libX11 libXrandr libxcb wayland ];

  # Help vulkan-loader find the validation layers
  setupHook = writeText "setup-hook" ''
    addToSearchPath XDG_DATA_DIRS @out@/share
  '';

  meta = with lib; {
    description = "Layers providing Vulkan HDR";
    homepage = "https://github.com/Zamundaaa/VK_hdr_layer";
    platforms = platforms.linux;
    license = licenses.mit;
  };
}
anthr76 commented 8 months ago

Awesome to hear! I'm also having bad-luck with Moonlight*. I haven't tried mpv yet.

jansol commented 8 months ago

Switched from using a modified nixpkgs to just defining the package inline in my home-manager user packages list. Makes it much easier to track upstream nixos-unstable.

bglebrun commented 8 months ago

Good idea, I also have it imported in an external module. Makes it easier when this and KDE 6 eventually get releases and the cleanup needs to happen.