gpu/command_buffer/build_cmd_buffer_lib.py
def WriteStruct(self, func, f):
    """Writes a structure that matches the arguments to a function."""
    comment = func.GetInfo('cmd_comment')
    if not comment == None:
      f.write(comment)
    f.write("struct %s {\n" % func.name)
    f.write("  typedef %s ValueType;\n" % func.name)
    f.write("  static const CommandId kCmdId = k%s;\n" % func.name)
    func.WriteCmdArgFlag(f)
    func.WriteCmdFlag(f)
    f.write("\n")
    result = func.GetInfo('result')
    if not result == None:
      if len(result) == 1:
        f.write("  typedef %s Result;\n\n" % result[0])
      else:
        f.write("  struct Result {\n")
        for line in result:
          f.write("    %s;\n" % line)
        f.write("  };\n\n")

    func.WriteCmdComputeSize(f)
    func.WriteCmdSetHeader(f)
    func.WriteCmdInit(f)
    func.WriteCmdSet(f)
    func.WriteArgAccessors(f)

    f.write("  gpu::CommandHeader header;\n")
    total_args = 0
    args = func.GetCmdArgs()
    for arg in args:
      for cmd_type, name in arg.GetArgDecls():
        f.write("  %s %s;\n" % (cmd_type, name))
        total_args += 1
    trace_queue = func.GetInfo('trace_queueing_flow', False)
    if trace_queue:
      f.write("  uint32_t trace_id;\n")
      total_args += 1

    consts = func.GetCmdConstants()
    for const in consts:
      const_decls = const.GetArgDecls()
      assert(len(const_decls) == 1)
      const_cmd_type, const_name = const_decls[0]
      f.write("  static const %s %s = %s;\n" %
                 (const_cmd_type, const_name, const.GetConstantValue()))

    f.write("};\n")
    f.write("\n")

    size = total_args * _SIZE_OF_UINT32 + _SIZE_OF_COMMAND_HEADER
    f.write("static_assert(sizeof(%s) == %d,\n" % (func.name, size))
    f.write("              \"size of %s should be %d\");\n" %
            (func.name, size))
    f.write("static_assert(offsetof(%s, header) == 0,\n" % func.name)
    f.write("              \"offset of %s header should be 0\");\n" %
            func.name)
    offset = _SIZE_OF_COMMAND_HEADER
    for arg in args:
      for _, name in arg.GetArgDecls():
        f.write("static_assert(offsetof(%s, %s) == %d,\n" %
                (func.name, name, offset))
        f.write("              \"offset of %s %s should be %d\");\n" %
                (func.name, name, offset))
        offset += _SIZE_OF_UINT32
    if not result == None and len(result) > 1:
      offset = 0;
      for line in result:
        parts = line.split()
        name = parts[-1]
        check = """
static_assert(offsetof(%(cmd_name)s::Result, %(field_name)s) == %(offset)d,
              "offset of %(cmd_name)s Result %(field_name)s should be "
              "%(offset)d");
"""
        f.write((check.strip() + "\n") % {
              'cmd_name': func.name,
              'field_name': name,
              'offset': offset,
            })
        offset += _SIZE_OF_UINT32
    f.write("\n")
Writes a structure that matches the arguments to a function.
Writes a structure that matches the arguments to a function.
Writes a structure that matches the arguments to a function .
def WriteStruct(self, func, f):
    comment = func.GetInfo('cmd_comment')
    if not comment == None:
      f.write(comment)
    f.write("struct %s {\n" % func.name)
    f.write("  typedef %s ValueType;\n" % func.name)
    f.write("  static const CommandId kCmdId = k%s;\n" % func.name)
    func.WriteCmdArgFlag(f)
    func.WriteCmdFlag(f)
    f.write("\n")
    result = func.GetInfo('result')
    if not result == None:
      if len(result) == 1:
        f.write("  typedef %s Result;\n\n" % result[0])
      else:
        f.write("  struct Result {\n")
        for line in result:
          f.write("    %s;\n" % line)
        f.write("  };\n\n")
    func.WriteCmdComputeSize(f)
    func.WriteCmdSetHeader(f)
    func.WriteCmdInit(f)
    func.WriteCmdSet(f)
    func.WriteArgAccessors(f)
    f.write("  gpu::CommandHeader header;\n")
    total_args = 0
    args = func.GetCmdArgs()
    for arg in args:
      for cmd_type, name in arg.GetArgDecls():
        f.write("  %s %s;\n" % (cmd_type, name))
        total_args += 1
    trace_queue = func.GetInfo('trace_queueing_flow', False)
    if trace_queue:
      f.write("  uint32_t trace_id;\n")
      total_args += 1
    consts = func.GetCmdConstants()
    for const in consts:
      const_decls = const.GetArgDecls()
      assert(len(const_decls) == 1)
      const_cmd_type, const_name = const_decls[0]
      f.write("  static const %s %s = %s;\n" %
                 (const_cmd_type, const_name, const.GetConstantValue()))
    f.write("};\n")
    f.write("\n")
    size = total_args * _SIZE_OF_UINT32 + _SIZE_OF_COMMAND_HEADER
    f.write("static_assert(sizeof(%s) == %d,\n" % (func.name, size))
    f.write("              \"size of %s should be %d\");\n" %
            (func.name, size))
    f.write("static_assert(offsetof(%s, header) == 0,\n" % func.name)
    f.write("              \"offset of %s header should be 0\");\n" %
            func.name)
    offset = _SIZE_OF_COMMAND_HEADER
    for arg in args:
      for _, name in arg.GetArgDecls():
        f.write("static_assert(offsetof(%s, %s) == %d,\n" %
                (func.name, name, offset))
        f.write("              \"offset of %s %s should be %d\");\n" %
                (func.name, name, offset))
        offset += _SIZE_OF_UINT32
    if not result == None and len(result) > 1:
      offset = 0;
      for line in result:
        parts = line.split()
        name = parts[-1]
        check = """
static_assert(offsetof(%(cmd_name)s::Result, %(field_name)s) == %(offset)d,
              "offset of %(cmd_name)s Result %(field_name)s should be "
              "%(offset)d");
"""
        f.write((check.strip() + "\n") % {
              'cmd_name': func.name,
              'field_name': name,
              'offset': offset,
            })
        offset += _SIZE_OF_UINT32
    f.write("\n")
