code: def parse_cmd_buf(dat):
      ptr = 0
      while ptr < len(dat):
          cmd = struct.unpack("I", dat[ptr : ptr + 4])[0]
          if (cmd >> 24) == 0x70:
              # packet with opcode and opcode specific payload (replace pkt3)
              opcode, size = ((cmd >> 16) & 0x7F), cmd & 0x3FFF
              vals = struct.unpack(
                  "I" * size, dat[ptr + 4 : ptr + 4 + 4 * size]
              )
              print(
                  f"{ptr:3X} -- typ 7: {size=:3d}, {opcode=:#x} {ops[opcode]}",
                  hprint(vals),
              )
              if ops[opcode] == "CP_LOAD_STATE6_FRAG":
                  dst_off = vals[0] & 0x3FFF
                  state_type = (vals[0] >> 14) & 0x3
                  state_src = (vals[0] >> 16) & 0x3
                  state_block = (
                      vals[0] >> 18
                  ) & 0xF  # 13 = SB4_CS_SHADER
                  num_unit = vals[0] >> 22
                  print(
                      f"{num_unit=} {state_block=} {state_src=} {state_type=} {dst_off=}"
                  )
  
                  from disassemblers.adreno import disasm_raw
  
                  if state_type == ST6_SHADER:
                      disasm_raw(
                          get_mem(((vals[2] << 32) | vals[1]), 0x180)
                      )
                  if state_type == ST6_CONSTANTS:
                      hexdump(
                          get_mem(
                              ((vals[2] << 32) | vals[1]),
                              min(0x180, num_unit * 4),
                          )
                      )
                  pass
              ptr += 4 * size
          elif (cmd >> 28) == 0x4:
              # write one or more registers (replace pkt0)
              offset, size = ((cmd >> 8) & 0x7FFFF), cmd & 0x7F
              vals = struct.unpack(
                  "I" * size, dat[ptr + 4 : ptr + 4 + 4 * size]
              )
              print(
                  f"{ptr:3X} -- typ 4: {size=:3d}, {offset=:#x}",
                  hprint(vals),
              )
              ptr += 4 * size
          else:
              print("unk", hex(cmd))
          ptr += 4
  
file_path: tinygrad/extra/qcom_gpu_driver/opencl_ioctl.py
imports: import ctypes, ctypes.util, struct, fcntl, re
  from hexdump import hexdump
  from tinygrad.runtime.ops_gpu import CLDevice, CLAllocator
  import pathlib, sys
  import xml.etree.ElementTree
  from extra.qcom_gpu_driver import msm_kgsl
  import mmap
  from tinygrad import Tensor, Device, TinyJit
label_desc: Use image node_id 6 for calling a global function with example usage: parse_cmd_buf(dat) without return types