nixpkgs icon indicating copy to clipboard operation
nixpkgs copied to clipboard

darktable: Incomplete photo export in darktable-cli without OpenCL

Open mayjs opened this issue 11 months ago • 12 comments

Nixpkgs version

  • Unstable (25.05)

Describe the bug

Disabling OpenCL when using darktable-cli or running darktable-cli without OpenCL available causes parts of the output images to be missing. The missing part of the image will just contain black pixels, forming a black bar at the bottom of the image. Exporting through the UI is not affected by this bug.

I have found two workarounds so far:

  1. Disabling OpenMP using -DUSE_OPENMP=OFF in package.nix
  2. Switching to the clang stdenv and building darktable with clang

It seems like something related to OpenMP and gcc is different on NixOS compared to other distributions.

Steps to reproduce

  1. Install darktable or create a shell with darktable
  2. Run darktable-cli <IMAGE> export.jpg --core --disable-opencl, replacing <IMAGE> with a path to some image
  3. Check if export.jpg matches the input image, it will have a black bar at the bottom.

Expected behaviour

export.jpg should visually match the input image, no black bar should be present at the bottom

Screenshots

Image

Relevant log output


Additional context

This issue was first raised on the darktable repository: https://github.com/darktable-org/darktable/issues/18127

All affected users so far appear to be using NixOS and running the testsuite on other Linux distributions does not reproduce the error.

System metadata

  • system: "x86_64-linux"
  • host os: Linux 6.14.4, NixOS, 25.05 (Warbler), 25.05.20250429.46e634b
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.28.2
  • channels(root): "nixos"
  • channels(may): "home-manager"
  • nixpkgs: /nix/store/s8b6phy15mzjvx56vjdd1rdd8hr07qw5-source

Notify maintainers

@flosse @mrVanDalo @paperdigits @freyacodes


Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a :+1: reaction to issues you find important.

mayjs avatar May 03 '25 16:05 mayjs

Hi, thanks for the report. Can you try exporting with hq mode enabled as noted in https://github.com/darktable-org/darktable/issues/18127#issuecomment-2848731584

--hq true

Thanks!

On May 3, 2025 9:18:22 AM PDT, mayjs @.***> wrote:

