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

Add support for Mac OS #87

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft

Conversation

LucaZulberti
Copy link

@LucaZulberti LucaZulberti commented Sep 8, 2023

Dear all, I appreciate your work here and would like to try porting vkDT to Mac OS.

I'm not an experienced Mac OS developer; I want to give it a try to use the software on my MacBook.

My setup:

  • MacBook Pro M1
  • macOS Ventura 13.5 Sequoia 15.0

Dependency (to improve the list):

  • Install the MoltenVK SDK for vulkan by LunarG: Lunar VulkanSDK.
  • Install any missing package with brew.
  • Using brew, install llvm and libomp for custom compilation of the rawspeed library.

ToDo:

  • Update dependency with upstream versions
    • rawspeed: add controls for Apple target in 4894513
    • imgui: cherry-picked modifications from @hanatos fork to upstream in c57af75
    • glfw: use submodule to compile it with ImGui
    • Add preliminary checks for Apple target in Makefiles and source code
    • Customise compilation for the rawspeed library
    • [x ] Try to understand why it is not working
    • Update ImGui/GLFW code with the upstream version
    • Check modifications on other platforms
      • Ubuntu 22.4
      • others?

Up to now, the commits are just a fast try to make it work.
I know there is a lot of rubbish from many points of view of programmers 😄

Thank you again for this software!

@LucaZulberti LucaZulberti marked this pull request as draft September 8, 2023 19:10
@LucaZulberti LucaZulberti changed the title WIP: Add support for Mac OS Add support for Mac OS Sep 8, 2023
@hanatos
Copy link
Owner

hanatos commented Sep 10, 2023

heya,

nice, thanks for jumping onto this. as a general comment, the code with these patches applied will probably not run on my machine any more (or on macintosh with intel cpu?). also i want to limit platform specific code to very few places to make our life easier in the future. let me leave a few comments interleaved in the patch.

ext/Makefile Outdated Show resolved Hide resolved
src/Makefile Outdated Show resolved Hide resolved
src/db/db.c Outdated
@@ -454,7 +478,7 @@ int dt_db_read(dt_db_t *db, const char *filename)
lno++;

// scan filename:rating|labels:number
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, macintosh thinks 32-bit are long? then probably better to use %"PRIu64" here so it will work on all platforms.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just followed compiler warnings, I will see what is going on here, in case ok to switch to PRIu64

src/db/db.h Outdated
@@ -4,6 +4,12 @@
#include <string.h>
#include <strings.h>

#ifndef __APPLE__
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this argument swap issue is terrifying. there has got to be a better way (not involving the ifdef around all compare functions above).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I know, I want just to reach a working/compiling solution and then beutify. 😄

src/db/thumbnails.c Outdated Show resolved Hide resolved
snprintf(cfgfilename, sizeof(cfgfilename), "%s", filename);
snprintf(deffilename, sizeof(deffilename), "default.%"PRItkn, dt_token_str(input_module));
struct stat statbuf = {0};
time_t tcfg = 0, tbc1 = 0;

if(!stat(cfgfilename, &statbuf))
#ifndef __APPLE__
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay we probably want to factor this out in something like time_t t = dt_stat(filename) defined in core.h or similar, so the platform specific code is only in one place.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will do something like that to put together all plat-spec code. Thank you for the tip 😉

