Enable Metal Validation without Xcode.

Metal validation can be enabled for command-line application using environment variables.

Apple documents these environment variables on their developer site. More documentation about these environment variables is also available via a man page entry: man MetalValidation

To enable all relevant Metal API and shader validation without using Xcode, add the following to your .rc file.

# Metal Validation Defaults
export MTL_DEBUG_LAYER=1
export MTL_DEBUG_LAYER_ERROR_MODE=assert
# Set this to assert for stricter runtime checks. Set to "ignore" if too chatty.
export MTL_DEBUG_LAYER_WARNING_MODE=nslog
export MTL_SHADER_VALIDATION=1

These environment variable are good defaults but there are more validation related knobs and dials to turn. See man MetalValidation.