GLboolean nouveau_context_create(gl_api api, const struct gl_config *visual, __DRIcontext *dri_ctx, unsigned major_version, unsigned minor_version, uint32_t flags, bool notify_reset, unsigned *error, void *share_ctx) { __DRIscreen *dri_screen = dri_ctx->driScreenPriv; struct nouveau_screen *screen = dri_screen->driverPrivate; struct nouveau_context *nctx; struct gl_context *ctx; if (flags & ~__DRI_CTX_FLAG_DEBUG) { *error = __DRI_CTX_ERROR_UNKNOWN_FLAG; return false; } if (notify_reset) { *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE; return false; } ctx = screen->driver->context_create(screen, visual, share_ctx); if (!ctx) { *error = __DRI_CTX_ERROR_NO_MEMORY; return GL_FALSE; } driContextSetFlags(ctx, flags); nctx = to_nouveau_context(ctx); nctx->dri_context = dri_ctx; dri_ctx->driverPrivate = ctx; _mesa_compute_version(ctx); if (ctx->Version < major_version * 10 + minor_version) { nouveau_context_destroy(dri_ctx); *error = __DRI_CTX_ERROR_BAD_VERSION; return GL_FALSE; } /* Exec table initialization requires the version to be computed */ _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); if (nouveau_bo_new(context_dev(ctx), NOUVEAU_BO_VRAM, 0, 4096, NULL, &nctx->fence)) { nouveau_context_destroy(dri_ctx); *error = __DRI_CTX_ERROR_NO_MEMORY; return GL_FALSE; } *error = __DRI_CTX_ERROR_SUCCESS; return GL_TRUE; }
static struct st_context * st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe, const struct st_config_options *options) { struct pipe_screen *screen = pipe->screen; uint i; struct st_context *st = ST_CALLOC_STRUCT( st_context ); st->options = *options; ctx->st = st; st->ctx = ctx; st->pipe = pipe; /* XXX: this is one-off, per-screen init: */ st_debug_init(); /* state tracker needs the VBO module */ _vbo_CreateContext(ctx); st->dirty.mesa = ~0; st->dirty.st = ~0; /* Create upload manager for vertex data for glBitmap, glDrawPixels, * glClear, etc. */ st->uploader = u_upload_create(st->pipe, 65536, 4, PIPE_BIND_VERTEX_BUFFER); if (!screen->get_param(screen, PIPE_CAP_USER_INDEX_BUFFERS)) { st->indexbuf_uploader = u_upload_create(st->pipe, 128 * 1024, 4, PIPE_BIND_INDEX_BUFFER); } if (!screen->get_param(screen, PIPE_CAP_USER_CONSTANT_BUFFERS)) { unsigned alignment = screen->get_param(screen, PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT); st->constbuf_uploader = u_upload_create(pipe, 128 * 1024, alignment, PIPE_BIND_CONSTANT_BUFFER); } st->cso_context = cso_create_context(pipe); st_init_atoms( st ); st_init_bitmap(st); st_init_clear(st); st_init_draw( st ); st_init_generate_mipmap(st); /* Choose texture target for glDrawPixels, glBitmap, renderbuffers */ if (pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES)) st->internal_target = PIPE_TEXTURE_2D; else st->internal_target = PIPE_TEXTURE_RECT; /* Vertex element objects used for drawing rectangles for glBitmap, * glDrawPixels, glClear, etc. */ for (i = 0; i < Elements(st->velems_util_draw); i++) { memset(&st->velems_util_draw[i], 0, sizeof(struct pipe_vertex_element)); st->velems_util_draw[i].src_offset = i * 4 * sizeof(float); st->velems_util_draw[i].instance_divisor = 0; st->velems_util_draw[i].vertex_buffer_index = cso_get_aux_vertex_buffer_slot(st->cso_context); st->velems_util_draw[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; } /* we want all vertex data to be placed in buffer objects */ vbo_use_buffer_objects(ctx); /* make sure that no VBOs are left mapped when we're drawing. */ vbo_always_unmap_buffers(ctx); /* Need these flags: */ st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; st->pixel_xfer.cache = _mesa_new_program_cache(); st->has_stencil_export = screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT); st->has_shader_model3 = screen->get_param(screen, PIPE_CAP_SM3); st->prefer_blit_based_texture_transfer = screen->get_param(screen, PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER); st->needs_texcoord_semantic = screen->get_param(screen, PIPE_CAP_TGSI_TEXCOORD); st->apply_texture_swizzle_to_border_color = !!(screen->get_param(screen, PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK) & (PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 | PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600)); /* GL limits and extensions */ st_init_limits(st); st_init_extensions(st); _mesa_compute_version(ctx); _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); return st; }
/* Create the device specific context. */ GLboolean r100CreateContext( gl_api api, const struct gl_config *glVisual, __DRIcontext *driContextPriv, unsigned major_version, unsigned minor_version, uint32_t flags, unsigned *error, void *sharedContextPrivate) { __DRIscreen *sPriv = driContextPriv->driScreenPriv; radeonScreenPtr screen = (radeonScreenPtr)(sPriv->driverPrivate); struct dd_function_table functions; r100ContextPtr rmesa; struct gl_context *ctx; int i; int tcl_mode, fthrottle_mode; switch (api) { case API_OPENGL_COMPAT: if (major_version > 1 || minor_version > 3) { *error = __DRI_CTX_ERROR_BAD_VERSION; return GL_FALSE; } break; case API_OPENGLES: break; default: *error = __DRI_CTX_ERROR_BAD_API; return GL_FALSE; } /* Flag filtering is handled in dri2CreateContextAttribs. */ (void) flags; assert(glVisual); assert(driContextPriv); assert(screen); /* Allocate the Radeon context */ rmesa = calloc(1, sizeof(*rmesa)); if ( !rmesa ) { *error = __DRI_CTX_ERROR_NO_MEMORY; return GL_FALSE; } rmesa->radeon.radeonScreen = screen; r100_init_vtbl(&rmesa->radeon); /* init exp fog table data */ radeonInitStaticFogData(); /* Parse configuration files. * Do this here so that initialMaxAnisotropy is set before we create * the default textures. */ driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache, screen->driScreen->myNum, "radeon"); rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache, "def_max_anisotropy"); if ( driQueryOptionb( &rmesa->radeon.optionCache, "hyperz" ) ) { if ( sPriv->drm_version.minor < 13 ) fprintf( stderr, "DRM version 1.%d too old to support HyperZ, " "disabling.\n", sPriv->drm_version.minor ); else rmesa->using_hyperz = GL_TRUE; } if ( sPriv->drm_version.minor >= 15 ) rmesa->texmicrotile = GL_TRUE; /* Init default driver functions then plug in our Radeon-specific functions * (the texture functions are especially important) */ _mesa_init_driver_functions( &functions ); radeonInitTextureFuncs( &rmesa->radeon, &functions ); radeonInitQueryObjFunctions(&functions); if (!radeonInitContext(&rmesa->radeon, &functions, glVisual, driContextPriv, sharedContextPrivate)) { free(rmesa); *error = __DRI_CTX_ERROR_NO_MEMORY; return GL_FALSE; } rmesa->radeon.swtcl.RenderIndex = ~0; rmesa->radeon.hw.all_dirty = GL_TRUE; ctx = &rmesa->radeon.glCtx; /* Initialize the software rasterizer and helper modules. */ _swrast_CreateContext( ctx ); _vbo_CreateContext( ctx ); _tnl_CreateContext( ctx ); _swsetup_CreateContext( ctx ); _ae_create_context( ctx ); /* Set the maximum texture size small enough that we can guarentee that * all texture units can bind a maximal texture and have all of them in * texturable memory at once. Depending on the allow_large_textures driconf * setting allow larger textures. */ ctx->Const.MaxTextureUnits = driQueryOptioni (&rmesa->radeon.optionCache, "texture_units"); ctx->Const.FragmentProgram.MaxTextureImageUnits = ctx->Const.MaxTextureUnits; ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits; ctx->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxTextureUnits; ctx->Const.StripTextureBorder = GL_TRUE; i = driQueryOptioni( &rmesa->radeon.optionCache, "allow_large_textures"); /* FIXME: When no memory manager is available we should set this * to some reasonable value based on texture memory pool size */ ctx->Const.MaxTextureLevels = 12; ctx->Const.Max3DTextureLevels = 9; ctx->Const.MaxCubeTextureLevels = 12; ctx->Const.MaxTextureRectSize = 2048; ctx->Const.MaxTextureMaxAnisotropy = 16.0; /* No wide points. */ ctx->Const.MinPointSize = 1.0; ctx->Const.MinPointSizeAA = 1.0; ctx->Const.MaxPointSize = 1.0; ctx->Const.MaxPointSizeAA = 1.0; ctx->Const.MinLineWidth = 1.0; ctx->Const.MinLineWidthAA = 1.0; ctx->Const.MaxLineWidth = 10.0; ctx->Const.MaxLineWidthAA = 10.0; ctx->Const.LineWidthGranularity = 0.0625; /* Set maxlocksize (and hence vb size) small enough to avoid * fallbacks in radeon_tcl.c. ie. guarentee that all vertices can * fit in a single dma buffer for indexed rendering of quad strips, * etc. */ ctx->Const.MaxArrayLockSize = MIN2( ctx->Const.MaxArrayLockSize, RADEON_BUFFER_SIZE / RADEON_MAX_TCL_VERTSIZE ); rmesa->boxes = 0; ctx->Const.MaxDrawBuffers = 1; ctx->Const.MaxColorAttachments = 1; ctx->Const.MaxRenderbufferSize = 2048; ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX].PreferDP4 = true; /* Install the customized pipeline: */ _tnl_destroy_pipeline( ctx ); _tnl_install_pipeline( ctx, radeon_pipeline ); /* Try and keep materials and vertices separate: */ /* _tnl_isolate_materials( ctx, GL_TRUE ); */ /* Configure swrast and T&L to match hardware characteristics: */ _swrast_allow_pixel_fog( ctx, GL_FALSE ); _swrast_allow_vertex_fog( ctx, GL_TRUE ); _tnl_allow_pixel_fog( ctx, GL_FALSE ); _tnl_allow_vertex_fog( ctx, GL_TRUE ); for ( i = 0 ; i < RADEON_MAX_TEXTURE_UNITS ; i++ ) { _math_matrix_ctr( &rmesa->TexGenMatrix[i] ); _math_matrix_ctr( &rmesa->tmpmat[i] ); _math_matrix_set_identity( &rmesa->TexGenMatrix[i] ); _math_matrix_set_identity( &rmesa->tmpmat[i] ); } ctx->Extensions.ARB_texture_border_clamp = true; ctx->Extensions.ARB_texture_env_combine = true; ctx->Extensions.ARB_texture_env_crossbar = true; ctx->Extensions.ARB_texture_env_dot3 = true; ctx->Extensions.EXT_fog_coord = true; ctx->Extensions.EXT_packed_depth_stencil = true; ctx->Extensions.EXT_secondary_color = true; ctx->Extensions.EXT_texture_env_dot3 = true; ctx->Extensions.EXT_texture_filter_anisotropic = true; ctx->Extensions.EXT_texture_mirror_clamp = true; ctx->Extensions.ATI_texture_env_combine3 = true; ctx->Extensions.ATI_texture_mirror_once = true; ctx->Extensions.MESA_ycbcr_texture = true; ctx->Extensions.NV_blend_square = true; ctx->Extensions.OES_EGL_image = true; ctx->Extensions.EXT_framebuffer_object = true; ctx->Extensions.ARB_texture_cube_map = true; if (rmesa->radeon.glCtx.Mesa_DXTn) { ctx->Extensions.EXT_texture_compression_s3tc = true; ctx->Extensions.ANGLE_texture_compression_dxt = true; } else if (driQueryOptionb (&rmesa->radeon.optionCache, "force_s3tc_enable")) { ctx->Extensions.EXT_texture_compression_s3tc = true; ctx->Extensions.ANGLE_texture_compression_dxt = true; } ctx->Extensions.NV_texture_rectangle = true; ctx->Extensions.ARB_occlusion_query = true; /* XXX these should really go right after _mesa_init_driver_functions() */ radeon_fbo_init(&rmesa->radeon); radeonInitSpanFuncs( ctx ); radeonInitIoctlFuncs( ctx ); radeonInitStateFuncs( ctx ); radeonInitState( rmesa ); radeonInitSwtcl( ctx ); _mesa_vector4f_alloc( &rmesa->tcl.ObjClean, 0, ctx->Const.MaxArrayLockSize, 32 ); fthrottle_mode = driQueryOptioni(&rmesa->radeon.optionCache, "fthrottle_mode"); rmesa->radeon.iw.irq_seq = -1; rmesa->radeon.irqsEmitted = 0; rmesa->radeon.do_irqs = (rmesa->radeon.radeonScreen->irq != 0 && fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS); rmesa->radeon.do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS); #if DO_DEBUG RADEON_DEBUG = driParseDebugString( getenv( "RADEON_DEBUG" ), debug_control ); #endif tcl_mode = driQueryOptioni(&rmesa->radeon.optionCache, "tcl_mode"); if (driQueryOptionb(&rmesa->radeon.optionCache, "no_rast")) { fprintf(stderr, "disabling 3D acceleration\n"); FALLBACK(rmesa, RADEON_FALLBACK_DISABLE, 1); } else if (tcl_mode == DRI_CONF_TCL_SW || !(rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL)) { if (rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL) { rmesa->radeon.radeonScreen->chip_flags &= ~RADEON_CHIPSET_TCL; fprintf(stderr, "Disabling HW TCL support\n"); } TCL_FALLBACK(&rmesa->radeon.glCtx, RADEON_TCL_FALLBACK_TCL_DISABLE, 1); } if (rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL) { /* _tnl_need_dlist_norm_lengths( ctx, GL_FALSE ); */ } _mesa_compute_version(ctx); /* Exec table initialization requires the version to be computed */ _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); *error = __DRI_CTX_ERROR_SUCCESS; return GL_TRUE; }
static GLboolean dri_create_context(gl_api api, const struct gl_config * visual, __DRIcontext * cPriv, unsigned major_version, unsigned minor_version, uint32_t flags, bool notify_reset, unsigned *error, void *sharedContextPrivate) { struct dri_context *ctx = NULL; struct dri_context *share = (struct dri_context *)sharedContextPrivate; struct gl_context *mesaCtx = NULL; struct gl_context *sharedCtx = NULL; struct dd_function_table functions; TRACE; /* Flag filtering is handled in dri2CreateContextAttribs. */ (void) flags; ctx = CALLOC_STRUCT(dri_context); if (ctx == NULL) { *error = __DRI_CTX_ERROR_NO_MEMORY; goto context_fail; } cPriv->driverPrivate = ctx; ctx->cPriv = cPriv; /* build table of device driver functions */ _mesa_init_driver_functions(&functions); swrast_init_driver_functions(&functions); if (share) { sharedCtx = &share->Base; } mesaCtx = &ctx->Base; /* basic context setup */ if (!_mesa_initialize_context(mesaCtx, api, visual, sharedCtx, &functions)) { *error = __DRI_CTX_ERROR_NO_MEMORY; goto context_fail; } driContextSetFlags(mesaCtx, flags); /* create module contexts */ _swrast_CreateContext( mesaCtx ); _vbo_CreateContext( mesaCtx ); _tnl_CreateContext( mesaCtx ); _swsetup_CreateContext( mesaCtx ); _swsetup_Wakeup( mesaCtx ); /* use default TCL pipeline */ { TNLcontext *tnl = TNL_CONTEXT(mesaCtx); tnl->Driver.RunPipeline = _tnl_run_pipeline; } _mesa_meta_init(mesaCtx); _mesa_enable_sw_extensions(mesaCtx); _mesa_compute_version(mesaCtx); _mesa_initialize_dispatch_tables(mesaCtx); _mesa_initialize_vbo_vtxfmt(mesaCtx); *error = __DRI_CTX_ERROR_SUCCESS; return GL_TRUE; context_fail: free(ctx); return GL_FALSE; }
bool brwCreateContext(int api, const struct gl_config *mesaVis, __DRIcontext *driContextPriv, unsigned major_version, unsigned minor_version, uint32_t flags, unsigned *error, void *sharedContextPrivate) { __DRIscreen *sPriv = driContextPriv->driScreenPriv; struct intel_screen *screen = sPriv->driverPrivate; struct dd_function_table functions; struct brw_context *brw = rzalloc(NULL, struct brw_context); if (!brw) { printf("%s: failed to alloc context\n", __FUNCTION__); *error = __DRI_CTX_ERROR_NO_MEMORY; return false; } /* brwInitVtbl needs to know the chipset generation so that it can set the * right pointers. */ brw->gen = screen->gen; brwInitVtbl( brw ); brwInitDriverFunctions(screen, &functions); struct gl_context *ctx = &brw->ctx; if (!intelInitContext( brw, api, major_version, minor_version, mesaVis, driContextPriv, sharedContextPrivate, &functions, error)) { ralloc_free(brw); return false; } brw_initialize_context_constants(brw); /* Reinitialize the context point state. It depends on ctx->Const values. */ _mesa_init_point(ctx); if (brw->gen >= 6) { /* Create a new hardware context. Using a hardware context means that * our GPU state will be saved/restored on context switch, allowing us * to assume that the GPU is in the same state we left it in. * * This is required for transform feedback buffer offsets, query objects, * and also allows us to reduce how much state we have to emit. */ brw->hw_ctx = drm_intel_gem_context_create(brw->bufmgr); if (!brw->hw_ctx) { fprintf(stderr, "Gen6+ requires Kernel 3.6 or later.\n"); ralloc_free(brw); return false; } } brw_init_surface_formats(brw); /* Initialize swrast, tnl driver tables: */ TNLcontext *tnl = TNL_CONTEXT(ctx); if (tnl) tnl->Driver.RunPipeline = _tnl_run_pipeline; ctx->DriverFlags.NewTransformFeedback = BRW_NEW_TRANSFORM_FEEDBACK; ctx->DriverFlags.NewRasterizerDiscard = BRW_NEW_RASTERIZER_DISCARD; ctx->DriverFlags.NewUniformBuffer = BRW_NEW_UNIFORM_BUFFER; if (brw->is_g4x || brw->gen >= 5) { brw->CMD_VF_STATISTICS = GM45_3DSTATE_VF_STATISTICS; brw->CMD_PIPELINE_SELECT = CMD_PIPELINE_SELECT_GM45; brw->has_surface_tile_offset = true; if (brw->gen < 6) brw->has_compr4 = true; brw->has_aa_line_parameters = true; brw->has_pln = true; } else { brw->CMD_VF_STATISTICS = GEN4_3DSTATE_VF_STATISTICS; brw->CMD_PIPELINE_SELECT = CMD_PIPELINE_SELECT_965; } /* WM maximum threads is number of EUs times number of threads per EU. */ assert(brw->gen <= 7); if (brw->is_haswell) { if (brw->gt == 1) { brw->max_wm_threads = 102; brw->max_vs_threads = 70; brw->max_gs_threads = 70; brw->urb.size = 128; brw->urb.min_vs_entries = 32; brw->urb.max_vs_entries = 640; brw->urb.max_gs_entries = 256; } else if (brw->gt == 2) { brw->max_wm_threads = 204; brw->max_vs_threads = 280; brw->max_gs_threads = 256; brw->urb.size = 256; brw->urb.min_vs_entries = 64; brw->urb.max_vs_entries = 1664; brw->urb.max_gs_entries = 640; } else if (brw->gt == 3) { brw->max_wm_threads = 408; brw->max_vs_threads = 280; brw->max_gs_threads = 256; brw->urb.size = 512; brw->urb.min_vs_entries = 64; brw->urb.max_vs_entries = 1664; brw->urb.max_gs_entries = 640; } } else if (brw->gen == 7) { if (brw->gt == 1) { brw->max_wm_threads = 48; brw->max_vs_threads = 36; brw->max_gs_threads = 36; brw->urb.size = 128; brw->urb.min_vs_entries = 32; brw->urb.max_vs_entries = 512; brw->urb.max_gs_entries = 192; } else if (brw->gt == 2) { brw->max_wm_threads = 172; brw->max_vs_threads = 128; brw->max_gs_threads = 128; brw->urb.size = 256; brw->urb.min_vs_entries = 32; brw->urb.max_vs_entries = 704; brw->urb.max_gs_entries = 320; } else { assert(!"Unknown gen7 device."); } } else if (brw->gen == 6) { if (brw->gt == 2) { brw->max_wm_threads = 80; brw->max_vs_threads = 60; brw->max_gs_threads = 60; brw->urb.size = 64; /* volume 5c.5 section 5.1 */ brw->urb.min_vs_entries = 24; brw->urb.max_vs_entries = 256; /* volume 2a (see 3DSTATE_URB) */ brw->urb.max_gs_entries = 256; } else { brw->max_wm_threads = 40; brw->max_vs_threads = 24; brw->max_gs_threads = 21; /* conservative; 24 if rendering disabled */ brw->urb.size = 32; /* volume 5c.5 section 5.1 */ brw->urb.min_vs_entries = 24; brw->urb.max_vs_entries = 256; /* volume 2a (see 3DSTATE_URB) */ brw->urb.max_gs_entries = 256; } brw->urb.gen6_gs_previously_active = false; } else if (brw->gen == 5) { brw->urb.size = 1024; brw->max_vs_threads = 72; brw->max_gs_threads = 32; brw->max_wm_threads = 12 * 6; } else if (brw->is_g4x) { brw->urb.size = 384; brw->max_vs_threads = 32; brw->max_gs_threads = 2; brw->max_wm_threads = 10 * 5; } else if (brw->gen < 6) { brw->urb.size = 256; brw->max_vs_threads = 16; brw->max_gs_threads = 2; brw->max_wm_threads = 8 * 4; brw->has_negative_rhw_bug = true; } if (brw->gen <= 7) { brw->needs_unlit_centroid_workaround = true; } brw->prim_restart.in_progress = false; brw->prim_restart.enable_cut_index = false; brw_init_state( brw ); if (brw->gen < 6) { brw->curbe.last_buf = calloc(1, 4096); brw->curbe.next_buf = calloc(1, 4096); } brw->state.dirty.mesa = ~0; brw->state.dirty.brw = ~0; /* Make sure that brw->state.dirty.brw has enough bits to hold all possible * dirty flags. */ STATIC_ASSERT(BRW_NUM_STATE_BITS <= 8 * sizeof(brw->state.dirty.brw)); brw->emit_state_always = 0; brw->batch.need_workaround_flush = true; ctx->VertexProgram._MaintainTnlProgram = true; ctx->FragmentProgram._MaintainTexEnvProgram = true; brw_draw_init( brw ); brw->precompile = driQueryOptionb(&brw->optionCache, "shader_precompile"); ctx->Const.ContextFlags = 0; if ((flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0) ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT; ctx->Debug.DebugOutput = GL_FALSE; if ((flags & __DRI_CTX_FLAG_DEBUG) != 0) { ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT; ctx->Debug.DebugOutput = GL_TRUE; /* Turn on some extra GL_ARB_debug_output generation. */ brw->perf_debug = true; } brw_fs_alloc_reg_sets(brw); brw_vec4_alloc_reg_set(brw); if (INTEL_DEBUG & DEBUG_SHADER_TIME) brw_init_shader_time(brw); _mesa_compute_version(ctx); _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); return true; }
static GLboolean dri_create_context(gl_api api, const struct gl_config * visual, __DRIcontext * cPriv, unsigned major_version, unsigned minor_version, uint32_t flags, unsigned *error, void *sharedContextPrivate) { struct dri_context *ctx = NULL; struct dri_context *share = (struct dri_context *)sharedContextPrivate; struct gl_context *mesaCtx = NULL; struct gl_context *sharedCtx = NULL; struct dd_function_table functions; TRACE; /* Flag filtering is handled in dri2CreateContextAttribs. */ (void) flags; switch (api) { case API_OPENGL_COMPAT: if (major_version > 2 || (major_version == 2 && minor_version > 1)) { *error = __DRI_CTX_ERROR_BAD_VERSION; return GL_FALSE; } break; case API_OPENGLES: case API_OPENGLES2: break; case API_OPENGL_CORE: *error = __DRI_CTX_ERROR_BAD_API; return GL_FALSE; } ctx = CALLOC_STRUCT(dri_context); if (ctx == NULL) { *error = __DRI_CTX_ERROR_NO_MEMORY; goto context_fail; } cPriv->driverPrivate = ctx; ctx->cPriv = cPriv; /* build table of device driver functions */ _mesa_init_driver_functions(&functions); swrast_init_driver_functions(&functions); if (share) { sharedCtx = &share->Base; } mesaCtx = &ctx->Base; /* basic context setup */ if (!_mesa_initialize_context(mesaCtx, api, visual, sharedCtx, &functions)) { *error = __DRI_CTX_ERROR_NO_MEMORY; goto context_fail; } /* do bounds checking to prevent segfaults and server crashes! */ mesaCtx->Const.CheckArrayBounds = GL_TRUE; /* create module contexts */ _swrast_CreateContext( mesaCtx ); _vbo_CreateContext( mesaCtx ); _tnl_CreateContext( mesaCtx ); _swsetup_CreateContext( mesaCtx ); _swsetup_Wakeup( mesaCtx ); /* use default TCL pipeline */ { TNLcontext *tnl = TNL_CONTEXT(mesaCtx); tnl->Driver.RunPipeline = _tnl_run_pipeline; } _mesa_meta_init(mesaCtx); _mesa_enable_sw_extensions(mesaCtx); _mesa_compute_version(mesaCtx); _mesa_initialize_dispatch_tables(mesaCtx); _mesa_initialize_vbo_vtxfmt(mesaCtx); *error = __DRI_CTX_ERROR_SUCCESS; return GL_TRUE; context_fail: free(ctx); return GL_FALSE; }
static struct st_context * st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe, const struct st_config_options *options) { struct pipe_screen *screen = pipe->screen; uint i; struct st_context *st = ST_CALLOC_STRUCT( st_context ); st->options = *options; ctx->st = st; st->ctx = ctx; st->pipe = pipe; /* XXX: this is one-off, per-screen init: */ st_debug_init(); /* state tracker needs the VBO module */ _vbo_CreateContext(ctx); st->dirty.mesa = ~0; st->dirty.st = ~0; /* Create upload manager for vertex data for glBitmap, glDrawPixels, * glClear, etc. */ st->uploader = u_upload_create(st->pipe, 65536, PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_STREAM); if (!screen->get_param(screen, PIPE_CAP_USER_INDEX_BUFFERS)) { st->indexbuf_uploader = u_upload_create(st->pipe, 128 * 1024, PIPE_BIND_INDEX_BUFFER, PIPE_USAGE_STREAM); } if (!screen->get_param(screen, PIPE_CAP_USER_CONSTANT_BUFFERS)) st->constbuf_uploader = u_upload_create(pipe, 128 * 1024, PIPE_BIND_CONSTANT_BUFFER, PIPE_USAGE_STREAM); st->cso_context = cso_create_context(pipe); st_init_atoms( st ); st_init_bitmap(st); st_init_clear(st); st_init_draw( st ); /* Choose texture target for glDrawPixels, glBitmap, renderbuffers */ if (pipe->screen->get_param(pipe->screen, PIPE_CAP_NPOT_TEXTURES)) st->internal_target = PIPE_TEXTURE_2D; else st->internal_target = PIPE_TEXTURE_RECT; /* Vertex element objects used for drawing rectangles for glBitmap, * glDrawPixels, glClear, etc. */ for (i = 0; i < ARRAY_SIZE(st->velems_util_draw); i++) { memset(&st->velems_util_draw[i], 0, sizeof(struct pipe_vertex_element)); st->velems_util_draw[i].src_offset = i * 4 * sizeof(float); st->velems_util_draw[i].instance_divisor = 0; st->velems_util_draw[i].vertex_buffer_index = cso_get_aux_vertex_buffer_slot(st->cso_context); st->velems_util_draw[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; } /* we want all vertex data to be placed in buffer objects */ vbo_use_buffer_objects(ctx); /* make sure that no VBOs are left mapped when we're drawing. */ vbo_always_unmap_buffers(ctx); /* Need these flags: */ st->ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; st->ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; st->has_stencil_export = screen->get_param(screen, PIPE_CAP_SHADER_STENCIL_EXPORT); st->has_shader_model3 = screen->get_param(screen, PIPE_CAP_SM3); st->has_etc1 = screen->is_format_supported(screen, PIPE_FORMAT_ETC1_RGB8, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW); st->has_etc2 = screen->is_format_supported(screen, PIPE_FORMAT_ETC2_RGB8, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW); st->prefer_blit_based_texture_transfer = screen->get_param(screen, PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER); st->force_persample_in_shader = screen->get_param(screen, PIPE_CAP_SAMPLE_SHADING) && !screen->get_param(screen, PIPE_CAP_FORCE_PERSAMPLE_INTERP); st->has_shareable_shaders = screen->get_param(screen, PIPE_CAP_SHAREABLE_SHADERS); st->needs_texcoord_semantic = screen->get_param(screen, PIPE_CAP_TGSI_TEXCOORD); st->apply_texture_swizzle_to_border_color = !!(screen->get_param(screen, PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK) & (PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 | PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600)); st->has_time_elapsed = screen->get_param(screen, PIPE_CAP_QUERY_TIME_ELAPSED); st->has_half_float_packing = screen->get_param(screen, PIPE_CAP_TGSI_PACK_HALF_FLOAT); st->has_multi_draw_indirect = screen->get_param(screen, PIPE_CAP_MULTI_DRAW_INDIRECT); /* GL limits and extensions */ st_init_limits(st->pipe->screen, &ctx->Const, &ctx->Extensions); st_init_extensions(st->pipe->screen, &ctx->Const, &ctx->Extensions, &st->options, ctx->Mesa_DXTn); if (st_have_perfmon(st)) { ctx->Extensions.AMD_performance_monitor = GL_TRUE; } /* Enable shader-based fallbacks for ARB_color_buffer_float if needed. */ if (screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_UNCLAMPED)) { if (!screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_CLAMPED)) { st->clamp_vert_color_in_shader = GL_TRUE; } if (!screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMPED)) { st->clamp_frag_color_in_shader = GL_TRUE; } /* For drivers which cannot do color clamping, it's better to just * disable ARB_color_buffer_float in the core profile, because * the clamping is deprecated there anyway. */ if (ctx->API == API_OPENGL_CORE && (st->clamp_frag_color_in_shader || st->clamp_vert_color_in_shader)) { st->clamp_vert_color_in_shader = GL_FALSE; st->clamp_frag_color_in_shader = GL_FALSE; ctx->Extensions.ARB_color_buffer_float = GL_FALSE; } } /* called after _mesa_create_context/_mesa_init_point, fix default user * settable max point size up */ st->ctx->Point.MaxSize = MAX2(ctx->Const.MaxPointSize, ctx->Const.MaxPointSizeAA); /* For vertex shaders, make sure not to emit saturate when SM 3.0 is not supported */ ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].EmitNoSat = !st->has_shader_model3; if (!ctx->Extensions.ARB_gpu_shader5) { for (i = 0; i < MESA_SHADER_STAGES; i++) ctx->Const.ShaderCompilerOptions[i].EmitNoIndirectSampler = true; } /* Set which shader types can be compiled at link time. */ st->shader_has_one_variant[MESA_SHADER_VERTEX] = st->has_shareable_shaders && !st->clamp_vert_color_in_shader; st->shader_has_one_variant[MESA_SHADER_FRAGMENT] = st->has_shareable_shaders && !st->clamp_frag_color_in_shader && !st->force_persample_in_shader; st->shader_has_one_variant[MESA_SHADER_TESS_CTRL] = st->has_shareable_shaders; st->shader_has_one_variant[MESA_SHADER_TESS_EVAL] = st->has_shareable_shaders; st->shader_has_one_variant[MESA_SHADER_GEOMETRY] = st->has_shareable_shaders; _mesa_compute_version(ctx); if (ctx->Version == 0) { /* This can happen when a core profile was requested, but the driver * does not support some features of GL 3.1 or later. */ st_destroy_context_priv(st); return NULL; } _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); return st; }
GLboolean brwCreateContext(gl_api api, const struct gl_config *mesaVis, __DRIcontext *driContextPriv, unsigned major_version, unsigned minor_version, uint32_t flags, bool notify_reset, unsigned *dri_ctx_error, void *sharedContextPrivate) { __DRIscreen *sPriv = driContextPriv->driScreenPriv; struct gl_context *shareCtx = (struct gl_context *) sharedContextPrivate; struct intel_screen *screen = sPriv->driverPrivate; const struct brw_device_info *devinfo = screen->devinfo; struct dd_function_table functions; /* Only allow the __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS flag if the kernel * provides us with context reset notifications. */ uint32_t allowed_flags = __DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE; if (screen->has_context_reset_notification) allowed_flags |= __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS; if (flags & ~allowed_flags) { *dri_ctx_error = __DRI_CTX_ERROR_UNKNOWN_FLAG; return false; } struct brw_context *brw = rzalloc(NULL, struct brw_context); if (!brw) { fprintf(stderr, "%s: failed to alloc context\n", __FUNCTION__); *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY; return false; } driContextPriv->driverPrivate = brw; brw->driContext = driContextPriv; brw->intelScreen = screen; brw->bufmgr = screen->bufmgr; brw->gen = devinfo->gen; brw->gt = devinfo->gt; brw->is_g4x = devinfo->is_g4x; brw->is_baytrail = devinfo->is_baytrail; brw->is_haswell = devinfo->is_haswell; brw->has_llc = devinfo->has_llc; brw->has_hiz = devinfo->has_hiz_and_separate_stencil; brw->has_separate_stencil = devinfo->has_hiz_and_separate_stencil; brw->has_pln = devinfo->has_pln; brw->has_compr4 = devinfo->has_compr4; brw->has_surface_tile_offset = devinfo->has_surface_tile_offset; brw->has_negative_rhw_bug = devinfo->has_negative_rhw_bug; brw->needs_unlit_centroid_workaround = devinfo->needs_unlit_centroid_workaround; brw->must_use_separate_stencil = screen->hw_must_use_separate_stencil; brw->has_swizzling = screen->hw_has_swizzling; brw->vs.base.stage = MESA_SHADER_VERTEX; brw->gs.base.stage = MESA_SHADER_GEOMETRY; brw->wm.base.stage = MESA_SHADER_FRAGMENT; if (brw->gen >= 8) { gen8_init_vtable_surface_functions(brw); gen7_init_vtable_sampler_functions(brw); brw->vtbl.emit_depth_stencil_hiz = gen8_emit_depth_stencil_hiz; } else if (brw->gen >= 7) { gen7_init_vtable_surface_functions(brw); gen7_init_vtable_sampler_functions(brw); brw->vtbl.emit_depth_stencil_hiz = gen7_emit_depth_stencil_hiz; } else { gen4_init_vtable_surface_functions(brw); gen4_init_vtable_sampler_functions(brw); brw->vtbl.emit_depth_stencil_hiz = brw_emit_depth_stencil_hiz; } brw_init_driver_functions(brw, &functions); if (notify_reset) functions.GetGraphicsResetStatus = brw_get_graphics_reset_status; struct gl_context *ctx = &brw->ctx; if (!_mesa_initialize_context(ctx, api, mesaVis, shareCtx, &functions)) { *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY; fprintf(stderr, "%s: failed to init mesa context\n", __FUNCTION__); intelDestroyContext(driContextPriv); return false; } driContextSetFlags(ctx, flags); /* Initialize the software rasterizer and helper modules. * * As of GL 3.1 core, the gen4+ driver doesn't need the swrast context for * software fallbacks (which we have to support on legacy GL to do weird * glDrawPixels(), glBitmap(), and other functions). */ if (api != API_OPENGL_CORE && api != API_OPENGLES2) { _swrast_CreateContext(ctx); } _vbo_CreateContext(ctx); if (ctx->swrast_context) { _tnl_CreateContext(ctx); TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline; _swsetup_CreateContext(ctx); /* Configure swrast to match hardware characteristics: */ _swrast_allow_pixel_fog(ctx, false); _swrast_allow_vertex_fog(ctx, true); } _mesa_meta_init(ctx); brw_process_driconf_options(brw); brw_process_intel_debug_variable(brw); brw_initialize_context_constants(brw); ctx->Const.ResetStrategy = notify_reset ? GL_LOSE_CONTEXT_ON_RESET_ARB : GL_NO_RESET_NOTIFICATION_ARB; /* Reinitialize the context point state. It depends on ctx->Const values. */ _mesa_init_point(ctx); intel_fbo_init(brw); intel_batchbuffer_init(brw); if (brw->gen >= 6) { /* Create a new hardware context. Using a hardware context means that * our GPU state will be saved/restored on context switch, allowing us * to assume that the GPU is in the same state we left it in. * * This is required for transform feedback buffer offsets, query objects, * and also allows us to reduce how much state we have to emit. */ brw->hw_ctx = drm_intel_gem_context_create(brw->bufmgr); if (!brw->hw_ctx) { fprintf(stderr, "Gen6+ requires Kernel 3.6 or later.\n"); intelDestroyContext(driContextPriv); return false; } } brw_init_state(brw); intelInitExtensions(ctx); brw_init_surface_formats(brw); brw->max_vs_threads = devinfo->max_vs_threads; brw->max_gs_threads = devinfo->max_gs_threads; brw->max_wm_threads = devinfo->max_wm_threads; brw->urb.size = devinfo->urb.size; brw->urb.min_vs_entries = devinfo->urb.min_vs_entries; brw->urb.max_vs_entries = devinfo->urb.max_vs_entries; brw->urb.max_gs_entries = devinfo->urb.max_gs_entries; /* Estimate the size of the mappable aperture into the GTT. There's an * ioctl to get the whole GTT size, but not one to get the mappable subset. * It turns out it's basically always 256MB, though some ancient hardware * was smaller. */ uint32_t gtt_size = 256 * 1024 * 1024; /* We don't want to map two objects such that a memcpy between them would * just fault one mapping in and then the other over and over forever. So * we would need to divide the GTT size by 2. Additionally, some GTT is * taken up by things like the framebuffer and the ringbuffer and such, so * be more conservative. */ brw->max_gtt_map_object_size = gtt_size / 4; if (brw->gen == 6) brw->urb.gen6_gs_previously_active = false; brw->prim_restart.in_progress = false; brw->prim_restart.enable_cut_index = false; brw->gs.enabled = false; if (brw->gen < 6) { brw->curbe.last_buf = calloc(1, 4096); brw->curbe.next_buf = calloc(1, 4096); } ctx->VertexProgram._MaintainTnlProgram = true; ctx->FragmentProgram._MaintainTexEnvProgram = true; brw_draw_init( brw ); if ((flags & __DRI_CTX_FLAG_DEBUG) != 0) { /* Turn on some extra GL_ARB_debug_output generation. */ brw->perf_debug = true; } if ((flags & __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS) != 0) ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB; if (INTEL_DEBUG & DEBUG_SHADER_TIME) brw_init_shader_time(brw); _mesa_compute_version(ctx); _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); if (ctx->Extensions.AMD_performance_monitor) { brw_init_performance_monitors(brw); } vbo_use_buffer_objects(ctx); vbo_always_unmap_buffers(ctx); return true; }
/* Create the device specific context. */ GLboolean r100CreateContext( gl_api api, const struct gl_config *glVisual, __DRIcontext *driContextPriv, const struct __DriverContextConfig *ctx_config, unsigned *error, void *sharedContextPrivate) { __DRIscreen *sPriv = driContextPriv->driScreenPriv; radeonScreenPtr screen = (radeonScreenPtr)(sPriv->driverPrivate); struct dd_function_table functions; r100ContextPtr rmesa; struct gl_context *ctx; int i; int tcl_mode, fthrottle_mode; if (ctx_config->flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_NO_ERROR)) { *error = __DRI_CTX_ERROR_UNKNOWN_FLAG; return false; } if (ctx_config->attribute_mask) { *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE; return false; } assert(driContextPriv); assert(screen); /* Allocate the Radeon context */ rmesa = calloc(1, sizeof(*rmesa)); if ( !rmesa ) { *error = __DRI_CTX_ERROR_NO_MEMORY; return GL_FALSE; } rmesa->radeon.radeonScreen = screen; r100_init_vtbl(&rmesa->radeon); /* init exp fog table data */ radeonInitStaticFogData(); /* Parse configuration files. * Do this here so that initialMaxAnisotropy is set before we create * the default textures. */ driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache, screen->driScreen->myNum, "radeon", NULL); rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache, "def_max_anisotropy"); if (driQueryOptionb(&rmesa->radeon.optionCache, "hyperz")) rmesa->using_hyperz = GL_TRUE; /* Init default driver functions then plug in our Radeon-specific functions * (the texture functions are especially important) */ _mesa_init_driver_functions( &functions ); _tnl_init_driver_draw_function( &functions ); radeonInitTextureFuncs( &rmesa->radeon, &functions ); radeonInitQueryObjFunctions(&functions); if (!radeonInitContext(&rmesa->radeon, api, &functions, glVisual, driContextPriv, sharedContextPrivate)) { free(rmesa); *error = __DRI_CTX_ERROR_NO_MEMORY; return GL_FALSE; } rmesa->radeon.swtcl.RenderIndex = ~0; rmesa->radeon.hw.all_dirty = GL_TRUE; ctx = &rmesa->radeon.glCtx; driContextSetFlags(ctx, ctx_config->flags); /* Initialize the software rasterizer and helper modules. */ _swrast_CreateContext( ctx ); _vbo_CreateContext( ctx ); _tnl_CreateContext( ctx ); _swsetup_CreateContext( ctx ); ctx->Const.MaxTextureUnits = driQueryOptioni (&rmesa->radeon.optionCache, "texture_units"); ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = ctx->Const.MaxTextureUnits; ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits; ctx->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxTextureUnits; ctx->Const.StripTextureBorder = GL_TRUE; /* FIXME: When no memory manager is available we should set this * to some reasonable value based on texture memory pool size */ ctx->Const.MaxTextureLevels = 12; ctx->Const.Max3DTextureLevels = 9; ctx->Const.MaxCubeTextureLevels = 12; ctx->Const.MaxTextureRectSize = 2048; ctx->Const.MaxTextureMaxAnisotropy = 16.0; /* No wide points. */ ctx->Const.MinPointSize = 1.0; ctx->Const.MinPointSizeAA = 1.0; ctx->Const.MaxPointSize = 1.0; ctx->Const.MaxPointSizeAA = 1.0; ctx->Const.MinLineWidth = 1.0; ctx->Const.MinLineWidthAA = 1.0; ctx->Const.MaxLineWidth = 10.0; ctx->Const.MaxLineWidthAA = 10.0; ctx->Const.LineWidthGranularity = 0.0625; /* Set maxlocksize (and hence vb size) small enough to avoid * fallbacks in radeon_tcl.c. ie. guarentee that all vertices can * fit in a single dma buffer for indexed rendering of quad strips, * etc. */ ctx->Const.MaxArrayLockSize = MIN2( ctx->Const.MaxArrayLockSize, RADEON_BUFFER_SIZE / RADEON_MAX_TCL_VERTSIZE ); rmesa->boxes = 0; ctx->Const.MaxDrawBuffers = 1; ctx->Const.MaxColorAttachments = 1; ctx->Const.MaxRenderbufferSize = 2048; ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].OptimizeForAOS = true; /* Install the customized pipeline: */ _tnl_destroy_pipeline( ctx ); _tnl_install_pipeline( ctx, radeon_pipeline ); /* Try and keep materials and vertices separate: */ /* _tnl_isolate_materials( ctx, GL_TRUE ); */ /* Configure swrast and T&L to match hardware characteristics: */ _swrast_allow_pixel_fog( ctx, GL_FALSE ); _swrast_allow_vertex_fog( ctx, GL_TRUE ); _tnl_allow_pixel_fog( ctx, GL_FALSE ); _tnl_allow_vertex_fog( ctx, GL_TRUE ); for ( i = 0 ; i < RADEON_MAX_TEXTURE_UNITS ; i++ ) { _math_matrix_ctr( &rmesa->TexGenMatrix[i] ); _math_matrix_ctr( &rmesa->tmpmat[i] ); _math_matrix_set_identity( &rmesa->TexGenMatrix[i] ); _math_matrix_set_identity( &rmesa->tmpmat[i] ); } ctx->Extensions.ARB_occlusion_query = true; ctx->Extensions.ARB_texture_border_clamp = true; ctx->Extensions.ARB_texture_cube_map = true; ctx->Extensions.ARB_texture_env_combine = true; ctx->Extensions.ARB_texture_env_crossbar = true; ctx->Extensions.ARB_texture_env_dot3 = true; ctx->Extensions.ARB_texture_filter_anisotropic = true; ctx->Extensions.ARB_texture_mirror_clamp_to_edge = true; ctx->Extensions.ATI_texture_env_combine3 = true; ctx->Extensions.ATI_texture_mirror_once = true; ctx->Extensions.EXT_texture_env_dot3 = true; ctx->Extensions.EXT_texture_filter_anisotropic = true; ctx->Extensions.EXT_texture_mirror_clamp = true; ctx->Extensions.MESA_ycbcr_texture = true; ctx->Extensions.NV_texture_rectangle = true; ctx->Extensions.OES_EGL_image = true; ctx->Extensions.EXT_texture_compression_s3tc = true; ctx->Extensions.ANGLE_texture_compression_dxt = true; /* XXX these should really go right after _mesa_init_driver_functions() */ radeon_fbo_init(&rmesa->radeon); radeonInitSpanFuncs( ctx ); radeonInitIoctlFuncs( ctx ); radeonInitStateFuncs( ctx ); radeonInitState( rmesa ); radeonInitSwtcl( ctx ); _mesa_vector4f_alloc( &rmesa->tcl.ObjClean, 0, ctx->Const.MaxArrayLockSize, 32 ); fthrottle_mode = driQueryOptioni(&rmesa->radeon.optionCache, "fthrottle_mode"); rmesa->radeon.iw.irq_seq = -1; rmesa->radeon.irqsEmitted = 0; rmesa->radeon.do_irqs = (rmesa->radeon.radeonScreen->irq != 0 && fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS); rmesa->radeon.do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS); tcl_mode = driQueryOptioni(&rmesa->radeon.optionCache, "tcl_mode"); if (getenv("RADEON_NO_RAST")) { fprintf(stderr, "disabling 3D acceleration\n"); FALLBACK(rmesa, RADEON_FALLBACK_DISABLE, 1); } else if (tcl_mode == DRI_CONF_TCL_SW || !(rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL)) { if (rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL) { rmesa->radeon.radeonScreen->chip_flags &= ~RADEON_CHIPSET_TCL; fprintf(stderr, "Disabling HW TCL support\n"); } TCL_FALLBACK(&rmesa->radeon.glCtx, RADEON_TCL_FALLBACK_TCL_DISABLE, 1); } if (rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL) { /* _tnl_need_dlist_norm_lengths( ctx, GL_FALSE ); */ } _mesa_override_extensions(ctx); _mesa_compute_version(ctx); /* Exec table initialization requires the version to be computed */ _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); *error = __DRI_CTX_ERROR_SUCCESS; return GL_TRUE; }
/** * New in Mesa 11.2 * * Create context with attribute list. */ GLAPI OSMesaContext GLAPIENTRY OSMesaCreateContextAttribs(const int *attribList, OSMesaContext sharelist) { OSMesaContext osmesa; struct dd_function_table functions; GLint rind, gind, bind, aind; GLint redBits = 0, greenBits = 0, blueBits = 0, alphaBits =0; GLenum format = OSMESA_RGBA; GLint depthBits = 0, stencilBits = 0, accumBits = 0; int profile = OSMESA_COMPAT_PROFILE, version_major = 1, version_minor = 0; gl_api api_profile = API_OPENGL_COMPAT; int i; for (i = 0; attribList[i]; i += 2) { switch (attribList[i]) { case OSMESA_FORMAT: format = attribList[i+1]; switch (format) { case OSMESA_COLOR_INDEX: case OSMESA_RGBA: case OSMESA_BGRA: case OSMESA_ARGB: case OSMESA_RGB: case OSMESA_BGR: case OSMESA_RGB_565: /* legal */ break; default: return NULL; } break; case OSMESA_DEPTH_BITS: depthBits = attribList[i+1]; if (depthBits < 0) return NULL; break; case OSMESA_STENCIL_BITS: stencilBits = attribList[i+1]; if (stencilBits < 0) return NULL; break; case OSMESA_ACCUM_BITS: accumBits = attribList[i+1]; if (accumBits < 0) return NULL; break; case OSMESA_PROFILE: profile = attribList[i+1]; if (profile == OSMESA_COMPAT_PROFILE) api_profile = API_OPENGL_COMPAT; else if (profile == OSMESA_CORE_PROFILE) api_profile = API_OPENGL_CORE; else return NULL; break; case OSMESA_CONTEXT_MAJOR_VERSION: version_major = attribList[i+1]; if (version_major < 1) return NULL; break; case OSMESA_CONTEXT_MINOR_VERSION: version_minor = attribList[i+1]; if (version_minor < 0) return NULL; break; case 0: /* end of list */ break; default: fprintf(stderr, "Bad attribute in OSMesaCreateContextAttribs()\n"); return NULL; } } rind = gind = bind = aind = 0; if (format==OSMESA_RGBA) { redBits = CHAN_BITS; greenBits = CHAN_BITS; blueBits = CHAN_BITS; alphaBits = CHAN_BITS; rind = 0; gind = 1; bind = 2; aind = 3; } else if (format==OSMESA_BGRA) { redBits = CHAN_BITS; greenBits = CHAN_BITS; blueBits = CHAN_BITS; alphaBits = CHAN_BITS; bind = 0; gind = 1; rind = 2; aind = 3; } else if (format==OSMESA_ARGB) { redBits = CHAN_BITS; greenBits = CHAN_BITS; blueBits = CHAN_BITS; alphaBits = CHAN_BITS; aind = 0; rind = 1; gind = 2; bind = 3; } else if (format==OSMESA_RGB) { redBits = CHAN_BITS; greenBits = CHAN_BITS; blueBits = CHAN_BITS; alphaBits = 0; rind = 0; gind = 1; bind = 2; } else if (format==OSMESA_BGR) { redBits = CHAN_BITS; greenBits = CHAN_BITS; blueBits = CHAN_BITS; alphaBits = 0; rind = 2; gind = 1; bind = 0; } #if CHAN_TYPE == GL_UNSIGNED_BYTE else if (format==OSMESA_RGB_565) { redBits = 5; greenBits = 6; blueBits = 5; alphaBits = 0; rind = 0; /* not used */ gind = 0; bind = 0; } #endif else { return NULL; } osmesa = (OSMesaContext) CALLOC_STRUCT(osmesa_context); if (osmesa) { osmesa->gl_visual = _mesa_create_visual( GL_FALSE, /* double buffer */ GL_FALSE, /* stereo */ redBits, greenBits, blueBits, alphaBits, depthBits, stencilBits, accumBits, accumBits, accumBits, alphaBits ? accumBits : 0, 1 /* num samples */ ); if (!osmesa->gl_visual) { free(osmesa); return NULL; } /* Initialize device driver function table */ _mesa_init_driver_functions(&functions); /* override with our functions */ functions.GetString = get_string; functions.UpdateState = osmesa_update_state_wrapper; if (!_mesa_initialize_context(&osmesa->mesa, api_profile, osmesa->gl_visual, sharelist ? &sharelist->mesa : (struct gl_context *) NULL, &functions)) { _mesa_destroy_visual( osmesa->gl_visual ); free(osmesa); return NULL; } _mesa_enable_sw_extensions(&(osmesa->mesa)); osmesa->gl_buffer = _mesa_create_framebuffer(osmesa->gl_visual); if (!osmesa->gl_buffer) { _mesa_destroy_visual( osmesa->gl_visual ); _mesa_free_context_data( &osmesa->mesa ); free(osmesa); return NULL; } /* Create depth/stencil/accum buffers. We'll create the color * buffer later in OSMesaMakeCurrent(). */ _swrast_add_soft_renderbuffers(osmesa->gl_buffer, GL_FALSE, /* color */ osmesa->gl_visual->haveDepthBuffer, osmesa->gl_visual->haveStencilBuffer, osmesa->gl_visual->haveAccumBuffer, GL_FALSE, /* alpha */ GL_FALSE /* aux */ ); osmesa->format = format; osmesa->userRowLength = 0; osmesa->yup = GL_TRUE; osmesa->rInd = rind; osmesa->gInd = gind; osmesa->bInd = bind; osmesa->aInd = aind; _mesa_meta_init(&osmesa->mesa); /* Initialize the software rasterizer and helper modules. */ { struct gl_context *ctx = &osmesa->mesa; SWcontext *swrast; TNLcontext *tnl; if (!_swrast_CreateContext( ctx ) || !_vbo_CreateContext( ctx ) || !_tnl_CreateContext( ctx ) || !_swsetup_CreateContext( ctx )) { _mesa_destroy_visual(osmesa->gl_visual); _mesa_free_context_data(ctx); free(osmesa); return NULL; } _swsetup_Wakeup( ctx ); /* use default TCL pipeline */ tnl = TNL_CONTEXT(ctx); tnl->Driver.RunPipeline = _tnl_run_pipeline; ctx->Driver.MapRenderbuffer = osmesa_MapRenderbuffer; ctx->Driver.UnmapRenderbuffer = osmesa_UnmapRenderbuffer; ctx->Driver.GenerateMipmap = _mesa_generate_mipmap; /* Extend the software rasterizer with our optimized line and triangle * drawing functions. */ swrast = SWRAST_CONTEXT( ctx ); swrast->choose_line = osmesa_choose_line; swrast->choose_triangle = osmesa_choose_triangle; _mesa_compute_version(ctx); if (ctx->Version < version_major * 10 + version_minor) { _mesa_destroy_visual(osmesa->gl_visual); _mesa_free_context_data(ctx); free(osmesa); return NULL; } /* Exec table initialization requires the version to be computed */ _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); } } return osmesa; }
/** * New in Mesa 3.5 * * Create context and specify size of ancillary buffers. */ GLAPI OSMesaContext GLAPIENTRY OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, OSMesaContext sharelist ) { OSMesaContext osmesa; struct dd_function_table functions; GLint rind, gind, bind, aind; GLint redBits = 0, greenBits = 0, blueBits = 0, alphaBits =0; rind = gind = bind = aind = 0; if (format==OSMESA_RGBA) { redBits = CHAN_BITS; greenBits = CHAN_BITS; blueBits = CHAN_BITS; alphaBits = CHAN_BITS; rind = 0; gind = 1; bind = 2; aind = 3; } else if (format==OSMESA_BGRA) { redBits = CHAN_BITS; greenBits = CHAN_BITS; blueBits = CHAN_BITS; alphaBits = CHAN_BITS; bind = 0; gind = 1; rind = 2; aind = 3; } else if (format==OSMESA_ARGB) { redBits = CHAN_BITS; greenBits = CHAN_BITS; blueBits = CHAN_BITS; alphaBits = CHAN_BITS; aind = 0; rind = 1; gind = 2; bind = 3; } else if (format==OSMESA_RGB) { redBits = CHAN_BITS; greenBits = CHAN_BITS; blueBits = CHAN_BITS; alphaBits = 0; rind = 0; gind = 1; bind = 2; } else if (format==OSMESA_BGR) { redBits = CHAN_BITS; greenBits = CHAN_BITS; blueBits = CHAN_BITS; alphaBits = 0; rind = 2; gind = 1; bind = 0; } #if CHAN_TYPE == GL_UNSIGNED_BYTE else if (format==OSMESA_RGB_565) { redBits = 5; greenBits = 6; blueBits = 5; alphaBits = 0; rind = 0; /* not used */ gind = 0; bind = 0; } #endif else { return NULL; } osmesa = (OSMesaContext) CALLOC_STRUCT(osmesa_context); if (osmesa) { osmesa->gl_visual = _mesa_create_visual( GL_FALSE, /* double buffer */ GL_FALSE, /* stereo */ redBits, greenBits, blueBits, alphaBits, depthBits, stencilBits, accumBits, accumBits, accumBits, alphaBits ? accumBits : 0, 1 /* num samples */ ); if (!osmesa->gl_visual) { free(osmesa); return NULL; } /* Initialize device driver function table */ _mesa_init_driver_functions(&functions); /* override with our functions */ functions.GetString = get_string; functions.UpdateState = osmesa_update_state; if (!_mesa_initialize_context(&osmesa->mesa, API_OPENGL_COMPAT, osmesa->gl_visual, sharelist ? &sharelist->mesa : (struct gl_context *) NULL, &functions)) { _mesa_destroy_visual( osmesa->gl_visual ); free(osmesa); return NULL; } _mesa_enable_sw_extensions(&(osmesa->mesa)); osmesa->gl_buffer = _mesa_create_framebuffer(osmesa->gl_visual); if (!osmesa->gl_buffer) { _mesa_destroy_visual( osmesa->gl_visual ); _mesa_free_context_data( &osmesa->mesa ); free(osmesa); return NULL; } /* Create depth/stencil/accum buffers. We'll create the color * buffer later in OSMesaMakeCurrent(). */ _swrast_add_soft_renderbuffers(osmesa->gl_buffer, GL_FALSE, /* color */ osmesa->gl_visual->haveDepthBuffer, osmesa->gl_visual->haveStencilBuffer, osmesa->gl_visual->haveAccumBuffer, GL_FALSE, /* alpha */ GL_FALSE /* aux */ ); osmesa->format = format; osmesa->userRowLength = 0; osmesa->yup = GL_TRUE; osmesa->rInd = rind; osmesa->gInd = gind; osmesa->bInd = bind; osmesa->aInd = aind; _mesa_meta_init(&osmesa->mesa); /* Initialize the software rasterizer and helper modules. */ { struct gl_context *ctx = &osmesa->mesa; SWcontext *swrast; TNLcontext *tnl; if (!_swrast_CreateContext( ctx ) || !_vbo_CreateContext( ctx ) || !_tnl_CreateContext( ctx ) || !_swsetup_CreateContext( ctx )) { _mesa_destroy_visual(osmesa->gl_visual); _mesa_free_context_data(ctx); free(osmesa); return NULL; } _swsetup_Wakeup( ctx ); /* use default TCL pipeline */ tnl = TNL_CONTEXT(ctx); tnl->Driver.RunPipeline = _tnl_run_pipeline; ctx->Driver.MapRenderbuffer = osmesa_MapRenderbuffer; ctx->Driver.UnmapRenderbuffer = osmesa_UnmapRenderbuffer; ctx->Driver.GenerateMipmap = _mesa_generate_mipmap; /* Extend the software rasterizer with our optimized line and triangle * drawing functions. */ swrast = SWRAST_CONTEXT( ctx ); swrast->choose_line = osmesa_choose_line; swrast->choose_triangle = osmesa_choose_triangle; _mesa_compute_version(ctx); /* Exec table initialization requires the version to be computed */ _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); } } return osmesa; }
/* Create the device specific rendering context. */ GLboolean r200CreateContext( gl_api api, const struct gl_config *glVisual, __DRIcontext *driContextPriv, unsigned major_version, unsigned minor_version, uint32_t flags, unsigned *error, void *sharedContextPrivate) { __DRIscreen *sPriv = driContextPriv->driScreenPriv; radeonScreenPtr screen = (radeonScreenPtr)(sPriv->driverPrivate); struct dd_function_table functions; r200ContextPtr rmesa; struct gl_context *ctx; int i; int tcl_mode; switch (api) { case API_OPENGL_COMPAT: if (major_version > 1 || minor_version > 3) { *error = __DRI_CTX_ERROR_BAD_VERSION; return GL_FALSE; } break; case API_OPENGLES: break; default: *error = __DRI_CTX_ERROR_BAD_API; return GL_FALSE; } /* Flag filtering is handled in dri2CreateContextAttribs. */ (void) flags; assert(glVisual); assert(driContextPriv); assert(screen); /* Allocate the R200 context */ rmesa = calloc(1, sizeof(*rmesa)); if ( !rmesa ) { *error = __DRI_CTX_ERROR_NO_MEMORY; return GL_FALSE; } rmesa->radeon.radeonScreen = screen; r200_init_vtbl(&rmesa->radeon); /* init exp fog table data */ radeonInitStaticFogData(); /* Parse configuration files. * Do this here so that initialMaxAnisotropy is set before we create * the default textures. */ driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache, screen->driScreen->myNum, "r200"); rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache, "def_max_anisotropy"); if ( sPriv->drm_version.major == 1 && driQueryOptionb( &rmesa->radeon.optionCache, "hyperz" ) ) { if ( sPriv->drm_version.minor < 13 ) fprintf( stderr, "DRM version 1.%d too old to support HyperZ, " "disabling.\n", sPriv->drm_version.minor ); else rmesa->using_hyperz = GL_TRUE; } if ( sPriv->drm_version.minor >= 15 ) rmesa->texmicrotile = GL_TRUE; /* Init default driver functions then plug in our R200-specific functions * (the texture functions are especially important) */ _mesa_init_driver_functions(&functions); r200InitDriverFuncs(&functions); r200InitIoctlFuncs(&functions); r200InitStateFuncs(&rmesa->radeon, &functions); r200InitTextureFuncs(&rmesa->radeon, &functions); r200InitShaderFuncs(&functions); radeonInitQueryObjFunctions(&functions); if (!radeonInitContext(&rmesa->radeon, &functions, glVisual, driContextPriv, sharedContextPrivate)) { free(rmesa); *error = __DRI_CTX_ERROR_NO_MEMORY; return GL_FALSE; } rmesa->radeon.swtcl.RenderIndex = ~0; rmesa->radeon.hw.all_dirty = 1; ctx = &rmesa->radeon.glCtx; /* Initialize the software rasterizer and helper modules. */ _swrast_CreateContext( ctx ); _vbo_CreateContext( ctx ); _tnl_CreateContext( ctx ); _swsetup_CreateContext( ctx ); _ae_create_context( ctx ); /* Set the maximum texture size small enough that we can guarentee that * all texture units can bind a maximal texture and have all of them in * texturable memory at once. Depending on the allow_large_textures driconf * setting allow larger textures. */ ctx->Const.MaxTextureUnits = driQueryOptioni (&rmesa->radeon.optionCache, "texture_units"); ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits; ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits; ctx->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxTextureUnits; ctx->Const.StripTextureBorder = GL_TRUE; i = driQueryOptioni( &rmesa->radeon.optionCache, "allow_large_textures"); /* FIXME: When no memory manager is available we should set this * to some reasonable value based on texture memory pool size */ ctx->Const.MaxTextureLevels = 12; ctx->Const.Max3DTextureLevels = 9; ctx->Const.MaxCubeTextureLevels = 12; ctx->Const.MaxTextureRectSize = 2048; ctx->Const.MaxRenderbufferSize = 2048; ctx->Const.MaxTextureMaxAnisotropy = 16.0; /* No wide AA points. */ ctx->Const.MinPointSize = 1.0; ctx->Const.MinPointSizeAA = 1.0; ctx->Const.MaxPointSizeAA = 1.0; ctx->Const.PointSizeGranularity = 0.0625; ctx->Const.MaxPointSize = 2047.0; /* mesa initialization problem - _mesa_init_point was already called */ ctx->Point.MaxSize = ctx->Const.MaxPointSize; ctx->Const.MinLineWidth = 1.0; ctx->Const.MinLineWidthAA = 1.0; ctx->Const.MaxLineWidth = 10.0; ctx->Const.MaxLineWidthAA = 10.0; ctx->Const.LineWidthGranularity = 0.0625; ctx->Const.VertexProgram.MaxNativeInstructions = R200_VSF_MAX_INST; ctx->Const.VertexProgram.MaxNativeAttribs = 12; ctx->Const.VertexProgram.MaxNativeTemps = R200_VSF_MAX_TEMPS; ctx->Const.VertexProgram.MaxNativeParameters = R200_VSF_MAX_PARAM; ctx->Const.VertexProgram.MaxNativeAddressRegs = 1; ctx->Const.MaxDrawBuffers = 1; ctx->Const.MaxColorAttachments = 1; _mesa_set_mvp_with_dp4( ctx, GL_TRUE ); /* Install the customized pipeline: */ _tnl_destroy_pipeline( ctx ); _tnl_install_pipeline( ctx, r200_pipeline ); /* Try and keep materials and vertices separate: */ /* _tnl_isolate_materials( ctx, GL_TRUE ); */ /* Configure swrast and TNL to match hardware characteristics: */ _swrast_allow_pixel_fog( ctx, GL_FALSE ); _swrast_allow_vertex_fog( ctx, GL_TRUE ); _tnl_allow_pixel_fog( ctx, GL_FALSE ); _tnl_allow_vertex_fog( ctx, GL_TRUE ); for ( i = 0 ; i < R200_MAX_TEXTURE_UNITS ; i++ ) { _math_matrix_ctr( &rmesa->TexGenMatrix[i] ); _math_matrix_set_identity( &rmesa->TexGenMatrix[i] ); } _math_matrix_ctr( &rmesa->tmpmat ); _math_matrix_set_identity( &rmesa->tmpmat ); ctx->Extensions.ARB_half_float_pixel = true; ctx->Extensions.ARB_occlusion_query = true; ctx->Extensions.ARB_texture_border_clamp = true; ctx->Extensions.ARB_texture_env_combine = true; ctx->Extensions.ARB_texture_env_dot3 = true; ctx->Extensions.ARB_texture_env_crossbar = true; ctx->Extensions.EXT_blend_color = true; ctx->Extensions.EXT_blend_minmax = true; ctx->Extensions.EXT_fog_coord = true; ctx->Extensions.EXT_packed_depth_stencil = true; ctx->Extensions.EXT_secondary_color = true; ctx->Extensions.EXT_texture_env_dot3 = true; ctx->Extensions.EXT_texture_filter_anisotropic = true; ctx->Extensions.EXT_texture_mirror_clamp = true; ctx->Extensions.ATI_texture_env_combine3 = true; ctx->Extensions.ATI_texture_mirror_once = true; ctx->Extensions.MESA_pack_invert = true; ctx->Extensions.NV_blend_square = true; ctx->Extensions.NV_texture_rectangle = true; ctx->Extensions.OES_EGL_image = true; ctx->Extensions.EXT_framebuffer_object = true; ctx->Extensions.ARB_occlusion_query = true; if (!(rmesa->radeon.radeonScreen->chip_flags & R200_CHIPSET_YCBCR_BROKEN)) { /* yuv textures don't work with some chips - R200 / rv280 okay so far others get the bit ordering right but don't actually do YUV-RGB conversion */ ctx->Extensions.MESA_ycbcr_texture = true; } if (rmesa->radeon.glCtx.Mesa_DXTn) { ctx->Extensions.EXT_texture_compression_s3tc = true; ctx->Extensions.ANGLE_texture_compression_dxt = true; } else if (driQueryOptionb (&rmesa->radeon.optionCache, "force_s3tc_enable")) { ctx->Extensions.EXT_texture_compression_s3tc = true; ctx->Extensions.ANGLE_texture_compression_dxt = true; } ctx->Extensions.ARB_texture_cube_map = true; ctx->Extensions.EXT_blend_equation_separate = true; ctx->Extensions.EXT_blend_func_separate = true; ctx->Extensions.ARB_vertex_program = true; ctx->Extensions.EXT_gpu_program_parameters = true; ctx->Extensions.ATI_fragment_shader = (ctx->Const.MaxTextureUnits == 6); ctx->Extensions.ARB_point_sprite = true; ctx->Extensions.EXT_point_parameters = true; #if 0 r200InitDriverFuncs( ctx ); r200InitIoctlFuncs( ctx ); r200InitStateFuncs( ctx ); r200InitTextureFuncs( ctx ); #endif /* plug in a few more device driver functions */ /* XXX these should really go right after _mesa_init_driver_functions() */ radeon_fbo_init(&rmesa->radeon); radeonInitSpanFuncs( ctx ); r200InitTnlFuncs( ctx ); r200InitState( rmesa ); r200InitSwtcl( ctx ); rmesa->prefer_gart_client_texturing = (getenv("R200_GART_CLIENT_TEXTURES") != 0); tcl_mode = driQueryOptioni(&rmesa->radeon.optionCache, "tcl_mode"); if (driQueryOptionb(&rmesa->radeon.optionCache, "no_rast")) { fprintf(stderr, "disabling 3D acceleration\n"); FALLBACK(rmesa, R200_FALLBACK_DISABLE, 1); } else if (tcl_mode == DRI_CONF_TCL_SW || getenv("R200_NO_TCL") || !(rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL)) { if (rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL) { rmesa->radeon.radeonScreen->chip_flags &= ~RADEON_CHIPSET_TCL; fprintf(stderr, "Disabling HW TCL support\n"); } TCL_FALLBACK(&rmesa->radeon.glCtx, R200_TCL_FALLBACK_TCL_DISABLE, 1); } _mesa_compute_version(ctx); /* Exec table initialization requires the version to be computed */ _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); *error = __DRI_CTX_ERROR_SUCCESS; return GL_TRUE; }
/** * Create a new XMesaContext. * \param v the XMesaVisual * \param share_list another XMesaContext with which to share display * lists or NULL if no sharing is wanted. * \return an XMesaContext or NULL if error. */ PUBLIC XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) { static GLboolean firstTime = GL_TRUE; XMesaContext c; struct gl_context *mesaCtx; struct dd_function_table functions; TNLcontext *tnl; if (firstTime) { _glthread_INIT_MUTEX(_xmesa_lock); firstTime = GL_FALSE; } /* Note: the XMesaContext contains a Mesa struct gl_context struct (inheritance) */ c = (XMesaContext) CALLOC_STRUCT(xmesa_context); if (!c) return NULL; mesaCtx = &(c->mesa); /* initialize with default driver functions, then plug in XMesa funcs */ _mesa_init_driver_functions(&functions); xmesa_init_driver_functions(v, &functions); if (!_mesa_initialize_context(mesaCtx, API_OPENGL_COMPAT, &v->mesa_visual, share_list ? &(share_list->mesa) : (struct gl_context *) NULL, &functions)) { free(c); return NULL; } /* Enable this to exercise fixed function -> shader translation * with software rendering. */ if (0) { mesaCtx->VertexProgram._MaintainTnlProgram = GL_TRUE; mesaCtx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; } _mesa_enable_sw_extensions(mesaCtx); _mesa_enable_1_3_extensions(mesaCtx); _mesa_enable_1_4_extensions(mesaCtx); _mesa_enable_1_5_extensions(mesaCtx); _mesa_enable_2_0_extensions(mesaCtx); _mesa_enable_2_1_extensions(mesaCtx); if (mesaCtx->Mesa_DXTn) { mesaCtx->Extensions.EXT_texture_compression_s3tc = GL_TRUE; mesaCtx->Extensions.ANGLE_texture_compression_dxt = GL_TRUE; } mesaCtx->Extensions.TDFX_texture_compression_FXT1 = GL_TRUE; #if ENABLE_EXT_timer_query mesaCtx->Extensions.EXT_timer_query = GL_TRUE; #endif /* finish up xmesa context initializations */ c->swapbytes = CHECK_BYTE_ORDER(v) ? GL_FALSE : GL_TRUE; c->xm_visual = v; c->xm_buffer = NULL; /* set later by XMesaMakeCurrent */ c->display = v->display; c->pixelformat = v->dithered_pf; /* Dithering is enabled by default */ /* Initialize the software rasterizer and helper modules. */ if (!_swrast_CreateContext( mesaCtx ) || !_vbo_CreateContext( mesaCtx ) || !_tnl_CreateContext( mesaCtx ) || !_swsetup_CreateContext( mesaCtx )) { _mesa_free_context_data(&c->mesa); free(c); return NULL; } /* tnl setup */ tnl = TNL_CONTEXT(mesaCtx); tnl->Driver.RunPipeline = _tnl_run_pipeline; /* swrast setup */ xmesa_register_swrast_functions( mesaCtx ); _swsetup_Wakeup(mesaCtx); _mesa_meta_init(mesaCtx); _mesa_compute_version(mesaCtx); /* Exec table initialization requires the version to be computed */ _mesa_initialize_dispatch_tables(mesaCtx); _mesa_initialize_vbo_vtxfmt(mesaCtx); return c; }
/* Create the device specific rendering context. */ GLboolean r200CreateContext( gl_api api, const struct gl_config *glVisual, __DRIcontext *driContextPriv, const struct __DriverContextConfig *ctx_config, unsigned *error, void *sharedContextPrivate) { __DRIscreen *sPriv = driContextPriv->driScreenPriv; radeonScreenPtr screen = (radeonScreenPtr)(sPriv->driverPrivate); struct dd_function_table functions; r200ContextPtr rmesa; struct gl_context *ctx; int i; int tcl_mode; if (ctx_config->flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_NO_ERROR)) { *error = __DRI_CTX_ERROR_UNKNOWN_FLAG; return false; } if (ctx_config->attribute_mask) { *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE; return false; } assert(driContextPriv); assert(screen); /* Allocate the R200 context */ rmesa = calloc(1, sizeof(*rmesa)); if ( !rmesa ) { *error = __DRI_CTX_ERROR_NO_MEMORY; return GL_FALSE; } rmesa->radeon.radeonScreen = screen; r200_init_vtbl(&rmesa->radeon); /* init exp fog table data */ radeonInitStaticFogData(); /* Parse configuration files. * Do this here so that initialMaxAnisotropy is set before we create * the default textures. */ driParseConfigFiles (&rmesa->radeon.optionCache, &screen->optionCache, screen->driScreen->myNum, "r200", NULL); rmesa->radeon.initialMaxAnisotropy = driQueryOptionf(&rmesa->radeon.optionCache, "def_max_anisotropy"); if (driQueryOptionb( &rmesa->radeon.optionCache, "hyperz")) rmesa->using_hyperz = GL_TRUE; /* Init default driver functions then plug in our R200-specific functions * (the texture functions are especially important) */ _mesa_init_driver_functions(&functions); _tnl_init_driver_draw_function(&functions); r200InitDriverFuncs(&functions); r200InitIoctlFuncs(&functions); r200InitStateFuncs(&rmesa->radeon, &functions); r200InitTextureFuncs(&rmesa->radeon, &functions); r200InitShaderFuncs(&functions); radeonInitQueryObjFunctions(&functions); if (!radeonInitContext(&rmesa->radeon, api, &functions, glVisual, driContextPriv, sharedContextPrivate)) { free(rmesa); *error = __DRI_CTX_ERROR_NO_MEMORY; return GL_FALSE; } rmesa->radeon.swtcl.RenderIndex = ~0; rmesa->radeon.hw.all_dirty = 1; ctx = &rmesa->radeon.glCtx; driContextSetFlags(ctx, ctx_config->flags); /* Initialize the software rasterizer and helper modules. */ _swrast_CreateContext( ctx ); _vbo_CreateContext( ctx ); _tnl_CreateContext( ctx ); _swsetup_CreateContext( ctx ); ctx->Const.MaxTextureUnits = driQueryOptioni (&rmesa->radeon.optionCache, "texture_units"); ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = ctx->Const.MaxTextureUnits; ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits; ctx->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxTextureUnits; ctx->Const.StripTextureBorder = GL_TRUE; /* FIXME: When no memory manager is available we should set this * to some reasonable value based on texture memory pool size */ ctx->Const.MaxTextureLevels = 12; ctx->Const.Max3DTextureLevels = 9; ctx->Const.MaxCubeTextureLevels = 12; ctx->Const.MaxTextureRectSize = 2048; ctx->Const.MaxRenderbufferSize = 2048; ctx->Const.MaxTextureMaxAnisotropy = 16.0; /* No wide AA points. */ ctx->Const.MinPointSize = 1.0; ctx->Const.MinPointSizeAA = 1.0; ctx->Const.MaxPointSizeAA = 1.0; ctx->Const.PointSizeGranularity = 0.0625; ctx->Const.MaxPointSize = 2047.0; /* mesa initialization problem - _mesa_init_point was already called */ ctx->Point.MaxSize = ctx->Const.MaxPointSize; ctx->Const.MinLineWidth = 1.0; ctx->Const.MinLineWidthAA = 1.0; ctx->Const.MaxLineWidth = 10.0; ctx->Const.MaxLineWidthAA = 10.0; ctx->Const.LineWidthGranularity = 0.0625; ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeInstructions = R200_VSF_MAX_INST; ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeAttribs = 12; ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeTemps = R200_VSF_MAX_TEMPS; ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeParameters = R200_VSF_MAX_PARAM; ctx->Const.Program[MESA_SHADER_VERTEX].MaxNativeAddressRegs = 1; ctx->Const.MaxDrawBuffers = 1; ctx->Const.MaxColorAttachments = 1; ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].OptimizeForAOS = GL_TRUE; /* Install the customized pipeline: */ _tnl_destroy_pipeline( ctx ); _tnl_install_pipeline( ctx, r200_pipeline ); /* Try and keep materials and vertices separate: */ /* _tnl_isolate_materials( ctx, GL_TRUE ); */ /* Configure swrast and TNL to match hardware characteristics: */ _swrast_allow_pixel_fog( ctx, GL_FALSE ); _swrast_allow_vertex_fog( ctx, GL_TRUE ); _tnl_allow_pixel_fog( ctx, GL_FALSE ); _tnl_allow_vertex_fog( ctx, GL_TRUE ); for ( i = 0 ; i < R200_MAX_TEXTURE_UNITS ; i++ ) { _math_matrix_ctr( &rmesa->TexGenMatrix[i] ); _math_matrix_set_identity( &rmesa->TexGenMatrix[i] ); } _math_matrix_ctr( &rmesa->tmpmat ); _math_matrix_set_identity( &rmesa->tmpmat ); ctx->Extensions.ARB_occlusion_query = true; ctx->Extensions.ARB_point_sprite = true; ctx->Extensions.ARB_texture_border_clamp = true; ctx->Extensions.ARB_texture_cube_map = true; ctx->Extensions.ARB_texture_env_combine = true; ctx->Extensions.ARB_texture_env_dot3 = true; ctx->Extensions.ARB_texture_env_crossbar = true; ctx->Extensions.ARB_texture_filter_anisotropic = true; ctx->Extensions.ARB_texture_mirror_clamp_to_edge = true; ctx->Extensions.ARB_vertex_program = true; ctx->Extensions.ATI_fragment_shader = (ctx->Const.MaxTextureUnits == 6); ctx->Extensions.ATI_texture_env_combine3 = true; ctx->Extensions.ATI_texture_mirror_once = true; ctx->Extensions.EXT_blend_color = true; ctx->Extensions.EXT_blend_equation_separate = true; ctx->Extensions.EXT_blend_func_separate = true; ctx->Extensions.EXT_blend_minmax = true; ctx->Extensions.EXT_gpu_program_parameters = true; ctx->Extensions.EXT_point_parameters = true; ctx->Extensions.EXT_texture_env_dot3 = true; ctx->Extensions.EXT_texture_filter_anisotropic = true; ctx->Extensions.EXT_texture_mirror_clamp = true; ctx->Extensions.MESA_pack_invert = true; ctx->Extensions.NV_fog_distance = true; ctx->Extensions.NV_texture_rectangle = true; ctx->Extensions.OES_EGL_image = true; if (!(rmesa->radeon.radeonScreen->chip_flags & R200_CHIPSET_YCBCR_BROKEN)) { /* yuv textures don't work with some chips - R200 / rv280 okay so far others get the bit ordering right but don't actually do YUV-RGB conversion */ ctx->Extensions.MESA_ycbcr_texture = true; } ctx->Extensions.EXT_texture_compression_s3tc = true; ctx->Extensions.ANGLE_texture_compression_dxt = true; #if 0 r200InitDriverFuncs( ctx ); r200InitIoctlFuncs( ctx ); r200InitStateFuncs( ctx ); r200InitTextureFuncs( ctx ); #endif /* plug in a few more device driver functions */ /* XXX these should really go right after _mesa_init_driver_functions() */ radeon_fbo_init(&rmesa->radeon); radeonInitSpanFuncs( ctx ); r200InitTnlFuncs( ctx ); r200InitState( rmesa ); r200InitSwtcl( ctx ); rmesa->prefer_gart_client_texturing = (getenv("R200_GART_CLIENT_TEXTURES") != 0); tcl_mode = driQueryOptioni(&rmesa->radeon.optionCache, "tcl_mode"); if (getenv("R200_NO_RAST")) { fprintf(stderr, "disabling 3D acceleration\n"); FALLBACK(rmesa, R200_FALLBACK_DISABLE, 1); } else if (tcl_mode == DRI_CONF_TCL_SW || getenv("R200_NO_TCL") || !(rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL)) { if (rmesa->radeon.radeonScreen->chip_flags & RADEON_CHIPSET_TCL) { rmesa->radeon.radeonScreen->chip_flags &= ~RADEON_CHIPSET_TCL; fprintf(stderr, "Disabling HW TCL support\n"); } TCL_FALLBACK(&rmesa->radeon.glCtx, R200_TCL_FALLBACK_TCL_DISABLE, 1); } _mesa_override_extensions(ctx); _mesa_compute_version(ctx); /* Exec table initialization requires the version to be computed */ _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); *error = __DRI_CTX_ERROR_SUCCESS; return GL_TRUE; }
bool i915CreateContext(int api, const struct gl_config * mesaVis, __DRIcontext * driContextPriv, unsigned major_version, unsigned minor_version, uint32_t flags, unsigned *error, void *sharedContextPrivate) { struct dd_function_table functions; struct i915_context *i915 = rzalloc(NULL, struct i915_context); struct intel_context *intel = &i915->intel; struct gl_context *ctx = &intel->ctx; if (!i915) { *error = __DRI_CTX_ERROR_NO_MEMORY; return false; } i915InitVtbl(i915); i915InitDriverFunctions(&functions); if (!intelInitContext(intel, api, major_version, minor_version, flags, mesaVis, driContextPriv, sharedContextPrivate, &functions, error)) { ralloc_free(i915); return false; } intel_init_texture_formats(ctx); _math_matrix_ctr(&intel->ViewportMatrix); /* Initialize swrast, tnl driver tables: */ intelInitTriFuncs(ctx); /* Install the customized pipeline: */ _tnl_destroy_pipeline(ctx); _tnl_install_pipeline(ctx, intel_pipeline); if (intel->no_rast) FALLBACK(intel, INTEL_FALLBACK_USER, 1); ctx->Const.MaxTextureUnits = I915_TEX_UNITS; ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits = I915_TEX_UNITS; ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits = I915_TEX_UNITS; ctx->Const.MaxTextureCoordUnits = I915_TEX_UNITS; ctx->Const.MaxVarying = I915_TEX_UNITS; ctx->Const.Program[MESA_SHADER_VERTEX].MaxOutputComponents = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = ctx->Const.MaxVarying * 4; ctx->Const.MaxCombinedTextureImageUnits = ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits + ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits; /* Advertise the full hardware capabilities. The new memory * manager should cope much better with overload situations: */ ctx->Const.MaxTextureSize = 2048; ctx->Const.Max3DTextureLevels = 9; ctx->Const.MaxCubeTextureLevels = 12; ctx->Const.MaxTextureRectSize = (1 << 11); ctx->Const.MaxTextureUnits = I915_TEX_UNITS; ctx->Const.MaxTextureMaxAnisotropy = 4.0; /* GL_ARB_fragment_program limits - don't think Mesa actually * validates programs against these, and in any case one ARB * instruction can translate to more than one HW instruction, so * we'll still have to check and fallback each time. */ ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeTemps = I915_MAX_TEMPORARY; ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeAttribs = 11; /* 8 tex, 2 color, fog */ ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeParameters = I915_MAX_CONSTANT; ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeAluInstructions = I915_MAX_ALU_INSN; ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeTexInstructions = I915_MAX_TEX_INSN; ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeInstructions = (I915_MAX_ALU_INSN + I915_MAX_TEX_INSN); ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeTexIndirections = I915_MAX_TEX_INDIRECT; ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeAddressRegs = 0; /* I don't think we have one */ ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxEnvParams = MIN2(ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxNativeParameters, ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxEnvParams); /* i915 stores all values in single-precision floats. Values aren't set * for other program targets because software is used for those targets. */ ctx->Const.Program[MESA_SHADER_FRAGMENT].MediumFloat.RangeMin = 127; ctx->Const.Program[MESA_SHADER_FRAGMENT].MediumFloat.RangeMax = 127; ctx->Const.Program[MESA_SHADER_FRAGMENT].MediumFloat.Precision = 23; ctx->Const.Program[MESA_SHADER_FRAGMENT].LowFloat = ctx->Const.Program[MESA_SHADER_FRAGMENT].HighFloat = ctx->Const.Program[MESA_SHADER_FRAGMENT].MediumFloat; ctx->Const.Program[MESA_SHADER_FRAGMENT].MediumInt.RangeMin = 24; ctx->Const.Program[MESA_SHADER_FRAGMENT].MediumInt.RangeMax = 24; ctx->Const.Program[MESA_SHADER_FRAGMENT].MediumInt.Precision = 0; ctx->Const.Program[MESA_SHADER_FRAGMENT].LowInt = ctx->Const.Program[MESA_SHADER_FRAGMENT].HighInt = ctx->Const.Program[MESA_SHADER_FRAGMENT].MediumInt; ctx->FragmentProgram._MaintainTexEnvProgram = true; /* FINISHME: Are there other options that should be enabled for software * FINISHME: vertex shaders? */ ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].EmitNoIndirectSampler = true; struct gl_shader_compiler_options *const fs_options = & ctx->Const.ShaderCompilerOptions[MESA_SHADER_FRAGMENT]; fs_options->MaxIfDepth = 0; fs_options->EmitNoPow = true; fs_options->EmitNoMainReturn = true; fs_options->EmitNoIndirectInput = true; fs_options->EmitNoIndirectOutput = true; fs_options->EmitNoIndirectUniform = true; fs_options->EmitNoIndirectTemp = true; fs_options->EmitNoIndirectSampler = true; ctx->Const.MaxDrawBuffers = 1; ctx->Const.QueryCounterBits.SamplesPassed = 0; _tnl_init_vertices(ctx, ctx->Const.MaxArrayLockSize + 12, 36 * sizeof(GLfloat)); intel->verts = TNL_CONTEXT(ctx)->clipspace.vertex_buf; i915InitState(i915); /* Always enable pixel fog. Vertex fog using fog coord will conflict * with fog code appended onto fragment program. */ _tnl_allow_vertex_fog(ctx, 0); _tnl_allow_pixel_fog(ctx, 1); _mesa_override_extensions(ctx); _mesa_compute_version(ctx); _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); return true; }