@@ -314,7 +314,11 @@ void modify_roi_out(
mod->img_param.whitebalance[3] /= mod->img_param.whitebalance[1];
mod->img_param.whitebalance[1] = 1.0f;

#ifndef __APPLE__
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really that doesn't exist? then maybe another wrapper in core.h like dt_isnan

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes... Too many things are not in Macos... Painful work..

@hanatos
Copy link
Owner

hanatos commented Sep 10, 2023

.. about rawspeed. does the vanilla rawspeed git build on M1? i would be surprised if not. anyways it's probably better to use upstream rawspeed for changes.

about the blank screen. did you run vkdt -d all and does it give any useful hints? maybe it fails to detect paths to dsos for dynamic loading?

@LucaZulberti
Copy link
Author

LucaZulberti commented Sep 10, 2023

Here I am!

If you appreciate it, I'm working to make it compile with CMake, which does more platform-specific controls.
Next, I wanted to play with ImGUI to build the GUI and integrate it in Ansel in the long (very long?) run.

I also updated ImGUI dependency (I cherry-picked your modifications) to check for the blank screen problem.
As before, I'm going to investigate more and then make the changes more solid.

Thank you for your feedback!

@LucaZulberti
Copy link
Author

With the new imgui this is the error:

$ mkdir build
$ cd build
$ cmake .. && Make
$ cd ../bin
$ cp ../build/vkdt* ../build/libvkdt.* ./
$ ln -s ../build/modules ./
$ ./vkdt-gui -d err -d all -D perf ~/Pictures/Temp/ProvaDT/AND_092.dng 
[gui] glfwGetVersionString() : 3.3.8 Cocoa NSGL EGL OSMesa
[gui] monitor [0] DELL U2721DE at 0 0
[gui] vk extension required by GLFW:
[gui]   VK_KHR_surface
[gui]   VK_EXT_metal_surface
[qvk] dev 0: vendorid 0x106b
[qvk] dev 0: Apple M1
[qvk] max number of allocations 1073741824
[qvk] max image allocation size 16384 x 16384
[qvk] max uniform buffer range 4294967295
[qvk] num queue families: 4
[qvk] picked device 0 without ray tracing and without float atomics support
[qvk] available surface formats:
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] colour space: 0
[gui] no joysticks found
[gui] no display profile file display.DELL U2721DE, using sRGB!
[gui] no display profile file display.DELL U2721DE, using sRGB!
[qvk] available surface formats:
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] B8G8R8A8_UNORM
[qvk] B8G8R8A8_SRGB
[qvk] R16G16B16A16_SFLOAT
[qvk] A2B10G10R10_UNORM_PACK32
[qvk] A2R10G10B10_UNORM_PACK32
[qvk] colour space: 0
Assertion failed: (font_cfg->SizePixels > 0.0f), function AddFont, file imgui_draw.cpp, line 2131.
an error occurred while trying to execute gdb.please check if gdb is installed on your system.
backtrace written to /tmp/vkdt-bt-95883.txt
recovery data written to /tmp/vkdt-crash-recovery.*

Apparently, it cannot set the WindowSize properly... I saw you modified imgui backends for that.
In my plans I would like to use ImGui:: instead of lower level functions from glfw. It will be a longer process, but I think it could help in having something portable in the long run.

@LucaZulberti
Copy link
Author

Updates on error state.

I set the font size to 16.0 with a literal to go on.

Now blocked at:

$ ./vkdt-gui -d err -d all -D qvk -D perf ~/Pictures/Temp/ProvaDT/AND_092.dng
[gui] glfwGetVersionString() : 3.3.8 Cocoa NSGL EGL OSMesa
[gui] monitor [0] DELL U2721DE at 0 0
[gui] vk extension required by GLFW:
[gui]   VK_KHR_surface
[gui]   VK_EXT_metal_surface
[gui] no joysticks found
[gui] no display profile file display.DELL U2721DE, using sRGB!
[gui] no display profile file display.DELL U2721DE, using sRGB!
[db] allocating 1024.0 MB for thumbnails
[i-bc1] (null): can't open file!
[i-bc1] (null): wrong magic number or version!
[i-bc1] (null): can't open file!
[i-bc1] (null): wrong magic number or version!
[ERR] [thm] failed to run first half of graph!
[ERR] could not load required thumbnail symbols!
[ERR] image could not be loaded!

I think this is related to how the dynamic libraries of the modules are compiled.
I will check compilation flags and other differences with Linux .so files.

