void nv30_draw_init(struct pipe_context *pipe) { struct nv30_context *nv30 = nv30_context(pipe); struct vbuf_render *render; struct draw_context *draw; struct draw_stage *stage; draw = draw_create(pipe); if (!draw) return; render = nv30_render_create(nv30); if (!render) { draw_destroy(draw); return; } stage = draw_vbuf_stage(draw, render); if (!stage) { render->destroy(render); draw_destroy(draw); return; } draw_set_render(draw, render); draw_set_rasterize_stage(draw, stage); draw_wide_line_threshold(draw, 10000000.f); draw_wide_point_threshold(draw, 10000000.f); draw_wide_point_sprites(draw, TRUE); nv30->draw = draw; }
struct pipe_context * softpipe_create_context( struct pipe_screen *screen, void *priv ) { struct softpipe_screen *sp_screen = softpipe_screen(screen); struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context); uint i, sh; util_init_math(); softpipe->dump_fs = debug_get_bool_option( "SOFTPIPE_DUMP_FS", FALSE ); softpipe->dump_gs = debug_get_bool_option( "SOFTPIPE_DUMP_GS", FALSE ); softpipe->pipe.screen = screen; softpipe->pipe.destroy = softpipe_destroy; softpipe->pipe.priv = priv; /* state setters */ softpipe_init_blend_funcs(&softpipe->pipe); softpipe_init_clip_funcs(&softpipe->pipe); softpipe_init_query_funcs( softpipe ); softpipe_init_rasterizer_funcs(&softpipe->pipe); softpipe_init_sampler_funcs(&softpipe->pipe); softpipe_init_shader_funcs(&softpipe->pipe); softpipe_init_streamout_funcs(&softpipe->pipe); softpipe_init_texture_funcs( &softpipe->pipe ); softpipe_init_vertex_funcs(&softpipe->pipe); softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; softpipe->pipe.draw_vbo = softpipe_draw_vbo; softpipe->pipe.clear = softpipe_clear; softpipe->pipe.flush = softpipe_flush_wrapped; softpipe->pipe.render_condition = softpipe_render_condition; softpipe->pipe.create_video_decoder = vl_create_decoder; softpipe->pipe.create_video_buffer = vl_video_buffer_create; /* * Alloc caches for accessing drawing surfaces and textures. * Must be before quad stage setup! */ for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) softpipe->cbuf_cache[i] = sp_create_tile_cache( &softpipe->pipe ); softpipe->zsbuf_cache = sp_create_tile_cache( &softpipe->pipe ); /* Allocate texture caches */ for (sh = 0; sh < Elements(softpipe->tex_cache); sh++) { for (i = 0; i < Elements(softpipe->tex_cache[0]); i++) { softpipe->tex_cache[sh][i] = sp_create_tex_tile_cache(&softpipe->pipe); if (!softpipe->tex_cache[sh][i]) goto fail; } } softpipe->fs_machine = tgsi_exec_machine_create(); /* setup quad rendering stages */ softpipe->quad.shade = sp_quad_shade_stage(softpipe); softpipe->quad.depth_test = sp_quad_depth_test_stage(softpipe); softpipe->quad.blend = sp_quad_blend_stage(softpipe); softpipe->quad.pstipple = sp_quad_polygon_stipple_stage(softpipe); /* * Create drawing context and plug our rendering stage into it. */ if (sp_screen->use_llvm) softpipe->draw = draw_create(&softpipe->pipe); else softpipe->draw = draw_create_no_llvm(&softpipe->pipe); if (!softpipe->draw) goto fail; draw_texture_samplers(softpipe->draw, PIPE_SHADER_VERTEX, PIPE_MAX_SAMPLERS, (struct tgsi_sampler **) softpipe->tgsi.samplers_list[PIPE_SHADER_VERTEX]); draw_texture_samplers(softpipe->draw, PIPE_SHADER_GEOMETRY, PIPE_MAX_SAMPLERS, (struct tgsi_sampler **) softpipe->tgsi.samplers_list[PIPE_SHADER_GEOMETRY]); if (debug_get_bool_option( "SOFTPIPE_NO_RAST", FALSE )) softpipe->no_rast = TRUE; softpipe->vbuf_backend = sp_create_vbuf_backend(softpipe); if (!softpipe->vbuf_backend) goto fail; softpipe->vbuf = draw_vbuf_stage(softpipe->draw, softpipe->vbuf_backend); if (!softpipe->vbuf) goto fail; draw_set_rasterize_stage(softpipe->draw, softpipe->vbuf); draw_set_render(softpipe->draw, softpipe->vbuf_backend); /* plug in AA line/point stages */ draw_install_aaline_stage(softpipe->draw, &softpipe->pipe); draw_install_aapoint_stage(softpipe->draw, &softpipe->pipe); /* Do polygon stipple w/ texture map + frag prog? */ #if DO_PSTIPPLE_IN_DRAW_MODULE draw_install_pstipple_stage(softpipe->draw, &softpipe->pipe); #endif draw_wide_point_sprites(softpipe->draw, TRUE); sp_init_surface_functions(softpipe); #if DO_PSTIPPLE_IN_HELPER_MODULE /* create the polgon stipple sampler */ softpipe->pstipple.sampler = util_pstipple_create_sampler(&softpipe->pipe); #endif return &softpipe->pipe; fail: softpipe_destroy(&softpipe->pipe); return NULL; }
struct pipe_context* r300_create_context(struct pipe_screen* screen, void *priv) { struct r300_context* r300 = CALLOC_STRUCT(r300_context); struct r300_screen* r300screen = r300_screen(screen); struct radeon_winsys *rws = r300screen->rws; if (!r300) return NULL; r300->rws = rws; r300->screen = r300screen; r300->context.screen = screen; r300->context.priv = priv; r300->context.destroy = r300_destroy_context; util_slab_create(&r300->pool_transfers, sizeof(struct pipe_transfer), 64, UTIL_SLAB_SINGLETHREADED); r300->cs = rws->cs_create(rws, RING_GFX, r300_flush_callback, r300, NULL); if (r300->cs == NULL) goto fail; if (!r300screen->caps.has_tcl) { /* Create a Draw. This is used for SW TCL. */ r300->draw = draw_create(&r300->context); if (r300->draw == NULL) goto fail; /* Enable our renderer. */ draw_set_rasterize_stage(r300->draw, r300_draw_stage(r300)); /* Disable converting points/lines to triangles. */ draw_wide_line_threshold(r300->draw, 10000000.f); draw_wide_point_threshold(r300->draw, 10000000.f); draw_wide_point_sprites(r300->draw, FALSE); draw_enable_line_stipple(r300->draw, TRUE); draw_enable_point_sprites(r300->draw, FALSE); } if (!r300_setup_atoms(r300)) goto fail; r300_init_blit_functions(r300); r300_init_flush_functions(r300); r300_init_query_functions(r300); r300_init_state_functions(r300); r300_init_resource_functions(r300); r300_init_render_functions(r300); r300_init_states(&r300->context); r300->context.create_video_codec = vl_create_decoder; r300->context.create_video_buffer = vl_video_buffer_create; r300->uploader = u_upload_create(&r300->context, 256 * 1024, 4, PIPE_BIND_CUSTOM); r300->blitter = util_blitter_create(&r300->context); if (r300->blitter == NULL) goto fail; r300->blitter->draw_rectangle = r300_blitter_draw_rectangle; /* The KIL opcode needs the first texture unit to be enabled * on r3xx-r4xx. In order to calm down the CS checker, we bind this * dummy texture there. */ if (!r300->screen->caps.is_r500) { struct pipe_resource *tex; struct pipe_resource rtempl = {{0}}; struct pipe_sampler_view vtempl = {{0}}; rtempl.target = PIPE_TEXTURE_2D; rtempl.format = PIPE_FORMAT_I8_UNORM; rtempl.usage = PIPE_USAGE_IMMUTABLE; rtempl.width0 = 1; rtempl.height0 = 1; rtempl.depth0 = 1; tex = screen->resource_create(screen, &rtempl); u_sampler_view_default_template(&vtempl, tex, tex->format); r300->texkill_sampler = (struct r300_sampler_view*) r300->context.create_sampler_view(&r300->context, tex, &vtempl); pipe_resource_reference(&tex, NULL); } if (r300screen->caps.has_tcl) { struct pipe_resource vb; memset(&vb, 0, sizeof(vb)); vb.target = PIPE_BUFFER; vb.format = PIPE_FORMAT_R8_UNORM; vb.usage = PIPE_USAGE_DEFAULT; vb.width0 = sizeof(float) * 16; vb.height0 = 1; vb.depth0 = 1; r300->dummy_vb.buffer = screen->resource_create(screen, &vb); r300->context.set_vertex_buffers(&r300->context, 0, 1, &r300->dummy_vb); } { struct pipe_depth_stencil_alpha_state dsa; memset(&dsa, 0, sizeof(dsa)); dsa.depth.writemask = 1; r300->dsa_decompress_zmask = r300->context.create_depth_stencil_alpha_state(&r300->context, &dsa); } r300->hyperz_time_of_last_flush = os_time_get(); /* Register allocator state */ rc_init_regalloc_state(&r300->fs_regalloc_state); /* Print driver info. */ #ifdef DEBUG { #else if (DBG_ON(r300, DBG_INFO)) { #endif fprintf(stderr, "r300: DRM version: %d.%d.%d, Name: %s, ID: 0x%04x, GB: %d, Z: %d\n" "r300: GART size: %"PRIu64" MB, VRAM size: %"PRIu64" MB\n" "r300: AA compression RAM: %s, Z compression RAM: %s, HiZ RAM: %s\n", r300->screen->info.drm_major, r300->screen->info.drm_minor, r300->screen->info.drm_patchlevel, screen->get_name(screen), r300->screen->info.pci_id, r300->screen->info.r300_num_gb_pipes, r300->screen->info.r300_num_z_pipes, r300->screen->info.gart_size >> 20, r300->screen->info.vram_size >> 20, "YES", /* XXX really? */ r300->screen->caps.zmask_ram ? "YES" : "NO", r300->screen->caps.hiz_ram ? "YES" : "NO"); } return &r300->context; fail: r300_destroy_context(&r300->context); return NULL; }
struct pipe_context * llvmpipe_create_context( struct pipe_screen *screen, void *priv ) { struct llvmpipe_context *llvmpipe; llvmpipe = align_malloc(sizeof(struct llvmpipe_context), 16); if (!llvmpipe) return NULL; util_init_math(); memset(llvmpipe, 0, sizeof *llvmpipe); make_empty_list(&llvmpipe->fs_variants_list); make_empty_list(&llvmpipe->setup_variants_list); llvmpipe->pipe.screen = screen; llvmpipe->pipe.priv = priv; /* Init the pipe context methods */ llvmpipe->pipe.destroy = llvmpipe_destroy; llvmpipe->pipe.set_framebuffer_state = llvmpipe_set_framebuffer_state; llvmpipe->pipe.clear = llvmpipe_clear; llvmpipe->pipe.flush = do_flush; llvmpipe->pipe.render_condition = llvmpipe_render_condition; llvmpipe_init_blend_funcs(llvmpipe); llvmpipe_init_clip_funcs(llvmpipe); llvmpipe_init_draw_funcs(llvmpipe); llvmpipe_init_sampler_funcs(llvmpipe); llvmpipe_init_query_funcs( llvmpipe ); llvmpipe_init_vertex_funcs(llvmpipe); llvmpipe_init_so_funcs(llvmpipe); llvmpipe_init_fs_funcs(llvmpipe); llvmpipe_init_vs_funcs(llvmpipe); llvmpipe_init_gs_funcs(llvmpipe); llvmpipe_init_rasterizer_funcs(llvmpipe); llvmpipe_init_context_resource_funcs( &llvmpipe->pipe ); llvmpipe_init_surface_functions(llvmpipe); /* * Create drawing context and plug our rendering stage into it. */ llvmpipe->draw = draw_create(&llvmpipe->pipe); if (!llvmpipe->draw) goto fail; /* FIXME: devise alternative to draw_texture_samplers */ llvmpipe->setup = lp_setup_create( &llvmpipe->pipe, llvmpipe->draw ); if (!llvmpipe->setup) goto fail; /* plug in AA line/point stages */ draw_install_aaline_stage(llvmpipe->draw, &llvmpipe->pipe); draw_install_aapoint_stage(llvmpipe->draw, &llvmpipe->pipe); draw_install_pstipple_stage(llvmpipe->draw, &llvmpipe->pipe); /* convert points and lines into triangles: * (otherwise, draw points and lines natively) */ draw_wide_point_sprites(llvmpipe->draw, FALSE); draw_enable_point_sprites(llvmpipe->draw, FALSE); draw_wide_point_threshold(llvmpipe->draw, 10000.0); draw_wide_line_threshold(llvmpipe->draw, 10000.0); lp_reset_counters(); return &llvmpipe->pipe; fail: llvmpipe_destroy(&llvmpipe->pipe); return NULL; }