@@ -286,6 +286,50 @@ def check_command_list_closed(state, ctx, defi)
286286end
287287
288288
289+ # ADDED: validate a zeCommandListReset. Runs at ENTRY, before the model applies
290+ # the reset, reading the list handle from defi. Reports three misuses:
291+ # * already-destroyed list -- resetting a destroyed handle is a usage error.
292+ # * immediate command list -- zeCommandListReset is invalid on an immediate list
293+ # (it has no closed/execute lifecycle to reset); the runtime returns
294+ # ZE_RESULT_ERROR_INVALID_ARGUMENT.
295+ # * reset while in-flight -- the list is still executing a prior
296+ # zeCommandQueueExecuteCommandLists submission. Resetting it now races the
297+ # device and is undefined behavior in Level Zero.
298+ # Every command list handle is tracked, so the list is always found.
299+ # Reported once per (command list, reason) pair.
300+ def check_command_list_reset ( state , ctx , defi )
301+ handle = defi [ 'hCommandList' ]
302+ cmd_list = state . find_objects ( ctx , 'command_list' ) [ handle ]
303+
304+ if cmd_list . status == ZEModel ::CommandList . class_variable_get ( :@@DESTROYED )
305+ key = "clreset-destroyed-#{ state . get_handle_str ( handle ) } "
306+ if state . print_tracker [ key ] == 0
307+ state . print_tracker [ key ] = 1
308+ state . print_usage_error ( ctx , "command list #{ state . get_handle_str ( handle ) } was already destroyed before zeCommandListReset" )
309+ end
310+ return
311+ end
312+
313+ if cmd_list . immediate
314+ key = "clreset-immediate-#{ state . get_handle_str ( handle ) } "
315+ if state . print_tracker [ key ] == 0
316+ state . print_tracker [ key ] = 1
317+ state . print_usage_error ( ctx , "zeCommandListReset called on immediate command list #{ state . get_handle_str ( handle ) } ; " \
318+ "immediate command lists cannot be reset" )
319+ end
320+ end
321+
322+ if state . command_list_in_flight? ( ctx , handle )
323+ key = "clreset-inflight-#{ state . get_handle_str ( handle ) } "
324+ if state . print_tracker [ key ] == 0
325+ state . print_tracker [ key ] = 1
326+ state . print_usage_error ( ctx , "command list #{ state . get_handle_str ( handle ) } is being reset while a prior " \
327+ "zeCommandQueueExecuteCommandLists submission is still in-flight; the device may " \
328+ "still be executing it (undefined behavior)" )
329+ end
330+ end
331+ end
332+
289333def check_valid_module ( state , ctx , defi )
290334 module_handle = state . find_param ( ctx , 'hModule' )
291335 if !module_handle || module_handle == 0
0 commit comments