@@ -207,10 +207,32 @@ pub fn unlockStdErr() void {
207
207
/// Print to stderr, unbuffered, and silently returning on failure. Intended
208
208
/// for use in "printf debugging." Use `std.log` functions for proper logging.
209
209
pub fn print (comptime fmt : []const u8 , args : anytype ) void {
210
- lockStdErr ();
211
- defer unlockStdErr ();
212
- const stderr = io .getStdErr ().writer ();
213
- nosuspend stderr .print (fmt , args ) catch return ;
210
+ if (builtin .zig_backend == .stage2_spirv ) {
211
+ const ret = asm volatile (
212
+ \\ %set = OpExtInstImport "OpenCL.std"
213
+ \\ %u8 = OpTypeInt 8 0
214
+ \\ %u32 = OpTypeInt 32 0
215
+ \\ %u64 = OpTypeInt 64 0
216
+ \\ %u64_4 = OpConstant %u64 4
217
+ \\%_arr_u8_4 = OpTypeArray %u8 %u64_4
218
+ \\%_ptr_UniformConstant__arr_u8_4 = OpTypePointer UniformConstant %_arr_u8_4
219
+ \\ %char_H = OpConstant %u8 72
220
+ \\ %char_i = OpConstant %u8 105
221
+ \\ %char__n = OpConstant %u8 10
222
+ \\ %char_0 = OpConstant %u8 0
223
+ \\%const_str = OpConstantComposite %_arr_u8_4 %char_H %char_i %char__n %char_0
224
+ \\ %fmt = OpVariable %_ptr_UniformConstant__arr_u8_4 UniformConstant %const_str
225
+ \\
226
+ \\ %ret = OpExtInst %u32 %set 184 %fmt
227
+ : [ret ] "" (- > u32 ),
228
+ );
229
+ _ = ret ;
230
+ } else {
231
+ lockStdErr ();
232
+ defer unlockStdErr ();
233
+ const stderr = io .getStdErr ().writer ();
234
+ nosuspend stderr .print (fmt , args ) catch return ;
235
+ }
214
236
}
215
237
216
238
pub fn getStderrMutex () * std.Thread.Mutex {
0 commit comments