@hanatos
Copy link
Owner

hanatos commented Sep 10, 2023

okay is that error any different to the older imgui at all?

not sure i understand how you would put imgui into a gtk3/cairo application. as additional dependency?

maybe a saner approach is to use libvkdt.so in an external application, if you want to backport the processing to legacy gui library stacks? or do you want to rewrite ansel in imgui?

about dynamic libraries. i saw you link -lvkdt in the makefile. why? normally the library is not even built.

there may also be an issue about setting file paths to discover additional data/config files/dsos.

i'm highly unlikely to merge cmake build system patches. cmake doesn't do anything for me (it generates makefiles, i have makefiles already), i'm unconvinced it does much for platform independence except mostly a big if around stuff. all variables related to local build environments should go in config.mk and config.mk.defaults instead.

re:imgui vs glfw functions: some code is c, some is c++ (as minimal as possible, only gui related and interfacing with rawspeed/exiv2). glfw is c, so there are some constraints as to when you can swap things around.

@LucaZulberti
Copy link
Author

okay is that error any different to the older imgui at all?

I'm going to investigate the cause in the following days.

not sure i understand how you would put imgui into a gtk3/cairo application. as additional dependency?
maybe a saner approach is to use libvkdt.so in an external application, if you want to backport the processing to legacy gui library stacks? or do you want to rewrite ansel in imgui?

I would like essential ImGui components to control the processing on a single image, then extend for library management like in Ansel. Yes, I would like to get rid of GTK. For sure I will link with libvkdt to keep QVK stuff as it is.

about dynamic libraries. i saw you link -lvkdt in the makefile. why? normally the library is not even built.

Bad patch due to ramp up on the compilation flow of the project; I will force push the next days.

there may also be an issue about setting file paths to discover additional data/config files/dsos.

Thank you for the hint, I will investigate also this.

i'm highly unlikely to merge cmake build system patches. cmake doesn't do anything for me (it generates makefiles, i have makefiles already), i'm unconvinced it does much for platform independence except mostly a big if around stuff. all variables related to local build environments should go in config.mk and config.mk.defaults instead.

I will keep it separated. I found it more convenient than hand-written Makefiles for the long-term, but it could be optional for this work. For example, in shared libraries, it automatically handles all the different flags for other OSes.
I will continue to modify the Makefile-based compilation flow too.

re:imgui vs glfw functions: some code is c, some is c++ (as minimal as possible, only gui related and interfacing with rawspeed/exiv2). glfw is c, so there are some constraints as to when you can swap things around.

Here, I need more experience in ImGui development to be helpful. I noticed the patch about setDisplayProfile() that I assume is very important for the workflow. This should be considered in any GUI-based application using the libvkdt, right?
I will postpone these long-term decisions until I can run this tool on macOS.

@LucaZulberti
Copy link
Author

Updated with only Makefile modifications.
Cleaned ext compilation with brew llvm.
Fixed some flat.mk in src/pipe/modules; @hanatos can you check these? I need those dependencies with .o files.

Now the error is:

$ ./vkdt -d err -d all -D qvk -D perf ~/Pictures/Temp/ProvaDT/AND_092.dng
[gui] glfwGetVersionString() : 3.3.8 Cocoa NSGL EGL OSMesa dynamic
[gui] monitor [0] DELL U2721DE at 0 0
[gui] vk extension required by GLFW:
[gui]   VK_KHR_surface
[gui]   VK_EXT_metal_surface
[gui] no joysticks found
[gui] no display profile file display.DELL U2721DE, using sRGB!
[gui] no display profile file display.DELL U2721DE, using sRGB!
[db] allocating 1024.0 MB for thumbnails
[ERR] [thm] failed to run first half of graph!
[ERR] could not load required thumbnail symbols!
[ERR] image could not be loaded!

Same error with updated ImGui (HEAD) and old version (HEAD~2).