mayjs created an issue (NixOS/nixpkgs#403954)

Nixpkgs version

  • Unstable (25.05)

Describe the bug

Disabling OpenCL when using darktable-cli or running darktable-cli without OpenCL available causes parts of the output images to be missing. The missing part of the image will just contain black pixels, forming a black bar at the bottom of the image. Exporting through the UI is not affected by this bug.

I have found two workarounds so far:

  1. Disabling OpenMP using -DUSE_OPENMP=OFF in package.nix
  2. Switching to the clang stdenv and building darktable with clang

It seems like something related to OpenMP and gcc is different on NixOS compared to other distributions.

Steps to reproduce

  1. Install darktable or create a shell with darktable
  2. Run darktable-cli <IMAGE> export.jpg --core --disable-opencl, replacing <IMAGE> with a path to some image
  3. Check if export.jpg matches the input image, it will have a black bar at the bottom.

Expected behaviour

export.jpg should visually match the input image, no black bar should be present at the bottom

Screenshots

Image

Relevant log output


Additional context

This issue was first raised on the darktable repository: https://github.com/darktable-org/darktable/issues/18127

All affected users so far appear to be using NixOS and running the testsuite on other Linux distributions does not reproduce the error.

System metadata

  • system: "x86_64-linux"
  • host os: Linux 6.14.4, NixOS, 25.05 (Warbler), 25.05.20250429.46e634b
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.28.2
  • channels(root): "nixos"
  • channels(may): "home-manager"
  • nixpkgs: /nix/store/s8b6phy15mzjvx56vjdd1rdd8hr07qw5-source

Notify maintainers

@flosse @mrVanDalo @paperdigits @freyacodes


Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a :+1: reaction to issues you find important.

-- Reply to this email directly or view it on GitHub: https://github.com/NixOS/nixpkgs/issues/403954 You are receiving this because you were mentioned.

Message ID: @.***>

paperdigits avatar May 03 '25 18:05 paperdigits

Hi, thanks for the report. Can you try exporting with hq mode enabled as noted in <darktable-org/darktable#18127 (comment)>

--hq true

Thanks!

Actually, I already ran the test suite as a part of my experiments, the results also show the issue. So HQ mode does not seem to make a difference (I even set it to false for one of my tests).

Let me know if I can assist in any other way! I would love to help resolve this, I just don't know the best approach for further analysis right now.

mayjs avatar May 03 '25 18:05 mayjs

Thanks. This seems like one that's going to be tricky. 🙃

On May 3, 2025 11:42:04 AM PDT, mayjs @.***> wrote:

mayjs left a comment (NixOS/nixpkgs#403954)

Hi, thanks for the report. Can you try exporting with hq mode enabled as noted in <darktable-org/darktable#18127 (comment)>

--hq true

Thanks!

Actually, I already ran the test suite as a part of my experiments, the results also show the issue. So HQ mode does not seem to make a difference (I even set it to false for one of my tests).

Let me know if I can assist in any other way! I would love to help resolve this, I just don't know the best approach for further analysis right now.

-- Reply to this email directly or view it on GitHub: https://github.com/NixOS/nixpkgs/issues/403954#issuecomment-2848753648 You are receiving this because you were mentioned.

Message ID: @.***>

paperdigits avatar May 03 '25 19:05 paperdigits

I don't know if it is relevant, but I've found this issue that talks about discrepancies between nixos's openmp and ubuntu using gcc.

It doesn't have any comment, so I guess it's not very helpful, but that's the only potentially relevant already open issue I could find on the nixos repository...

puyral avatar May 03 '25 19:05 puyral

@paperdigits just a quick update, we have identified the root cause in darktable. Apparently, for darktable-cli on NixOS, OpenMP dynamic thread number adjustment is allowed, resulting in some parallel for loops running in less threads than expected. A PR to fix this by making the code not rely on the number of threads was merged yesterday and I think there is going to be an additional change to ensure that all darktable executables explicitly disable dynamic thread number adjustment.

Whether dynamic thread number adjustment is enabled or disabled by default is up to the implementation, which explains the differences between platforms and also means that all programs that require a fixed amount of threads must disable it explicitly. However, I do wonder why this appears to be enabled by default on NixOS while it's disabled by default on other platforms that are also using GCC. If this is something specific to NixOS, it might also cause failures in other programs.

For reference, this is the comment where I originally found the issue: https://github.com/darktable-org/darktable/issues/18127#issuecomment-2921643856

mayjs avatar May 31 '25 08:05 mayjs

Actually, I just tested it, compiling a simple C program with GCC and OpenMP enabled will NOT enable dynamic thread number adjustment by default, so something else must cause it to be enabled for darktable-cli.

mayjs avatar May 31 '25 08:05 mayjs

Aha, it turns out this is initialized to 1 by OpenCV: https://github.com/darktable-org/darktable/issues/18127#issuecomment-2925210094

I still have no idea why this is different on NixOS though, but I think we can at least close this issues or maybe close this once a new darktable version is released?

mayjs avatar May 31 '25 13:05 mayjs

@mayjs this is an impressive bit of work, thank you so much for digging into it.

I'll close this issue for now, feel free to reopen if needed.

paperdigits avatar Jun 01 '25 22:06 paperdigits

not sure why you closed this issue, i am still getting black bars on cli exports on nixpkgs' darktable v5.0.1.

auroraanna avatar Jun 21 '25 14:06 auroraanna

@auroraanna have you tried the patch from the linked issue above or tried an overlay with the newest release 5.2.0?

paperdigits avatar Jun 21 '25 17:06 paperdigits

no, i did not. point was though that the issue should not be closed as completed because it is still broken in master.

auroraanna avatar Jun 22 '25 21:06 auroraanna

It'll be fixed by https://github.com/NixOS/nixpkgs/pull/418798

paperdigits avatar Jun 22 '25 21:06 paperdigits

https://github.com/NixOS/nixpkgs/pull/418798 has been merged. Closing.

paperdigits avatar Jul 13 '25 20:07 paperdigits