void st_init_clear(struct st_context *st) { struct pipe_context *pipe = st->pipe; memset(&st->clear.raster, 0, sizeof(st->clear.raster)); st->clear.raster.gl_rasterization_rules = 1; /* rasterizer state: bypass vertex shader, clipping and viewport */ st->clear.raster.bypass_vs_clip_and_viewport = 1; /* fragment shader state: color pass-through program */ st->clear.fs = util_make_fragment_passthrough_shader(pipe); /* vertex shader state: color/position pass-through */ { const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_COLOR }; const uint semantic_indexes[] = { 0, 0 }; st->clear.vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names, semantic_indexes); } }
/** * Called via ctx->Driver.Bitmap() */ static void st_Bitmap(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap ) { struct st_context *st = st_context(ctx); struct pipe_resource *pt; if (width == 0 || height == 0) return; st_validate_state(st); if (!st->bitmap.vs) { /* create pass-through vertex shader now */ const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_COLOR, st->needs_texcoord_semantic ? TGSI_SEMANTIC_TEXCOORD : TGSI_SEMANTIC_GENERIC }; const uint semantic_indexes[] = { 0, 0, 0 }; st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3, semantic_names, semantic_indexes, FALSE); } if (UseBitmapCache && accum_bitmap(ctx, x, y, width, height, unpack, bitmap)) return; pt = make_bitmap_texture(ctx, width, height, unpack, bitmap); if (pt) { struct pipe_sampler_view *sv = st_create_texture_sampler_view(st->pipe, pt); assert(pt->target == PIPE_TEXTURE_2D || pt->target == PIPE_TEXTURE_RECT); if (sv) { draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2], width, height, sv, st->ctx->Current.RasterColor); pipe_sampler_view_reference(&sv, NULL); } /* release/free the texture */ pipe_resource_reference(&pt, NULL); } }
/** * Helper function to set the vertex shader. */ static INLINE void set_vertex_shader(struct blit_state *ctx) { /* vertex shader - still required to provide the linkage between * fragment shader input semantics and vertex_element/buffers. */ if (!ctx->vs) { const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_GENERIC }; const uint semantic_indexes[] = { 0, 0 }; ctx->vs = util_make_vertex_passthrough_shader(ctx->pipe, 2, semantic_names, semantic_indexes); } cso_set_vertex_shader_handle(ctx->cso, ctx->vs); }
static void * util_set_passthrough_vertex_shader(struct cso_context *cso, struct pipe_context *ctx, bool window_space) { static const uint vs_attribs[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_GENERIC }; static const uint vs_indices[] = {0, 0}; void *vs; vs = util_make_vertex_passthrough_shader(ctx, 2, vs_attribs, vs_indices, window_space); cso_set_vertex_shader_handle(cso, vs); return vs; }
/** * Helper function to set the vertex shader. */ static INLINE void set_vertex_shader(struct st_context *st) { /* vertex shader - still required to provide the linkage between * fragment shader input semantics and vertex_element/buffers. */ if (!st->clear.vs) { const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_COLOR }; const uint semantic_indexes[] = { 0, 0 }; st->clear.vs = util_make_vertex_passthrough_shader(st->pipe, 2, semantic_names, semantic_indexes); } cso_set_vertex_shader_handle(st->cso_context, st->clear.vs); }
static void * lookup_shader(struct pipe_context *pipe, uint num_attribs, const uint *semantic_names, const uint *semantic_indexes) { GLuint i, j; /* look for existing shader with same attributes */ for (i = 0; i < NumCachedShaders; i++) { if (CachedShaders[i].num_attribs == num_attribs) { GLboolean match = GL_TRUE; for (j = 0; j < num_attribs; j++) { if (semantic_names[j] != CachedShaders[i].semantic_names[j] || semantic_indexes[j] != CachedShaders[i].semantic_indexes[j]) { match = GL_FALSE; break; } } if (match) return CachedShaders[i].handle; } } /* not found - create new one now */ if (NumCachedShaders >= MAX_SHADERS) { return NULL; } CachedShaders[i].num_attribs = num_attribs; for (j = 0; j < num_attribs; j++) { CachedShaders[i].semantic_names[j] = semantic_names[j]; CachedShaders[i].semantic_indexes[j] = semantic_indexes[j]; } CachedShaders[i].handle = util_make_vertex_passthrough_shader(pipe, num_attribs, semantic_names, semantic_indexes, FALSE); NumCachedShaders++; return CachedShaders[i].handle; }
static void init_prog(struct program *p) { struct pipe_surface surf_tmpl; int ret; /* find a hardware device */ ret = pipe_loader_probe(&p->dev, 1); assert(ret); /* init a pipe screen */ p->screen = pipe_loader_create_screen(p->dev, PIPE_SEARCH_DIR); assert(p->screen); /* create the pipe driver context and cso context */ p->pipe = p->screen->context_create(p->screen, NULL); p->cso = cso_create_context(p->pipe); /* set clear color */ p->clear_color.f[0] = 0.3; p->clear_color.f[1] = 0.1; p->clear_color.f[2] = 0.3; p->clear_color.f[3] = 1.0; /* vertex buffer */ { float vertices[4][2][4] = { { { 0.0f, -0.9f, 0.0f, 1.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } }, { { -0.9f, 0.9f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } }, { { 0.9f, 0.9f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } } }; p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_STATIC, sizeof(vertices)); pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(vertices), vertices); } /* render target texture */ { struct pipe_resource tmplt; memset(&tmplt, 0, sizeof(tmplt)); tmplt.target = PIPE_TEXTURE_2D; tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */ tmplt.width0 = WIDTH; tmplt.height0 = HEIGHT; tmplt.depth0 = 1; tmplt.array_size = 1; tmplt.last_level = 0; tmplt.bind = PIPE_BIND_RENDER_TARGET; p->target = p->screen->resource_create(p->screen, &tmplt); } /* disabled blending/masking */ memset(&p->blend, 0, sizeof(p->blend)); p->blend.rt[0].colormask = PIPE_MASK_RGBA; /* no-op depth/stencil/alpha */ memset(&p->depthstencil, 0, sizeof(p->depthstencil)); /* rasterizer */ memset(&p->rasterizer, 0, sizeof(p->rasterizer)); p->rasterizer.cull_face = PIPE_FACE_NONE; p->rasterizer.gl_rasterization_rules = 1; p->rasterizer.depth_clip = 1; surf_tmpl.format = PIPE_FORMAT_B8G8R8A8_UNORM; surf_tmpl.usage = PIPE_BIND_RENDER_TARGET; surf_tmpl.u.tex.level = 0; surf_tmpl.u.tex.first_layer = 0; surf_tmpl.u.tex.last_layer = 0; /* drawing destination */ memset(&p->framebuffer, 0, sizeof(p->framebuffer)); p->framebuffer.width = WIDTH; p->framebuffer.height = HEIGHT; p->framebuffer.nr_cbufs = 1; p->framebuffer.cbufs[0] = p->pipe->create_surface(p->pipe, p->target, &surf_tmpl); /* viewport, depth isn't really needed */ { float x = 0; float y = 0; float z = FAR; float half_width = (float)WIDTH / 2.0f; float half_height = (float)HEIGHT / 2.0f; float half_depth = ((float)FAR - (float)NEAR) / 2.0f; float scale, bias; if (FLIP) { scale = -1.0f; bias = (float)HEIGHT; } else { scale = 1.0f; bias = 0.0f; } p->viewport.scale[0] = half_width; p->viewport.scale[1] = half_height * scale; p->viewport.scale[2] = half_depth; p->viewport.scale[3] = 1.0f; p->viewport.translate[0] = half_width + x; p->viewport.translate[1] = (half_height + y) * scale + bias; p->viewport.translate[2] = half_depth + z; p->viewport.translate[3] = 0.0f; } /* vertex elements state */ memset(p->velem, 0, sizeof(p->velem)); p->velem[0].src_offset = 0 * 4 * sizeof(float); /* offset 0, first element */ p->velem[0].instance_divisor = 0; p->velem[0].vertex_buffer_index = 0; p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; p->velem[1].src_offset = 1 * 4 * sizeof(float); /* offset 16, second element */ p->velem[1].instance_divisor = 0; p->velem[1].vertex_buffer_index = 0; p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; /* vertex shader */ { const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_COLOR }; const uint semantic_indexes[] = { 0, 0 }; p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes); } /* fragment shader */ p->fs = util_make_fragment_passthrough_shader(p->pipe); }
/** * One-time init for drawing bitmaps. */ static void init_bitmap_state(struct st_context *st) { struct pipe_context *pipe = st->pipe; struct pipe_screen *screen = pipe->screen; /* This function should only be called once */ assert(st->bitmap.cache == NULL); assert(st->internal_target == PIPE_TEXTURE_2D || st->internal_target == PIPE_TEXTURE_RECT); /* alloc bitmap cache object */ st->bitmap.cache = ST_CALLOC_STRUCT(bitmap_cache); /* init sampler state once */ memset(&st->bitmap.sampler, 0, sizeof(st->bitmap.sampler)); st->bitmap.sampler.wrap_s = PIPE_TEX_WRAP_CLAMP; st->bitmap.sampler.wrap_t = PIPE_TEX_WRAP_CLAMP; st->bitmap.sampler.wrap_r = PIPE_TEX_WRAP_CLAMP; st->bitmap.sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; st->bitmap.sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; st->bitmap.sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; st->bitmap.sampler.normalized_coords = st->internal_target == PIPE_TEXTURE_2D; st->bitmap.atlas_sampler = st->bitmap.sampler; st->bitmap.atlas_sampler.normalized_coords = 0; /* init baseline rasterizer state once */ memset(&st->bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer)); st->bitmap.rasterizer.half_pixel_center = 1; st->bitmap.rasterizer.bottom_edge_rule = 1; st->bitmap.rasterizer.depth_clip = 1; /* find a usable texture format */ if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, st->internal_target, 0, PIPE_BIND_SAMPLER_VIEW)) { st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM; } else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM, st->internal_target, 0, PIPE_BIND_SAMPLER_VIEW)) { st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM; } else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM, st->internal_target, 0, PIPE_BIND_SAMPLER_VIEW)) { st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM; } else { /* XXX support more formats */ assert(0); } /* Create the vertex shader */ { const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_COLOR, st->needs_texcoord_semantic ? TGSI_SEMANTIC_TEXCOORD : TGSI_SEMANTIC_GENERIC }; const uint semantic_indexes[] = { 0, 0, 0 }; st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3, semantic_names, semantic_indexes, FALSE); } reset_cache(st); }
static void init_prog(struct program *p) { struct pipe_surface surf_tmpl; int ret; /* find a hardware device */ ret = pipe_loader_probe(&p->dev, 1); assert(ret); /* init a pipe screen */ p->screen = pipe_loader_create_screen(p->dev, PIPE_SEARCH_DIR); assert(p->screen); /* create the pipe driver context and cso context */ p->pipe = p->screen->context_create(p->screen, NULL); p->cso = cso_create_context(p->pipe); /* set clear color */ p->clear_color.f[0] = 0.3; p->clear_color.f[1] = 0.1; p->clear_color.f[2] = 0.3; p->clear_color.f[3] = 1.0; /* vertex buffer */ { float vertices[4][2][4] = { { { 0.9f, 0.9f, 0.0f, 1.0f }, { 1.0f, 1.0f, 0.0f, 1.0f } }, { { -0.9f, 0.9f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } }, { { -0.9f, -0.9f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } }, { { 0.9f, -0.9f, 0.0f, 1.0f }, { 1.0f, 0.0f, 1.0f, 1.0f } } }; p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_DEFAULT, sizeof(vertices)); pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(vertices), vertices); } /* render target texture */ { struct pipe_resource tmplt; memset(&tmplt, 0, sizeof(tmplt)); tmplt.target = PIPE_TEXTURE_2D; tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */ tmplt.width0 = WIDTH; tmplt.height0 = HEIGHT; tmplt.depth0 = 1; tmplt.array_size = 1; tmplt.last_level = 0; tmplt.bind = PIPE_BIND_RENDER_TARGET; p->target = p->screen->resource_create(p->screen, &tmplt); } /* sampler texture */ { uint32_t *ptr; struct pipe_transfer *t; struct pipe_resource t_tmplt; struct pipe_sampler_view v_tmplt; struct pipe_box box; memset(&t_tmplt, 0, sizeof(t_tmplt)); t_tmplt.target = PIPE_TEXTURE_2D; t_tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */ t_tmplt.width0 = 2; t_tmplt.height0 = 2; t_tmplt.depth0 = 1; t_tmplt.array_size = 1; t_tmplt.last_level = 0; t_tmplt.bind = PIPE_BIND_RENDER_TARGET; p->tex = p->screen->resource_create(p->screen, &t_tmplt); memset(&box, 0, sizeof(box)); box.width = 2; box.height = 2; ptr = p->pipe->transfer_map(p->pipe, p->tex, 0, PIPE_TRANSFER_WRITE, &box, &t); ptr[0] = 0xffff0000; ptr[1] = 0xff0000ff; ptr[2] = 0xff00ff00; ptr[3] = 0xffffff00; p->pipe->transfer_unmap(p->pipe, t); u_sampler_view_default_template(&v_tmplt, p->tex, p->tex->format); p->view = p->pipe->create_sampler_view(p->pipe, p->tex, &v_tmplt); } /* disabled blending/masking */ memset(&p->blend, 0, sizeof(p->blend)); p->blend.rt[0].colormask = PIPE_MASK_RGBA; /* no-op depth/stencil/alpha */ memset(&p->depthstencil, 0, sizeof(p->depthstencil)); /* rasterizer */ memset(&p->rasterizer, 0, sizeof(p->rasterizer)); p->rasterizer.cull_face = PIPE_FACE_NONE; p->rasterizer.half_pixel_center = 1; p->rasterizer.bottom_edge_rule = 1; p->rasterizer.depth_clip = 1; /* sampler */ memset(&p->sampler, 0, sizeof(p->sampler)); p->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; p->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; p->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; p->sampler.min_img_filter = PIPE_TEX_MIPFILTER_LINEAR; p->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR; p->sampler.normalized_coords = 1; surf_tmpl.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */ surf_tmpl.u.tex.level = 0; surf_tmpl.u.tex.first_layer = 0; surf_tmpl.u.tex.last_layer = 0; /* drawing destination */ memset(&p->framebuffer, 0, sizeof(p->framebuffer)); p->framebuffer.width = WIDTH; p->framebuffer.height = HEIGHT; p->framebuffer.nr_cbufs = 1; p->framebuffer.cbufs[0] = p->pipe->create_surface(p->pipe, p->target, &surf_tmpl); /* viewport, depth isn't really needed */ { float x = 0; float y = 0; float z = FAR; float half_width = (float)WIDTH / 2.0f; float half_height = (float)HEIGHT / 2.0f; float half_depth = ((float)FAR - (float)NEAR) / 2.0f; float scale, bias; if (FLIP) { scale = -1.0f; bias = (float)HEIGHT; } else { scale = 1.0f; bias = 0.0f; } p->viewport.scale[0] = half_width; p->viewport.scale[1] = half_height * scale; p->viewport.scale[2] = half_depth; p->viewport.translate[0] = half_width + x; p->viewport.translate[1] = (half_height + y) * scale + bias; p->viewport.translate[2] = half_depth + z; } /* vertex elements state */ memset(p->velem, 0, sizeof(p->velem)); p->velem[0].src_offset = 0 * 4 * sizeof(float); /* offset 0, first element */ p->velem[0].instance_divisor = 0; p->velem[0].vertex_buffer_index = 0; p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; p->velem[1].src_offset = 1 * 4 * sizeof(float); /* offset 16, second element */ p->velem[1].instance_divisor = 0; p->velem[1].vertex_buffer_index = 0; p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; /* vertex shader */ { const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_GENERIC }; const uint semantic_indexes[] = { 0, 0 }; p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes, FALSE); } /* fragment shader */ p->fs = util_make_fragment_tex_shader(p->pipe, TGSI_TEXTURE_2D, TGSI_INTERPOLATE_LINEAR); }
/** Initialize the internal details */ struct program * pp_init_prog(struct pp_queue_t *ppq, struct pipe_screen *pscreen) { struct program *p; pp_debug("Initializing program\n"); if (!pscreen) return NULL; p = CALLOC(1, sizeof(struct program)); if (!p) return NULL; p->screen = pscreen; p->pipe = pscreen->context_create(pscreen, NULL); p->cso = cso_create_context(p->pipe); { static const float verts[4][2][4] = { { {1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f, 1.0f} }, { {-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f} }, { {-1.0f, -1.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f} }, { {1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f} } }; p->vbuf = pipe_buffer_create(pscreen, PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_STATIC, sizeof(verts)); pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(verts), verts); } p->blend.rt[0].colormask = PIPE_MASK_RGBA; p->blend.rt[0].rgb_src_factor = p->blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_SRC_ALPHA; p->blend.rt[0].rgb_dst_factor = p->blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_INV_SRC_ALPHA; p->rasterizer.cull_face = PIPE_FACE_NONE; p->rasterizer.gl_rasterization_rules = 1; p->sampler.wrap_s = p->sampler.wrap_t = p->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; p->sampler.min_img_filter = p->sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR; p->sampler.normalized_coords = 1; p->sampler_point.wrap_s = p->sampler_point.wrap_t = p->sampler_point.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; p->sampler_point.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; p->sampler_point.min_img_filter = p->sampler_point.mag_img_filter = PIPE_TEX_FILTER_NEAREST; p->sampler_point.normalized_coords = 1; p->velem[0].src_offset = 0; p->velem[0].instance_divisor = 0; p->velem[0].vertex_buffer_index = 0; p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; p->velem[1].src_offset = 1 * 4 * sizeof(float); p->velem[1].instance_divisor = 0; p->velem[1].vertex_buffer_index = 0; p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; if (!p->screen->is_format_supported(p->screen, PIPE_FORMAT_R32G32B32A32_FLOAT, PIPE_BUFFER, 1, PIPE_BIND_VERTEX_BUFFER)) pp_debug("Vertex buf format fail\n"); { const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_GENERIC }; const uint semantic_indexes[] = { 0, 0 }; p->passvs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes); } p->framebuffer.nr_cbufs = 1; p->surf.usage = PIPE_BIND_RENDER_TARGET; p->surf.format = PIPE_FORMAT_B8G8R8A8_UNORM; p->pipe->set_sample_mask(p->pipe, ~0); return p; }
struct st_context * st_context_create(struct st_device *st_dev) { struct st_context *st_ctx; st_ctx = CALLOC_STRUCT(st_context); if(!st_ctx) return NULL; st_device_reference(&st_ctx->st_dev, st_dev); st_ctx->real_pipe = st_dev->st_ws->context_create(st_dev->real_screen); if(!st_ctx->real_pipe) { st_context_destroy(st_ctx); return NULL; } st_ctx->pipe = trace_context_create(st_dev->screen, st_ctx->real_pipe); if(!st_ctx->pipe) { st_context_destroy(st_ctx); return NULL; } st_ctx->cso = cso_create_context(st_ctx->pipe); if(!st_ctx->cso) { st_context_destroy(st_ctx); return NULL; } /* disabled blending/masking */ { struct pipe_blend_state blend; memset(&blend, 0, sizeof(blend)); blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE; blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE; blend.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; blend.colormask = PIPE_MASK_RGBA; cso_set_blend(st_ctx->cso, &blend); } /* no-op depth/stencil/alpha */ { struct pipe_depth_stencil_alpha_state depthstencil; memset(&depthstencil, 0, sizeof(depthstencil)); cso_set_depth_stencil_alpha(st_ctx->cso, &depthstencil); } /* rasterizer */ { struct pipe_rasterizer_state rasterizer; memset(&rasterizer, 0, sizeof(rasterizer)); rasterizer.front_winding = PIPE_WINDING_CW; rasterizer.cull_mode = PIPE_WINDING_NONE; cso_set_rasterizer(st_ctx->cso, &rasterizer); } /* clip */ { struct pipe_clip_state clip; memset(&clip, 0, sizeof(clip)); st_ctx->pipe->set_clip_state(st_ctx->pipe, &clip); } /* identity viewport */ { struct pipe_viewport_state viewport; viewport.scale[0] = 1.0; viewport.scale[1] = 1.0; viewport.scale[2] = 1.0; viewport.scale[3] = 1.0; viewport.translate[0] = 0.0; viewport.translate[1] = 0.0; viewport.translate[2] = 0.0; viewport.translate[3] = 0.0; cso_set_viewport(st_ctx->cso, &viewport); } /* samplers */ { struct pipe_sampler_state sampler; unsigned i; memset(&sampler, 0, sizeof(sampler)); sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST; sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST; sampler.normalized_coords = 1; for (i = 0; i < PIPE_MAX_SAMPLERS; i++) cso_single_sampler(st_ctx->cso, i, &sampler); cso_single_sampler_done(st_ctx->cso); } /* default textures */ { struct pipe_screen *screen = st_dev->screen; struct pipe_texture templat; struct pipe_transfer *transfer; unsigned i; memset( &templat, 0, sizeof( templat ) ); templat.target = PIPE_TEXTURE_2D; templat.format = PIPE_FORMAT_A8R8G8B8_UNORM; templat.block.size = 4; templat.block.width = 1; templat.block.height = 1; templat.width[0] = 1; templat.height[0] = 1; templat.depth[0] = 1; templat.last_level = 0; st_ctx->default_texture = screen->texture_create( screen, &templat ); if(st_ctx->default_texture) { transfer = screen->get_tex_transfer(screen, st_ctx->default_texture, 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, st_ctx->default_texture->width[0], st_ctx->default_texture->height[0]); if (transfer) { uint32_t *map; map = (uint32_t *) screen->transfer_map(screen, transfer); if(map) { *map = 0x00000000; screen->transfer_unmap(screen, transfer); } screen->tex_transfer_destroy(transfer); } } for (i = 0; i < PIPE_MAX_SAMPLERS; i++) pipe_texture_reference(&st_ctx->sampler_textures[i], st_ctx->default_texture); cso_set_sampler_textures(st_ctx->cso, PIPE_MAX_SAMPLERS, st_ctx->sampler_textures); } /* vertex shader */ { const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_GENERIC }; const uint semantic_indexes[] = { 0, 0 }; st_ctx->vs = util_make_vertex_passthrough_shader(st_ctx->pipe, 2, semantic_names, semantic_indexes); cso_set_vertex_shader_handle(st_ctx->cso, st_ctx->vs); } /* fragment shader */ { st_ctx->fs = util_make_fragment_passthrough_shader(st_ctx->pipe); cso_set_fragment_shader_handle(st_ctx->cso, st_ctx->fs); } return st_ctx; }
struct blitter_context *util_blitter_create(struct pipe_context *pipe) { struct blitter_context_priv *ctx; struct pipe_blend_state blend; struct pipe_depth_stencil_alpha_state dsa; struct pipe_rasterizer_state rs_state; struct pipe_sampler_state sampler_state; struct pipe_vertex_element velem[2]; unsigned i; ctx = CALLOC_STRUCT(blitter_context_priv); if (!ctx) return NULL; ctx->base.pipe = pipe; ctx->base.draw_rectangle = blitter_draw_rectangle; /* init state objects for them to be considered invalid */ ctx->base.saved_blend_state = INVALID_PTR; ctx->base.saved_dsa_state = INVALID_PTR; ctx->base.saved_rs_state = INVALID_PTR; ctx->base.saved_fs = INVALID_PTR; ctx->base.saved_vs = INVALID_PTR; ctx->base.saved_gs = INVALID_PTR; ctx->base.saved_velem_state = INVALID_PTR; ctx->base.saved_fb_state.nr_cbufs = ~0; ctx->base.saved_num_sampler_views = ~0; ctx->base.saved_num_sampler_states = ~0; ctx->base.saved_num_vertex_buffers = ~0; ctx->base.saved_num_so_targets = ~0; ctx->has_geometry_shader = pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_GEOMETRY, PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0; ctx->vertex_has_integers = pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_VERTEX, PIPE_SHADER_CAP_INTEGERS); ctx->has_stream_out = pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS) != 0; /* blend state objects */ memset(&blend, 0, sizeof(blend)); ctx->blend_keep_color = pipe->create_blend_state(pipe, &blend); blend.rt[0].colormask = PIPE_MASK_RGBA; ctx->blend_write_color = pipe->create_blend_state(pipe, &blend); /* depth stencil alpha state objects */ memset(&dsa, 0, sizeof(dsa)); ctx->dsa_keep_depth_stencil = pipe->create_depth_stencil_alpha_state(pipe, &dsa); dsa.depth.enabled = 1; dsa.depth.writemask = 1; dsa.depth.func = PIPE_FUNC_ALWAYS; ctx->dsa_write_depth_keep_stencil = pipe->create_depth_stencil_alpha_state(pipe, &dsa); dsa.stencil[0].enabled = 1; dsa.stencil[0].func = PIPE_FUNC_ALWAYS; dsa.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE; dsa.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE; dsa.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE; dsa.stencil[0].valuemask = 0xff; dsa.stencil[0].writemask = 0xff; ctx->dsa_write_depth_stencil = pipe->create_depth_stencil_alpha_state(pipe, &dsa); dsa.depth.enabled = 0; dsa.depth.writemask = 0; ctx->dsa_keep_depth_write_stencil = pipe->create_depth_stencil_alpha_state(pipe, &dsa); /* sampler state */ memset(&sampler_state, 0, sizeof(sampler_state)); sampler_state.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; sampler_state.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; sampler_state.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; sampler_state.normalized_coords = 1; ctx->sampler_state = pipe->create_sampler_state(pipe, &sampler_state); /* rasterizer state */ memset(&rs_state, 0, sizeof(rs_state)); rs_state.cull_face = PIPE_FACE_NONE; rs_state.gl_rasterization_rules = 1; rs_state.flatshade = 1; rs_state.depth_clip = 1; ctx->rs_state = pipe->create_rasterizer_state(pipe, &rs_state); if (ctx->has_stream_out) { rs_state.rasterizer_discard = 1; ctx->rs_discard_state = pipe->create_rasterizer_state(pipe, &rs_state); } /* vertex elements states */ memset(&velem[0], 0, sizeof(velem[0]) * 2); for (i = 0; i < 2; i++) { velem[i].src_offset = i * 4 * sizeof(float); velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; } ctx->velem_state = pipe->create_vertex_elements_state(pipe, 2, &velem[0]); if (ctx->vertex_has_integers) { memset(&velem[0], 0, sizeof(velem[0]) * 2); velem[0].src_offset = 0; velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; velem[1].src_offset = 4 * sizeof(float); velem[1].src_format = PIPE_FORMAT_R32G32B32A32_SINT; ctx->velem_sint_state = pipe->create_vertex_elements_state(pipe, 2, &velem[0]); memset(&velem[0], 0, sizeof(velem[0]) * 2); velem[0].src_offset = 0; velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; velem[1].src_offset = 4 * sizeof(float); velem[1].src_format = PIPE_FORMAT_R32G32B32A32_UINT; ctx->velem_uint_state = pipe->create_vertex_elements_state(pipe, 2, &velem[0]); } if (ctx->has_stream_out) { velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; ctx->velem_state_readbuf = pipe->create_vertex_elements_state(pipe, 1, &velem[0]); } /* fragment shaders are created on-demand */ /* vertex shaders */ { const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_GENERIC }; const uint semantic_indices[] = { 0, 0 }; ctx->vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names, semantic_indices); } if (ctx->has_stream_out) { struct pipe_stream_output_info so; const uint semantic_names[] = { TGSI_SEMANTIC_POSITION }; const uint semantic_indices[] = { 0 }; memset(&so, 0, sizeof(so)); so.num_outputs = 1; so.output[0].register_mask = TGSI_WRITEMASK_XYZW; so.stride = 4; ctx->vs_pos_only = util_make_vertex_passthrough_shader_with_so(pipe, 1, semantic_names, semantic_indices, &so); } /* set invariant vertex coordinates */ for (i = 0; i < 4; i++) ctx->vertices[i][0][3] = 1; /*v.w*/ /* create the vertex buffer */ ctx->vbuf = pipe_user_buffer_create(ctx->base.pipe->screen, ctx->vertices, sizeof(ctx->vertices), PIPE_BIND_VERTEX_BUFFER); return &ctx->base; }