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

skshaderc for MacOS #772

Open
mrstruijk opened this issue Nov 7, 2023 · 10 comments
Open

skshaderc for MacOS #772

mrstruijk opened this issue Nov 7, 2023 · 10 comments
Labels
feature Related to new feature work
Milestone

Comments

@mrstruijk
Copy link

mrstruijk commented Nov 7, 2023

Description

What's happening? What are you expecting? More details are better.
When I'm trying to publish the sk-multi template to the Quest 2 as standalone, it gives the error below.

I'm running the steps as in the StereoKit VSCode guide,
and then run dotnet add package StereoKit.Templates, dotnet new sk-multi --force.

When I dotnet run I get the error below, same as when I'm trying to publish to the Quest.

Platform / Environment

Windows/Linux/Android? Which OpenXR runtime, or is this the flatscreen simulator? What XR device is involved? C# or C++? Are you using StereoKit templates, or are you building SK from scratch? Are your graphics drivers up-to-date? Etc.

I'm working on M1 macOS 14.1, I'm using latest VS Code 1.84.1 (but same issue with Visual Studio 2022).
I've installed dotnet 7.0.483, the android workload, openJDK 17, Android API level 33 via Android Studio, Xamarin via VS.
Stereokit was installed (latest), as was the Templates (latest)

Logs or exception details

/Users/mrstruijk/.nuget/packages/stereokit/0.3.8/build/SKShaders.targets(58,3): error MSB3073: The command ""/Users/mrstruijk/.nuget/packages/stereokit/0.3.8/tools/skshaderc" -d -e -t xge -i "/Users/mrstruijk/.nuget/packages/stereokit/0.3.8/tools/include/" -o "obj/Debug/net7.0/Assets/" "Assets/floor.hlsl"" exited with code 126. [/Users/mrstruijk/Current StereoKit Projects/HelloWorld/HelloWorld.csproj]

The build failed. Fix the build errors and run again.
@maluoi
Copy link
Collaborator

maluoi commented Nov 7, 2023

I unfortunately don't ship a skshaderc build that works on Mac yet! If you remove any .hlsl files from the project (like floor.hlsl), you can get past this. But if you need to add custom shaders, you'll need to build those on Windows or Linux at the moment.

This is on my radar though, I've just been hoping to build this with something like Hermit so I don't have to ship a permutation of binaries. So, slightly more involved than just making a mac friendly build.

@maluoi maluoi changed the title SKShaders / skshaderc exit with code 126 on MacOS skshaderc for MacOS Nov 7, 2023
@maluoi maluoi added the feature Related to new feature work label Nov 7, 2023
@mrstruijk
Copy link
Author

Ah that's good to know, thanks! I couldn't find this in the documentation. So are there any shaders in the project currently that will compile on Mac for Android?

Thanks for the awesome work on this project. I saw a live demo done on the GlobalXR conference and I was so inspired!

@maluoi
Copy link
Collaborator

maluoi commented Nov 8, 2023

The shaders can compile, it's more that I just don't build or ship the mac flavored shader compiler binary for it! The simulator won't run on mac yet, I don't have a mac myself, and haven't met a lot of mac XR developers, so it's been a lower priority for me! Apple finally announcing their Vision Pro has made it a bit more common lately, which is why I'm much more interested in it now. But there's still a good pile of work to make that a good experience.

In theory, you could compile the shaders on Windows or Linux, and just grab the compiled .sks files, load those directly. It would work fine, it would just be a lot less fun to iterate on!

@mrstruijk
Copy link
Author

Thanks for the explanation! However, I'm not fully understanding it yet. So if I want to build to the Quest, and skip the dotnet run section, we're still having the issue of the shaders having to compile for the Mac? Or is it because the compilation is done on the Mac, that skshaderc is unhappy with me?

Aside from this, would you know anything the guy in this tutorial might have done differently? He's happily compiling from your repo directly to the Quest from his Mac. He doesn't seem to take any other additional steps to make it work. He uses the XPlat template from a couple of years ago, but for me that results in the same issue as I have with a current commit.

@rayperkins
Copy link
Contributor

@mrstruijk, my work colleague had the same build issue pop up, it turns out we had a .hlsl file in the project. Since this wasn't used and so just removing the .hlsl file mean the StereoKit build.targets won't attempt to execute the shader compile at build time. The build issue you see is because shader compilation is done on the build machine.
As for the tutorial, if you're mac is a newer ARM64 then that may make a difference if the tutorial used x86.

We've been happily building and debugging a StereoKit app on a Quest 2 from an ARM64 Mac, just without any custom shader hlsl files.

However, if you are using the custom shader then you'd be best to do the work around Nick's mentioned (aka, compile the shader on windows/linux, maybe even a linux docker image would work).

@maluoi
Copy link
Collaborator

maluoi commented Nov 9, 2023

Thanks for the explanation! However, I'm not fully understanding it yet. So if I want to build to the Quest, and skip the dotnet run section, we're still having the issue of the shaders having to compile for the Mac? Or is it because the compilation is done on the Mac, that skshaderc is unhappy with me?

StereoKit's NuGet comes with a tool for compiling .hlsl files into more platform appropriate shader data. Currently this comes in the form of skshaderc.exe, a Windows x64 binary, and skshaderc a Linux x64 binary. When a .hlsl file is detected in the C# project, it'll attempt to compile it using one of these two binaries, and on Mac, that'll fail.

I'm not currently sure why that previous demo would have worked, it's been a while and a lot has changed since then! If x64 Macs can run a Linux x64 executable (plausible for CLI stuff? I have no idea though), that could account for it. It's also possible that automatic shader compilation may have been working a bit differently back then 😅

But yeah, as rayperkins mentioned, removing .hlsl files from your project will get you past this for now. You would need to compile them manually on a different OS, and copy the resulting .sks files, you can load those directly instead.

@mrstruijk
Copy link
Author

You guys are the best, thank you @rayperkins and @maluoi! I'm slowly starting to understand what is happening, and that Is very satisfying. This is why I love these open source communities so much!

Ok final thing for me to wrap my head around: I remove the .hlsl from the project then it should work, fine. But some shader is used, right? This may be because I've been "raised" in Unity, but you gotta have some shader I presume? What is the cube using? Or the hands? And how about if I import any model, and wouldn't need to use any specific shader, is it still going to render?

@maluoi
Copy link
Collaborator

maluoi commented Nov 9, 2023

StereoKit does ship with a number of shaders that are "built-in", pre-compiled on Github Actions and packaged into the StereoKit library as binary data :) You can see a list of those over in this folder. This usually covers the majority of common cases, so you'll only need custom shaders if you need custom rendering or special effects!

You can access the builtin shaders via like Shader.PBR, or Shader.Unlit, but more often I end up just copying or using the default Materials that use those Shaders, like a Material.PBR.Copy() or Material.Unlit.Copy()

But for example, when loading a GLTF, StereoKit will match up the model's materials to an appropriate built-in shader that StereoKit always has. Generally that's the PBR one, but there's a few others GLTFs will sometimes use!

@mrstruijk
Copy link
Author

@maluoi This is excellent! Thank you so much for taking the time to explain it al so clearly!

@maluoi
Copy link
Collaborator

maluoi commented Apr 25, 2024

v0.4 preview builds should be able to compile shaders on Mac now. This isn't robustly tested, but may work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Related to new feature work
Projects
Status: In Review
Development

No branches or pull requests

3 participants