OpenRadar is down or something, so I am pasting my radar information here for anyone that wants to also file.
FB22068932
rdar://fb22068932
Repro project can be found here: https://github.com/jazzychad/MetalCompilerWarnings
Attached screenshots are:
Below is the text of the radar (feedback) I filed:
This issue occurs on all tested macOS trains.
When using one of the several methods to compile an MTLLibrary from source, there is no way to receive information about compile warnings in the case that there are no errors and a library is successfully compiled. This is a problem for the use-case of writing a metal shader editor when wanting to display diagnostics.
Compile warnings are only ever delivered through a compile error object when there are also errors associated with the passed source string. I have included a simple project to reproduce the issue.
Repro steps:
- unzip MetalCompilerWarnings.zip
- open Xcode project
- Run project on macOS
- Click the various compile button for the 4 different shader source strings
- Observe that errors and warnings are only reported in the case that an also exists
- Observe that the "Warnings Only" course reports no errors nor warnings
- Observe that when compiling the Warnings Only source that the compile warnings will actually appear in the Xcode console (I cannot reproduce this 100% of the time, but I have included a screenshot of when it appears)
So, the compiler knows about these warnings, but it is not reported up to the program at runtime.
In the documentation for the Objective-C method: https://developer.apple.com/documentation/metal/mtldevice/makelibrary(source:options:)?language=objc
- (id<MTLLibrary>) newLibraryWithSource:(NSString *) source
options:(MTLCompileOptions *) options
error:(NSError **) error;
error On return, if the compiler generates any warnings or errors, a pointer to an error instance that contains the error and warning information; otherwise, nil.
In my testing and use of this method, this statement is simply not true. The error param will only be set to non-nil if there are compile errors. My suspicion is that when supporting the swift methods (which use do/try/throw semantics) the behavior of returning both a non-nil library and a non-nil error was removed since the swift methods can only either succeed or fail (but not "both").
https://developer.apple.com/documentation/metal/mtllibraryerror-swift.struct/code/compilewarning There is an existing error code: MTLLibraryErrorCompileWarning (in objc) or MTLLibraryError.Code.compileWarning (in swift) for compiler warnings, but I haven't seen them come through.
It would be great as an enhancement request to update the makeLibrary methods to instead return some kind of wrapper object/struct which contains the MTLLibrary? and diagnostics information, such as:
struct MTLCompileDiagnostic {
let lineNumber: Int
let columnNumber: Int
let description: String
}
struct MTLCompileResults {
let library: MTLLibrary?
let errors: [MTLCompileDiagnostic]
let warnings: [MTLCompileDiagnostic]
}
or something similar. I'm sure you all can think of an excellent API for this.