#!/usr/bin/env python from ctypes import * import pprint import sys cdef extern from "gallium/pipe/p_context.h": cdef struct pipe_context: # ... void destroy(pipe_context*) # ... cdef extern from "gallium/pipe/p_screen.h": cdef struct pipe_screen: void destroy(pipe_screen*) char* get_name(pipe_screen*) char* get_vendor(pipe_screen*) int get_param(pipe_screen*, int) float get_paramf(pipe_screen*, int) pipe_context* context_create(pipe_screen*, void*) bint is_format_supported(pipe_screen*, int, int, unsigned int, unsigned int) # ... """ pipe_screen._fields_ = [ ("winsys", c_void_p), ("destroy", CFUNCTYPE(None, POINTER(pipe_screen))), ("get_name", CFUNCTYPE(c_char_p, POINTER(pipe_screen))), ("get_vendor", CFUNCTYPE(c_char_p, POINTER(pipe_screen))), ("get_param", CFUNCTYPE(c_int, POINTER(pipe_screen), c_int)), ("get_paramf", CFUNCTYPE(c_float, POINTER(pipe_screen), c_int)), ("context_create", CFUNCTYPE(c_void_p, POINTER(pipe_screen), c_void_p)), ("is_format_supported", CFUNCTYPE(c_int, POINTER(pipe_screen), c_int, c_int, c_uint, c_uint)), ("resource_create", CFUNCTYPE(c_void_p, POINTER(pipe_screen), c_void_p)), ("resource_from_handle", CFUNCTYPE(c_void_p, POINTER(pipe_screen), c_void_p, c_void_p)), ("resource_get_handle", CFUNCTYPE(c_int, POINTER(pipe_screen), c_void_p, c_void_p)), ("resource_destroy", CFUNCTYPE(None, POINTER(pipe_screen), c_void_p)), ("get_tex_surface", CFUNCTYPE(c_void_p, POINTER(pipe_screen), c_void_p, c_uint, c_uint, c_uint, c_uint)), ("tex_surface_destroy", CFUNCTYPE(None, c_void_p)), ("user_buffer_create", CFUNCTYPE(c_void_p, POINTER(pipe_screen), c_void_p, c_uint, c_uint)), ("flush_frontbuffer", CFUNCTYPE(None, POINTER(pipe_screen), c_void_p, c_void_p)), ("fence_reference", CFUNCTYPE(None, POINTER(pipe_screen), c_void_p, c_void_p)), ("fence_signalled", CFUNCTYPE(c_int, POINTER(pipe_screen), c_void_p, c_uint)), ("fence_finish", CFUNCTYPE(c_int, POINTER(pipe_screen), c_void_p, c_uint)), ] """ cdef class Screen: cdef pipe_screen *screen cdef readonly object params, format_supported_dict def __init__(self, int screen): self.screen = screen self.params = {} self.format_supported_dict = {} self.init_params() def __del__(self): self.destroy() def init_params(self): for k, v in params.iteritems(): self.params[k] = self.screen.get_param(self.screen, v) for k, v in parambs.iteritems(): self.params[k] = bool(self.screen.get_param(self.screen, v)) for k, v in paramfs.iteritems(): self.params[k] = self.screen.get_paramf(self.screen, v) def destroy(self): self.screen.destroy(self.screen) property name: def __get__(self): return self.screen.get_name(self.screen) property vendor: def __get__(self): return self.screen.get_vendor(self.screen) def is_format_supported(self, format, target, bindings, geom_flags): return self.screen.is_format_supported(self.screen, format, target, bindings.value, geom_flags.value) cdef class Context: cdef pipe_context *context def __init__(self, Screen screen): self.context = screen.screen.context_create(screen.screen, NULL) if self.context is NULL: raise Exception, "Couldn't create Context from given Screen" def __del__(self): self.destroy() def destroy(self): self.context.destroy(self.context) """ pipe_context._fields_ = [ ("winsys", c_void_p), ("screen", c_void_p), ("priv", c_void_p), ("draw", c_void_p), ("destroy", CFUNCTYPE(None, POINTER(pipe_context))), ("draw_arrays", CFUNCTYPE(None, POINTER(pipe_context), c_uint, c_uint, c_uint)), ("draw_elements", CFUNCTYPE(None, POINTER(pipe_context), c_void_p, c_uint, c_int, c_uint, c_uint, c_uint)), ("draw_arrays_instanced", c_void_p), ("draw_elements_instanced", c_void_p), ("draw_range_elements", c_void_p), ("render_condition", c_void_p), ("create_query", c_void_p), ("destroy_query", c_void_p), ("begin_query", c_void_p), ("end_query", c_void_p), ("get_query_result", c_void_p), ("create_blend_state", c_void_p), ("bind_blend_state", c_void_p), ("delete_blend_state", c_void_p), ("create_sampler_state", c_void_p), ("bind_fragment_sampler_states", c_void_p), ("bind_vertex_sampler_states", c_void_p), ("delete_sampler_state", c_void_p), ("create_rasterizer_state", c_void_p), ("bind_rasterizer_state", c_void_p), ("delete_rasterizer_state", c_void_p), ("create_depth_stencil_alpha_state", c_void_p), ("bind_depth_stencil_alpha_state", c_void_p), ("delete_depth_stencil_alpha_state", c_void_p), ("create_fs_state", c_void_p), ("bind_fs_state", c_void_p), ("delete_fs_state", c_void_p), ("create_vs_state", c_void_p), ("bind_vs_state", c_void_p), ("delete_vs_state", c_void_p), ("create_gs_state", c_void_p), ("bind_gs_state", c_void_p), ("delete_gs_state", c_void_p), ("create_vertex_elements_state", c_void_p), ("bind_vertex_elements_state", c_void_p), ("delete_vertex_elements_state", c_void_p), ("set_blend_color", c_void_p), ("set_stencil_ref", c_void_p), ("set_clip_state", c_void_p), ("set_constant_buffer", c_void_p), ("set_framebuffer_state", c_void_p), ("set_polygon_stipple", c_void_p), ("set_scissor_state", c_void_p), ("set_viewport_state", c_void_p), ("set_fragment_sampler_views", c_void_p), ("set_vertex_sampler_views", c_void_p), ("set_vertex_buffers", c_void_p), ("surface_copy", c_void_p), ("surface_fill", c_void_p), ("clear", c_void_p), ("flush", c_void_p), ("is_resource_referenced", c_void_p), ("create_sampler_view", c_void_p), ("sampler_view_destroy", c_void_p), ("get_transfer", c_void_p), ("transfer_destroy", c_void_p), ("transfer_map", c_void_p), ("transfer_flush_region", c_void_p), ("transfer_unmap", c_void_p), ("transfer_inline_write", c_void_p), ] """ def parse_enums(f): handle = open(f, "r") d = {} for chaff in handle: if "enum pipe_format" in chaff: break for format in handle: if format == "PIPE_FORMAT_NONE": break try: name, number = format.split("=") except ValueError: continue name = name.strip() number = int(number.split(",", 1)[0]) if not name.startswith("PIPE_FORMAT_"): continue d[name[12:]] = number return d if __name__ == "__main__": d = parse_enums(sys.argv[-1]) f = sys.argv[-2] handle = open(f, "r+") while not handle.readline().startswith("###"): pass handle.truncate() handle.write("by_name = ") pprint.pprint(d, handle) handle.close() ### by_name = {'A8B8G8R8_SRGB': 98, 'A8B8G8R8_UNORM': 121, 'A8R8G8B8_SRGB': 102, 'A8R8G8B8_UNORM': 3, 'A8_UNORM': 10, 'B10G10R10A2_UNORM': 131, 'B4G4R4A4_UNORM': 6, 'B4G4R4X4_UNORM': 135, 'B5G5R5A1_UNORM': 5, 'B5G5R5X1_UNORM': 122, 'B5G6R5_UNORM': 7, 'B8G8R8A8_SRGB': 100, 'B8G8R8A8_UNORM': 1, 'B8G8R8X8_SRGB': 101, 'B8G8R8X8_UNORM': 2, 'DXT1_RGB': 105, 'DXT1_RGBA': 106, 'DXT1_SRGB': 109, 'DXT1_SRGBA': 110, 'DXT3_RGBA': 107, 'DXT3_SRGBA': 111, 'DXT5_RGBA': 108, 'DXT5_SRGBA': 112, 'G8R8_G8B8_UNORM': 118, 'I8_UNORM': 11, 'L16_UNORM': 13, 'L4A4_UNORM': 130, 'L8A8_SRGB': 96, 'L8A8_UNORM': 12, 'L8_SRGB': 95, 'L8_UNORM': 9, 'NONE': 0, 'R10G10B10A2_UNORM': 8, 'R10G10B10A2_USCALED': 123, 'R10G10B10X2_SNORM': 129, 'R10G10B10X2_USCALED': 128, 'R10SG10SB10SA2U_NORM': 132, 'R11G11B10_FLOAT': 124, 'R16G16B16A16_FLOAT': 94, 'R16G16B16A16_SNORM': 59, 'R16G16B16A16_SSCALED': 63, 'R16G16B16A16_UNORM': 51, 'R16G16B16A16_USCALED': 55, 'R16G16B16_FLOAT': 93, 'R16G16B16_SNORM': 58, 'R16G16B16_SSCALED': 62, 'R16G16B16_UNORM': 50, 'R16G16B16_USCALED': 54, 'R16G16_FLOAT': 92, 'R16G16_SNORM': 57, 'R16G16_SSCALED': 61, 'R16G16_UNORM': 49, 'R16G16_USCALED': 53, 'R16_FLOAT': 91, 'R16_SNORM': 56, 'R16_SSCALED': 60, 'R16_UNORM': 48, 'R16_USCALED': 52, 'R1_UNORM': 127, 'R32G32B32A32_FIXED': 90, 'R32G32B32A32_FLOAT': 31, 'R32G32B32A32_SNORM': 43, 'R32G32B32A32_SSCALED': 47, 'R32G32B32A32_UNORM': 35, 'R32G32B32A32_USCALED': 39, 'R32G32B32_FIXED': 89, 'R32G32B32_FLOAT': 30, 'R32G32B32_SNORM': 42, 'R32G32B32_SSCALED': 46, 'R32G32B32_UNORM': 34, 'R32G32B32_USCALED': 38, 'R32G32_FIXED': 88, 'R32G32_FLOAT': 29, 'R32G32_SNORM': 41, 'R32G32_SSCALED': 45, 'R32G32_UNORM': 33, 'R32G32_USCALED': 37, 'R32_FIXED': 87, 'R32_FLOAT': 28, 'R32_SNORM': 40, 'R32_SSCALED': 44, 'R32_UNORM': 32, 'R32_USCALED': 36, 'R5SG5SB6U_NORM': 120, 'R64G64B64A64_FLOAT': 27, 'R64G64B64_FLOAT': 26, 'R64G64_FLOAT': 25, 'R64_FLOAT': 24, 'R8G8B8A8_SNORM': 77, 'R8G8B8A8_SRGB': 104, 'R8G8B8A8_SSCALED': 85, 'R8G8B8A8_UNORM': 67, 'R8G8B8A8_USCALED': 72, 'R8G8B8X8_UNORM': 134, 'R8G8B8_SNORM': 76, 'R8G8B8_SRGB': 97, 'R8G8B8_SSCALED': 84, 'R8G8B8_UNORM': 66, 'R8G8B8_USCALED': 71, 'R8G8Bx_SNORM': 133, 'R8G8_B8G8_UNORM': 117, 'R8G8_SNORM': 75, 'R8G8_SSCALED': 83, 'R8G8_UNORM': 65, 'R8G8_USCALED': 70, 'R8SG8SB8UX8U_NORM': 119, 'R8_SNORM': 74, 'R8_SSCALED': 82, 'R8_UNORM': 64, 'R8_USCALED': 69, 'R9G9B9E5_FLOAT': 125, 'RGTC1_SNORM': 114, 'RGTC1_UNORM': 113, 'RGTC2_SNORM': 116, 'RGTC2_UNORM': 115, 'S8_USCALED': 23, 'S8_USCALED_Z24_UNORM': 20, 'UYVY': 14, 'X8B8G8R8_SRGB': 99, 'X8B8G8R8_UNORM': 68, 'X8R8G8B8_SRGB': 103, 'X8R8G8B8_UNORM': 4, 'X8Z24_UNORM': 22, 'YUYV': 15, 'Z16_UNORM': 16, 'Z24X8_UNORM': 21, 'Z24_UNORM_S8_USCALED': 19, 'Z32_FLOAT': 18, 'Z32_FLOAT_S8X24_USCALED': 126, 'Z32_UNORM': 17} class bind_bitfield(Structure): _fields_ = [ ("DEPTH_STENCIL", c_uint, 1), ("RENDER_TARGET", c_uint, 1), ("SAMPLER_VIEW", c_uint, 1), ("VERTEX_BUFFER", c_uint, 1), ("INDEX_BUFFER", c_uint, 1), ("CONSTANT_BUFFER", c_uint, 1), ("BLIT_SOURCE", c_uint, 1), ("BLIT_DESTINATION", c_uint, 1), ("DISPLAY_TARGET", c_uint, 1), ("TRANSFER_WRITE", c_uint, 1), ("TRANSFER_READ", c_uint, 1), ] class Bindings(Union): _anonymous_ = ("bitfield",) _fields_ = [ ("bitfield", bind_bitfield), ("value", c_uint), ] class geom_bitfield(Structure): _fields_ = [ ("NON_SQUARE", c_uint, 1), ("NON_POWER_OF_TWO", c_uint, 1), ] class Geom(Union): _anonymous_ = ("bitfield",) _fields_ = [ ("bitfield", geom_bitfield), ("value", c_uint), ] params = { "MAX_TEXTURE_IMAGE_UNITS": 1, "MAX_RENDER_TARGETS": 8, "MAX_TEXTURE_2D_LEVELS": 11, "MAX_TEXTURE_3D_LEVELS": 12, "MAX_TEXTURE_CUBE_LEVELS": 13, "MAX_TEXTURE_ANISOTROPY": 18, "MAX_TEXTURE_LOD_BIAS": 19, "MAX_VERTEX_TEXTURE_UNITS": 26, "MAX_PREDICATE_REGISTERS": 30, "PIPE_CAP_MAX_COMBINED_SAMPLERS": 31, "PIPE_CAP_MAX_CONST_BUFFERS": 32, "PIPE_CAP_MAX_CONST_BUFFER_SIZE": 33, } parambs = { "NPOT_TEXTURES": 2, "TWO_SIDED_STENCIL": 3, "GLSL": 4, "DUAL_SOURCE_BLEND": 5, "ANISOTROPIC_FILTER": 6, "POINT_SPRITE": 7, "OCCLUSION_QUERY": 9, "TEXTURE_SHADOW_MAP": 10, "TEXTURE_MIRROR_CLAMP": 24, "TEXTURE_MIRROR_REPEAT": 25, "TGSI_CONT_SUPPORTED": 27, "BLEND_EQUATION_SEPARATE": 28, "SM3": 29, "PIPE_CAP_INDEP_BLEND_ENABLE": 34, "PIPE_CAP_INDEP_BLEND_FUNC": 35, "PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT": 36, "PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT": 37, "PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER": 38, "PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER": 39, } paramfs = { "MAX_LINE_WIDTH": 14, "MAX_LINE_WIDTH_AA": 15, "MAX_POINT_WIDTH": 16, "MAX_POINT_WIDTH_AA": 17, "GUARD_BAND_LEFT": 20, "GUARD_BAND_TOP": 21, "GUARD_BAND_RIGHT": 22, "GUARD_BAND_BOTTOM": 23, }