Skip to content

Conversation

@squidbus
Copy link
Contributor

Translates DebugPrintf to os_log_default.log, provided in MSL 3.2.

I don't think this is needed for MoltenVK as the Vulkan Validation Layer is responsible for instrumenting debug prints into buffer writes, but may be useful for users translating SPIR-V for use with Metal directly.

@squidbus
Copy link
Contributor Author

It seems that the version of macOS used in CI does not support MSL 3.2, causing the test to fail.

Copy link
Contributor

@HansKristian-Work HansKristian-Work left a comment

Choose a reason for hiding this comment

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

Simple enough.

@HansKristian-Work HansKristian-Work merged commit d12aa8e into KhronosGroup:main May 2, 2025
10 checks passed
@oscarbg
Copy link

oscarbg commented May 2, 2025

@squidbus some comments for MoltenVK complete support using this new way and avoiding Vulkan validator support..
correct me if I'm wrong but can that be useful for binary apps shipping shader source code and compiling dinamically so you inject printf's but they don't use vulkan validation layer..

first compiled a moltenvk branch (https://github.com/oscarbg/MoltenVK/tree/printf) referencing updated spirv-cross.. and I got:
[mvk-error] SPIR-V to MSL conversion error: Debug printf requires MSL 3.2.

seems also MoltenVK seems enabling CI to use macos-15, which I did:
oscarbg/MoltenVK@f0ef01d

now I get correct os_log used in MoltenVK seeing in dumping shaders but can't see anything in console app..

also some extra questions:
0)altough MSL generated code compiles fine with your patch:
I see shader in:
https://stackoverflow.com/questions/78652976/use-os-log-default-in-metal
that including <metal_logging> seems needed(recommended?):

Metal defines the logging functions and types in <metal_logging>. To enable logging, you need to set -fmetal-enable-logging (see section 1.6.9).

so adding ideally "#include <metal_logging>" in case later versions of shader compiler break compilation?
@HansKristian-Work what do you think? as said I'm being super "conformant" to Apple guide..

1)shader on MoltenVK side must be compiled with:
"-fmetal-enable-logging"
that's the reason I see no log output on my MoltenVK printf branch?

2)also setting MTL_LOG_LEVEL env variable to MTLLogLevelDebug or similar value according to:
https://developer.apple.com/forums/thread/763587
altough in this apple thread they use os_log_default.log_debug and you use os_log_default.log so maybe we need MTLLogLevelInfo:
export MTL_LOG_LEVEL=MTLLogLevelInfo
or experiment with:
https://developer.apple.com/documentation/metal/mtlloglevel

for complete reference:
https://developer.apple.com/documentation/metal/logging-shader-debug-messages

@oscarbg
Copy link

oscarbg commented May 2, 2025

to answer my own question 1) needs something like shown in:
https://developer.apple.com/documentation/metal/mtlcompileoptions/enablelogging
warning is:
Because logging incurs overhead, regardless of whether the system prints messages, you must explicitly enable logging.
which I did in my hacky branch:
oscarbg/MoltenVK@04c04e4
still can't see logs.. :-(

for reference also my commit to set macos-15:
oscarbg/MoltenVK@f0ef01d

@squidbus squidbus deleted the msl-debug-printf branch May 3, 2025 11:10
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.

3 participants