def WriteStruct ( self , func , f ) : comment = func . GetInfo ( 'cmd_comment' ) if not comment == None : f . write ( comment ) f . write ( "struct %s {\n" % func . name ) f . write ( "  typedef %s ValueType;\n" % func . name ) f . write ( "  static const CommandId kCmdId = k%s;\n" % func . name ) func . WriteCmdArgFlag ( f ) func . WriteCmdFlag ( f ) f . write ( "\n" ) result = func . GetInfo ( 'result' ) if not result == None : if len ( result ) == 1 : f . write ( "  typedef %s Result;\n\n" % result [ 0 ] ) else : f . write ( "  struct Result {\n" ) for line in result : f . write ( "    %s;\n" % line ) f . write ( "  };\n\n" ) func . WriteCmdComputeSize ( f ) func . WriteCmdSetHeader ( f ) func . WriteCmdInit ( f ) func . WriteCmdSet ( f ) func . WriteArgAccessors ( f ) f . write ( "  gpu::CommandHeader header;\n" ) total_args = 0 args = func . GetCmdArgs ( ) for arg in args : for cmd_type , name in arg . GetArgDecls ( ) : f . write ( "  %s %s;\n" % ( cmd_type , name ) ) total_args += 1 trace_queue = func . GetInfo ( 'trace_queueing_flow' , False ) if trace_queue : f . write ( "  uint32_t trace_id;\n" ) total_args += 1 consts = func . GetCmdConstants ( ) for const in consts : const_decls = const . GetArgDecls ( ) assert ( len ( const_decls ) == 1 ) const_cmd_type , const_name = const_decls [ 0 ] f . write ( "  static const %s %s = %s;\n" % ( const_cmd_type , const_name , const . GetConstantValue ( ) ) ) f . write ( "};\n" ) f . write ( "\n" ) size = total_args * _SIZE_OF_UINT32 + _SIZE_OF_COMMAND_HEADER f . write ( "static_assert(sizeof(%s) == %d,\n" % ( func . name , size ) ) f . write ( "              \"size of %s should be %d\");\n" % ( func . name , size ) ) f . write ( "static_assert(offsetof(%s, header) == 0,\n" % func . name ) f . write ( "              \"offset of %s header should be 0\");\n" % func . name ) offset = _SIZE_OF_COMMAND_HEADER for arg in args : for _ , name in arg . GetArgDecls ( ) : f . write ( "static_assert(offsetof(%s, %s) == %d,\n" % ( func . name , name , offset ) ) f . write ( "              \"offset of %s %s should be %d\");\n" % ( func . name , name , offset ) ) offset += _SIZE_OF_UINT32 if not result == None and len ( result ) > 1 : offset = 0 ; for line in result : parts = line . split ( ) name = parts [ - 1 ] check = """
static_assert(offsetof(%(cmd_name)s::Result, %(field_name)s) == %(offset)d,
              "offset of %(cmd_name)s Result %(field_name)s should be "
              "%(offset)d");
""" f . write ( ( check . strip ( ) + "\n" ) % { 'cmd_name' : func . name , 'field_name' : name , 'offset' : offset , } ) offset += _SIZE_OF_UINT32 f . write ( "\n" )
Writes a structure that matches the arguments to a function.
Writes a structure that matches the arguments to a function .
"""Writes a structure that matches the arguments to a function."""
self
func
f