@hanatos
Copy link
Owner

hanatos commented Sep 10, 2023

looks like you're lacking -rdynamic or the equivalent?

@LucaZulberti
Copy link
Author

Now Makefiles are more clean.

Next error:

$ ./vkdt -d err -d all -D qvk -D perf ~/Pictures/Temp/ProvaDT/AND_092.dng
[gui] glfwGetVersionString() : 3.3.8 Cocoa NSGL EGL OSMesa dynamic
[gui] monitor [0] DELL U2721DE at 0 0
[gui] vk extension required by GLFW:
[gui]   VK_KHR_surface
[gui]   VK_EXT_metal_surface
[gui] no joysticks found
[gui] no display profile file display.DELL U2721DE, using sRGB!
[gui] no display profile file display.DELL U2721DE, using sRGB!
[db] allocating 1024.0 MB for thumbnails
[mem] images : peak rss 0.00012207 MB vmsize 0.00012207 MB
[mem] buffers: peak rss 0 MB vmsize 0 MB
[mem] staging: peak rss 0.000244141 MB vmsize 0.000244141 MB
[mem] images : peak rss 0.00012207 MB vmsize 0.00012207 MB
[mem] buffers: peak rss 0 MB vmsize 0 MB
[mem] staging: peak rss 0.000244141 MB vmsize 0.000244141 MB
[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Shader library compile failed (Error code 3):
program_source:104:14: error: expected unqualified-id
float kernel(thread const float3& ci, thread const float3& p)
             ^
program_source:104:14: error: expected ')'
program_source:104:13: note: to match this '('
float kernel(thread const float3& ci, thread const float3& p)
            ^
program_source:285:42: error: expected expression
            co += (params.rbf_c[i].xyz * kernel(param_8, param_9));
                                         ^
.
[mvk-error] VK_ERROR_INVALID_SHADER_NV: Compute shader function could not be compiled into pipeline. See previous logged error.
[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Shader library compile failed (Error code 3):
program_source:104:14: error: expected unqualified-id
float kernel(thread const float3& ci, thread const float3& p)
             ^
program_source:104:14: error: expected ')'
program_source:104:13: note: to match this '('
float kernel(thread const float3& ci, thread const float3& p)
            ^
program_source:285:42: error: expected expression
            co += (params.rbf_c[i].xyz * kernel(param_8, param_9));
                                         ^
.
[mvk-error] VK_ERROR_INVALID_SHADER_NV: Compute shader function could not be compiled into pipeline. See previous logged error.
[db] [thm] running the thumbnail graph failed on image '/Users/luca/Pictures/Temp/ProvaDT/AND_092.dng.cfg'!

Same error for old and new ImGui+GLFW. Maybe is related to MoltenVK implementation of Vulkan on macOS?

@hanatos
Copy link
Owner

hanatos commented Jan 22, 2024

.. just wanted to ask whether the situation here changed with all the windows/compatibility patches lately? in particular some strange things wrt. -rdynamic and search paths (-d all reports them on the console output now) seem like they would be really similar problems.

@hanatos
Copy link
Owner

hanatos commented Jan 22, 2024

..maybe to add to the -rdynamic discussion. it seems the bs.h style of api opening should work on linux too if we pass 0 as filename to dlopen() to open the main executable. maybe this would even be portable code then (assuming we'll replace the windows stuff through the dlfcn package and dlopen/dlsym as well, the package is there for module loading anyways).

@LucaZulberti
Copy link
Author

Hi @hanatos, I still need to rebase the changes. I spent more time processing photos with Ansel, which now builds ok on M1. I will try to update the PR in few days ;-)

@LucaZulberti
Copy link
Author

Fast update. I needed to keep a few commits to compiling successfully. Anyway, it is still on a blank screen. I need to investigate more.

$ MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=1 bin/vkdt -d err -d all -D qvk -D perf ~/Pictures/Temp/ProvaDT/Zulberti.jpg
[pipe] base directory /Users/luca/Git/vkdt/bin
[pipe] home directory /Users/luca/.config/vkdt
[pipe] loaded 76 modules
[gui] glfwGetVersionString() : 3.3.9 Cocoa NSGL EGL OSMesa dynamic
[gui] monitor [0] Built-in Retina Display at 0 0
[gui] vk extension required by GLFW:
[gui]   VK_KHR_surface
[gui]   VK_EXT_metal_surface
[gui] no joysticks found
[gui] no display profile file display.Built-in Retina Display, using sRGB!
[gui] no display profile file display.Built-in Retina Display, using sRGB!
[db] allocating 1024.0 MB for thumbnails
[mem] images : peak rss 0.00012207 MB vmsize 0.00012207 MB
[mem] buffers: peak rss 0 MB vmsize 0 MB
[mem] staging: peak rss 0.000244141 MB vmsize 0.000244141 MB
[mem] images : peak rss 0.0498505 MB vmsize 0.0498505 MB
[mem] buffers: peak rss 0 MB vmsize 0 MB
[mem] staging: peak rss 0.0997009 MB vmsize 0.0997009 MB
[mem] images : peak rss 144.496 MB vmsize 144.496 MB
[mem] buffers: peak rss 0 MB vmsize 0 MB
[mem] staging: peak rss 91.027 MB vmsize 91.027 MB
[mem] images : peak rss 30.5359 MB vmsize 30.5359 MB
[mem] buffers: peak rss 0 MB vmsize 0 MB
[mem] staging: peak rss 29.3213 MB vmsize 29.3213 MB
[mem] images : peak rss 0.0498505 MB vmsize 0.0498505 MB
[mem] buffers: peak rss 0 MB vmsize 0 MB
[mem] staging: peak rss 0.0997009 MB vmsize 0.0997009 MB
[mem] images : peak rss 144.496 MB vmsize 144.496 MB
[mem] buffers: peak rss 0 MB vmsize 0 MB
[mem] staging: peak rss 91.027 MB vmsize 91.027 MB
[mem] images : peak rss 30.5359 MB vmsize 30.5359 MB
[mem] buffers: peak rss 0 MB vmsize 0 MB
[mem] staging: peak rss 29.3213 MB vmsize 29.3213 MB

@hanatos
Copy link
Owner

hanatos commented Jan 24, 2024 via email

@DorianRudolph
Copy link

DorianRudolph commented Feb 17, 2024

I also tried to compile this and I also get a blank window. However, the program crashes if I try to open a raw image.

MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=1 bin/vkdt -d err -d all -D qvk -D perf RAW_CANON_5D_ARGB.CR2

The debug build then crashes at the call of qvkDebugMarkerSetObjectNameEXT(qvk.device, &name_info); in dt_graph_create_shader_module from alloc_outputs.
The crash is then EXC_BAD_ACCESS in MVKVulkanAPIObject::setDebugName.

The release build crashes with the following error:

[mvk-error] VK_ERROR_OUT_OF_DEVICE_MEMORY: MTLCommandBuffer "vkQueueSubmit MTLCommandBuffer on Queue 0-0" execution failed (code 3): Caused GPU Address Fault Error (0000000b:kIOGPUCommandBufferCallbackErrorPageFault)

Addendum: When debugging, LLDB also pauses at an exception in vkResetFences called from dt_graph_run.

I had to apply the following patch to compile with rawspeed.

diff --git a/src/pipe/modules/i-raw/flat.mk b/src/pipe/modules/i-raw/flat.mk
index 0a90e242..fbce5052 100644
--- a/src/pipe/modules/i-raw/flat.mk
+++ b/src/pipe/modules/i-raw/flat.mk
@@ -5,12 +5,13 @@ RAWSPEED_L=pipe/modules/i-raw/rawspeed/build
 MOD_CFLAGS=-std=c++20 -Wall -I$(RAWSPEED_I)/src/librawspeed/ -I$(RAWSPEED_L)/src/ -I$(RAWSPEED_I)/src/external/ $(VKDT_PUGIXML_CFLAGS) $(VKDT_JPEG_CFLAGS)
 MOD_LDFLAGS=-L$(RAWSPEED_L) -lrawspeed -lz $(VKDT_PUGIXML_LDFLAGS) $(VKDT_JPEG_LDFLAGS)

-pipe/modules/i-raw/libi-raw.so: $(RAWSPEED_L)/librawspeed.a
+pipe/modules/i-raw/libi-raw.$(SEXT): $(RAWSPEED_L)/librawspeed.a

-ifeq ($(CXX),clang++)
+CXX_NAME=$(notdir $(CXX))
+ifeq ($(CXX_NAME),clang++)
 MOD_LDFLAGS+=-fopenmp=libomp
 endif
-ifeq ($(CXX),g++)
+ifeq ($(CXX_NAME),g++)
 MOD_LDFLAGS+=-lgomp
 endif

@@ -43,7 +44,7 @@ endif # end rawspeed
 ifeq ($(VKDT_USE_RAWINPUT),2)
 MOD_LDFLAGS=pipe/modules/i-raw/rawloader-c/target/release/librawloader.a
 MOD_CFLAGS=-Ipipe/modules/i-raw/rawloader-c
-pipe/modules/i-raw/libi-raw.so: pipe/modules/i-raw/rawloader-c/target/release/librawloader.a
+pipe/modules/i-raw/libi-raw.$(SEXT): pipe/modules/i-raw/rawloader-c/target/release/librawloader.a

 pipe/modules/i-raw/rawloader-c/target/release/librawloader.a: pipe/modules/i-raw/rawloader-c/lib.rs pipe/modules/i-raw/rawloader-c/Cargo.toml
 	cd pipe/modules/i-raw/rawloader-c; cargo update; cargo build --release

I hope this helps.

@DorianRudolph
Copy link

Another finding: If I remove the DEBUG_MARKERS, then the program also runs, and I do get many validation errors. The first is:

[qvk] validation layer: Validation Error: [ VUID-VkPipelineLayoutCreateInfo-descriptorType-03020 ] | MessageID = 0xd67a4ef5 | vkCreatePipelineLayout():  max per-stage storage image bindings count (11) exceeds device maxPerStageDescriptorStorageImages limit (8). The Vulkan spec states: The total number of descriptors in descriptor set layouts created without the VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT bit set with a descriptorType of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, and VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER accessible to any given shader stage across all elements of pSetLayouts must be less than or equal to VkPhysicalDeviceLimits::maxPerStageDescriptorStorageImages (https://vulkan.lunarg.com/doc/view/1.3.275.0/mac/1.3-extensions/vkspec.html#VUID-VkPipelineLayoutCreateInfo-descriptorType-03020)

@hanatos
Copy link
Owner

hanatos commented Sep 28, 2024

turns out on macos the internal framebuffer was running at 1x1 pixel resolution. 84a01f4 fixes this. i can run/use vkdt on an older intel macbook air (using LOD=3). it's not fun but kinda works.

i'm not sure this gpu already supports enough metal tier 2 or 3 or whatever to use MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS at all or whether the use of the variable changed. i still get the warning about descriptor set limits, though the llap module appears to be doing at least something anyways.

@hanatos
Copy link
Owner

hanatos commented Sep 28, 2024

btw, short list of steps to compile on macos, for the curious:

install brew
brew install make pkg-config glfw3 vulkan-validationlayers vulkan-headers rust molten-vk
export PATH="/usr/local/opt/make/libexec/gnubin:$PATH"
export PKG_CONFIG_PATH=$(find /usr/local/Cellar -name 'pkgconfig' -type d | grep lib/pkgconfig | tr '\n' ':' | sed s/.$//)
# and arm macs have it in /opt/homebrew/Cellar
# arm macs might have a problem with the simd in the mcraw decoder. also for mcraw:
brew install cmake

and then it kinda just worked with

make -j20
MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=1 ./vkdt

@LucaZulberti
Copy link
Author

LucaZulberti commented Sep 28, 2024

Hi @hanatos, I saw the update and rebased the PR quickly (poor checks). I also implemented fix from @DorianRudolph, thanks!
Anyway, I see the interface now! I can process JPEG, but not raw with Rawler, and rawspeed fails compilation due to a format specifier in printf (%d instead of %u)...
I will try again in a few days maybe. Anyway, I hope this update can help the others.

Error when Rawler is enabled (it seems related to SPIR-V compilation):

[gui] vkdt 0.8.99-204-g8ca5daca (c) 2020--2024 johannes hanika
[gui] glfwGetVersionString() : 3.4.0 Cocoa NSGL Null EGL OSMesa monotonic dynamic
[gui] monitor [0] Built-in Retina Display at 0 0
[gui] vk extension required by GLFW:
[gui]   VK_KHR_surface
[gui]   VK_EXT_metal_surface
[gui] no joysticks found
[gui] no display profile file display.Built-in Retina Display, using sRGB!
[mvk-error] SPIR-V to MSL conversion error: Argument buffer resource base type could not be determined. When padding argument buffer elements, all descriptor set resources must be supplied with a base type by the app.
[mvk-error] VK_ERROR_INVALID_SHADER_NV: Compute shader function could not be compiled into pipeline. See previous logged error.
2024-09-28 18:56:20.540 vkdt[23090:3162243] +[IMKClient subclass]: chose IMKClient_Legacy
2024-09-28 18:56:20.540 vkdt[23090:3162243] +[IMKInputSession subclass]: chose IMKInputSession_Legacy
[mvk-error] SPIR-V to MSL conversion error: Argument buffer resource base type could not be determined. When padding argument buffer elements, all descriptor set resources must be supplied with a base type by the app.
[mvk-error] VK_ERROR_INVALID_SHADER_NV: Compute shader function could not be compiled into pipeline. See previous logged error.

@LucaZulberti
Copy link
Author

btw, short list of steps to compile on macos, for the curious:

install brew
brew install make pkg-config glfw3 vulkan-validationlayers vulkan-headers rust molten-vk
export PATH="/usr/local/opt/make/libexec/gnubin:$PATH"
export PKG_CONFIG_PATH=$(find /usr/local/Cellar -name 'pkgconfig' -type d | grep lib/pkgconfig | tr '\n' ':' | sed s/.$//)
# and arm macs have it in /opt/homebrew/Cellar
# arm macs might have a problem with the simd in the mcraw decoder. also for mcraw:
brew install cmake

and then it kinda just worked with

make -j20
MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=1 ./vkdt

I still need to use Lunar SDK on my M1 Mac OS Sequoia. Brew-provided MVK seems to have different library names and I did not have the will to investigate and solve dynamic linking problems.

@hanatos
Copy link
Owner

hanatos commented Sep 28, 2024

[mvk-error] SPIR-V to MSL conversion error: Argument buffer resource base type could not be determined. When padding argument buffer elements, all descriptor set resources must be supplied with a base type by the app.
[mvk-error] VK_ERROR_INVALID_SHADER_NV: Compute shader function could not be compiled into pipeline. See previous logged error.

KhronosGroup/MoltenVK#2271

hmm certainly rawler does not use spir-v, so the error above will resurface if you use rawspeed just the same. this might appear in any module/node of the raw processing pipeline (that is not in use with jpg), so it's hard to tell where exactly things are going wrong. using arrays of descriptors as a scalar descriptor does ring a bell but i don't know where in vkdt's code this might be the case here.

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

Successfully merging this pull request may close these issues.

4 participants