/** Setup this resource as the filter input. */ void pp_filter_setup_in(struct program *p, struct pipe_resource *in) { struct pipe_sampler_view v_tmp; u_sampler_view_default_template(&v_tmp, in, in->format); p->view = p->pipe->create_sampler_view(p->pipe, in, &v_tmp); }
static bool init_zscan_buffer(struct vl_mpeg12_decoder *dec, struct vl_mpeg12_buffer *buffer) { struct pipe_resource *res, res_tmpl; struct pipe_sampler_view sv_tmpl; struct pipe_surface **destination; unsigned i; assert(dec && buffer); memset(&res_tmpl, 0, sizeof(res_tmpl)); res_tmpl.target = PIPE_TEXTURE_2D; res_tmpl.format = dec->zscan_source_format; res_tmpl.width0 = dec->blocks_per_line * VL_BLOCK_WIDTH * VL_BLOCK_HEIGHT; res_tmpl.height0 = align(dec->num_blocks, dec->blocks_per_line) / dec->blocks_per_line; res_tmpl.depth0 = 1; res_tmpl.array_size = 1; res_tmpl.usage = PIPE_USAGE_STREAM; res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW; res = dec->base.context->screen->resource_create(dec->base.context->screen, &res_tmpl); if (!res) goto error_source; memset(&sv_tmpl, 0, sizeof(sv_tmpl)); u_sampler_view_default_template(&sv_tmpl, res, res->format); sv_tmpl.swizzle_r = sv_tmpl.swizzle_g = sv_tmpl.swizzle_b = sv_tmpl.swizzle_a = PIPE_SWIZZLE_RED; buffer->zscan_source = dec->base.context->create_sampler_view(dec->base.context, res, &sv_tmpl); pipe_resource_reference(&res, NULL); if (!buffer->zscan_source) goto error_sampler; if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT) destination = dec->idct_source->get_surfaces(dec->idct_source); else destination = dec->mc_source->get_surfaces(dec->mc_source); if (!destination) goto error_surface; for (i = 0; i < VL_NUM_COMPONENTS; ++i) if (!vl_zscan_init_buffer(i == 0 ? &dec->zscan_y : &dec->zscan_c, &buffer->zscan[i], buffer->zscan_source, destination[i])) goto error_plane; return true; error_plane: for (; i > 0; --i) vl_zscan_cleanup_buffer(&buffer->zscan[i - 1]); error_surface: error_sampler: pipe_sampler_view_reference(&buffer->zscan_source, NULL); error_source: return false; }
static void xa_yuv_bind_samplers(struct xa_context *r, struct xa_surface *yuv[]) { struct pipe_sampler_state *samplers[3]; struct pipe_sampler_state sampler; struct pipe_sampler_view *views[3]; struct pipe_sampler_view view_templ; unsigned int i; memset(&sampler, 0, sizeof(struct pipe_sampler_state)); sampler.wrap_s = PIPE_TEX_WRAP_CLAMP; sampler.wrap_t = PIPE_TEX_WRAP_CLAMP; sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR; sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR; sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; sampler.normalized_coords = 1; for (i = 0; i < 3; ++i) { samplers[i] = &sampler; if (!yuv[i]->view) { u_sampler_view_default_template(&view_templ, yuv[i]->tex, yuv[i]->tex->format); yuv[i]->view = r->pipe->create_sampler_view(r->pipe, yuv[i]->tex, &view_templ); } views[i] = yuv[i]->view; } cso_set_samplers(r->cso, 3, (const struct pipe_sampler_state **)samplers); cso_set_fragment_sampler_views(r->cso, 3, views); }
static struct pipe_sampler_view * st_create_texture_sampler_view_from_stobj(struct pipe_context *pipe, struct st_texture_object *stObj, const struct gl_sampler_object *samp, enum pipe_format format) { struct pipe_sampler_view templ; GLuint swizzle = apply_depthmode(stObj->pt->format, stObj->base._Swizzle, samp->DepthMode); u_sampler_view_default_template(&templ, stObj->pt, format); templ.u.tex.first_level = stObj->base.BaseLevel; if (swizzle != SWIZZLE_NOOP) { templ.swizzle_r = GET_SWZ(swizzle, 0); templ.swizzle_g = GET_SWZ(swizzle, 1); templ.swizzle_b = GET_SWZ(swizzle, 2); templ.swizzle_a = GET_SWZ(swizzle, 3); } return pipe->create_sampler_view(pipe, stObj->pt, &templ); }
bool vl_zscan_init_buffer(struct vl_zscan *zscan, struct vl_zscan_buffer *buffer, struct pipe_sampler_view *src, struct pipe_surface *dst) { struct pipe_resource res_tmpl, *res; struct pipe_sampler_view sv_tmpl; assert(zscan && buffer); memset(buffer, 0, sizeof(struct vl_zscan_buffer)); pipe_sampler_view_reference(&buffer->src, src); buffer->viewport.scale[0] = dst->width; buffer->viewport.scale[1] = dst->height; buffer->viewport.scale[2] = 1; buffer->viewport.scale[3] = 1; buffer->viewport.translate[0] = 0; buffer->viewport.translate[1] = 0; buffer->viewport.translate[2] = 0; buffer->viewport.translate[3] = 0; buffer->fb_state.width = dst->width; buffer->fb_state.height = dst->height; buffer->fb_state.nr_cbufs = 1; pipe_surface_reference(&buffer->fb_state.cbufs[0], dst); memset(&res_tmpl, 0, sizeof(res_tmpl)); res_tmpl.target = PIPE_TEXTURE_3D; res_tmpl.format = PIPE_FORMAT_R8_UNORM; res_tmpl.width0 = VL_BLOCK_WIDTH * zscan->blocks_per_line; res_tmpl.height0 = VL_BLOCK_HEIGHT; res_tmpl.depth0 = 2; res_tmpl.array_size = 1; res_tmpl.usage = PIPE_USAGE_IMMUTABLE; res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW; res = zscan->pipe->screen->resource_create(zscan->pipe->screen, &res_tmpl); if (!res) return false; memset(&sv_tmpl, 0, sizeof(sv_tmpl)); u_sampler_view_default_template(&sv_tmpl, res, res->format); sv_tmpl.swizzle_r = sv_tmpl.swizzle_g = sv_tmpl.swizzle_b = sv_tmpl.swizzle_a = TGSI_SWIZZLE_X; buffer->quant = zscan->pipe->create_sampler_view(zscan->pipe, res, &sv_tmpl); pipe_resource_reference(&res, NULL); if (!buffer->quant) return false; return true; }
static struct pipe_sampler_view * st_create_texture_sampler_view_from_stobj(struct pipe_context *pipe, struct st_texture_object *stObj, const struct gl_sampler_object *samp, enum pipe_format format) { struct pipe_sampler_view templ; unsigned swizzle = get_texture_format_swizzle(stObj); u_sampler_view_default_template(&templ, stObj->pt, format); if (stObj->pt->target == PIPE_BUFFER) { unsigned base, size; unsigned f, n; const struct util_format_description *desc = util_format_description(templ.format); base = stObj->base.BufferOffset; if (base >= stObj->pt->width0) return NULL; size = MIN2(stObj->pt->width0 - base, (unsigned)stObj->base.BufferSize); f = ((base * 8) / desc->block.bits) * desc->block.width; n = ((size * 8) / desc->block.bits) * desc->block.width; if (!n) return NULL; templ.u.buf.first_element = f; templ.u.buf.last_element = f + (n - 1); } else { templ.u.tex.first_level = stObj->base.MinLevel + stObj->base.BaseLevel; templ.u.tex.last_level = last_level(stObj); assert(templ.u.tex.first_level <= templ.u.tex.last_level); templ.u.tex.first_layer = stObj->base.MinLayer; templ.u.tex.last_layer = last_layer(stObj); assert(templ.u.tex.first_layer <= templ.u.tex.last_layer); templ.target = gl_target_to_pipe(stObj->base.Target); } if (swizzle != SWIZZLE_NOOP) { templ.swizzle_r = GET_SWZ(swizzle, 0); templ.swizzle_g = GET_SWZ(swizzle, 1); templ.swizzle_b = GET_SWZ(swizzle, 2); templ.swizzle_a = GET_SWZ(swizzle, 3); } return pipe->create_sampler_view(pipe, stObj->pt, &templ); }
static struct pipe_sampler_view * st_create_texture_sampler_view_from_stobj(struct st_context *st, struct st_texture_object *stObj, enum pipe_format format, unsigned glsl_version) { struct pipe_sampler_view templ; unsigned swizzle = get_texture_format_swizzle(st, stObj, glsl_version); u_sampler_view_default_template(&templ, stObj->pt, format); if (stObj->pt->target == PIPE_BUFFER) { unsigned base, size; base = stObj->base.BufferOffset; if (base >= stObj->pt->width0) return NULL; size = MIN2(stObj->pt->width0 - base, (unsigned)stObj->base.BufferSize); if (!size) return NULL; templ.u.buf.offset = base; templ.u.buf.size = size; } else { templ.u.tex.first_level = stObj->base.MinLevel + stObj->base.BaseLevel; templ.u.tex.last_level = last_level(stObj); assert(templ.u.tex.first_level <= templ.u.tex.last_level); if (stObj->layer_override) { templ.u.tex.first_layer = templ.u.tex.last_layer = stObj->layer_override; } else { templ.u.tex.first_layer = stObj->base.MinLayer; templ.u.tex.last_layer = last_layer(stObj); } assert(templ.u.tex.first_layer <= templ.u.tex.last_layer); templ.target = gl_target_to_pipe(stObj->base.Target); } templ.swizzle_r = GET_SWZ(swizzle, 0); templ.swizzle_g = GET_SWZ(swizzle, 1); templ.swizzle_b = GET_SWZ(swizzle, 2); templ.swizzle_a = GET_SWZ(swizzle, 3); return st->pipe->create_sampler_view(st->pipe, stObj->pt, &templ); }
struct pipe_sampler_view *vg_prepare_blend_surface(struct vg_context *ctx) { struct pipe_context *pipe = ctx->pipe; struct pipe_sampler_view *view; struct pipe_sampler_view view_templ; struct st_framebuffer *stfb = ctx->draw_buffer; struct st_renderbuffer *strb = stfb->strb; vg_validate_state(ctx); u_sampler_view_default_template(&view_templ, strb->texture, strb->texture->format); view = pipe->create_sampler_view(pipe, strb->texture, &view_templ); vg_prepare_blend_texture(ctx, view); pipe_sampler_view_reference(&view, NULL); return stfb->blend_texture_view; }
static struct pipe_sampler_view * create_tex_and_view(struct pipe_context *pipe, enum pipe_format format, VGint width, VGint height) { struct pipe_resource *texture; struct pipe_sampler_view view_templ; struct pipe_sampler_view *view; texture = create_texture(pipe, format, width, height); if (!texture) return NULL; u_sampler_view_default_template(&view_templ, texture, texture->format); view = pipe->create_sampler_view(pipe, texture, &view_templ); /* want the texture to go away if the view is freed */ pipe_resource_reference(&texture, NULL); return view; }
static INLINE struct pipe_sampler_view *create_texture_1d_view(struct vg_context *ctx, const VGuint *color_data, const VGint color_data_len) { struct pipe_context *pipe = ctx->pipe; struct pipe_resource *texture; struct pipe_sampler_view view_templ; struct pipe_sampler_view *view; texture = create_texture_1d(ctx, color_data, color_data_len); if (!texture) return NULL; u_sampler_view_default_template(&view_templ, texture, texture->format); view = pipe->create_sampler_view(pipe, texture, &view_templ); /* want the texture to go away if the view is freed */ pipe_resource_reference(&texture, NULL); return view; }
GalliumSurface::GalliumSurface (pipe_context *context, int width, int height) { struct pipe_screen *screen = context->screen; struct pipe_resource pt, *texture; struct pipe_sampler_view view_templ; pipe = context; mapped = NULL; memset (&pt, 0, sizeof (pt)); pt.target = PIPE_TEXTURE_2D; pt.format = PIPE_FORMAT_B8G8R8A8_UNORM; pt.width0 = width; pt.height0 = height; pt.depth0 = 1; pt.last_level = 0; pt.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET | PIPE_BIND_TRANSFER_WRITE | PIPE_BIND_TRANSFER_READ; g_assert (screen->is_format_supported (screen, pt.format, pt.target, 0, pt.bind, 0)); texture = screen->resource_create (screen, &pt); g_assert (texture); u_sampler_view_default_template (&view_templ, texture, texture->format); sampler_view = pipe->create_sampler_view (pipe, texture, &view_templ); pipe_resource_reference (&texture, NULL); }
void vg_prepare_blend_surface(struct vg_context *ctx) { struct pipe_surface *dest_surface = NULL; struct pipe_context *pipe = ctx->pipe; struct pipe_sampler_view *view; struct pipe_sampler_view view_templ; struct st_framebuffer *stfb = ctx->draw_buffer; struct st_renderbuffer *strb = stfb->strb; /* first finish all pending rendering */ vgFinish(); u_sampler_view_default_template(&view_templ, strb->texture, strb->texture->format); view = pipe->create_sampler_view(pipe, strb->texture, &view_templ); dest_surface = pipe->screen->get_tex_surface(pipe->screen, stfb->blend_texture_view->texture, 0, 0, 0, PIPE_BIND_RENDER_TARGET); /* flip it, because we want to use it as a sampler */ util_blit_pixels_tex(ctx->blit, view, 0, strb->height, strb->width, 0, dest_surface, 0, 0, strb->width, strb->height, 0.0, PIPE_TEX_MIPFILTER_NEAREST); if (dest_surface) pipe_surface_reference(&dest_surface, NULL); /* make sure it's complete */ vgFinish(); pipe_sampler_view_reference(&view, NULL); }
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); }
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; }
/** * Create a VdpOutputSurface. */ VdpStatus vlVdpOutputSurfaceCreate(VdpDevice device, VdpRGBAFormat rgba_format, uint32_t width, uint32_t height, VdpOutputSurface *surface) { struct pipe_context *pipe; struct pipe_resource res_tmpl, *res; struct pipe_sampler_view sv_templ; struct pipe_surface surf_templ; vlVdpOutputSurface *vlsurface = NULL; VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Creating output surface\n"); if (!(width && height)) return VDP_STATUS_INVALID_SIZE; vlVdpDevice *dev = vlGetDataHTAB(device); if (!dev) return VDP_STATUS_INVALID_HANDLE; pipe = dev->context->pipe; if (!pipe) return VDP_STATUS_INVALID_HANDLE; vlsurface = CALLOC(1, sizeof(vlVdpOutputSurface)); if (!vlsurface) return VDP_STATUS_RESOURCES; vlsurface->device = dev; memset(&res_tmpl, 0, sizeof(res_tmpl)); res_tmpl.target = PIPE_TEXTURE_2D; res_tmpl.format = FormatRGBAToPipe(rgba_format); res_tmpl.width0 = width; res_tmpl.height0 = height; res_tmpl.depth0 = 1; res_tmpl.array_size = 1; res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; res_tmpl.usage = PIPE_USAGE_STATIC; res = pipe->screen->resource_create(pipe->screen, &res_tmpl); if (!res) { FREE(dev); return VDP_STATUS_ERROR; } memset(&sv_templ, 0, sizeof(sv_templ)); u_sampler_view_default_template(&sv_templ, res, res->format); vlsurface->sampler_view = pipe->create_sampler_view(pipe, res, &sv_templ); if (!vlsurface->sampler_view) { pipe_resource_reference(&res, NULL); FREE(dev); return VDP_STATUS_ERROR; } memset(&surf_templ, 0, sizeof(surf_templ)); surf_templ.format = res->format; surf_templ.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; vlsurface->surface = pipe->create_surface(pipe, res, &surf_templ); if (!vlsurface->surface) { pipe_resource_reference(&res, NULL); FREE(dev); return VDP_STATUS_ERROR; } *surface = vlAddDataHTAB(vlsurface); if (*surface == 0) { pipe_resource_reference(&res, NULL); FREE(dev); return VDP_STATUS_ERROR; } pipe_resource_reference(&res, NULL); vl_compositor_reset_dirty_area(&vlsurface->dirty_area); return VDP_STATUS_OK; }
struct vg_image * image_create(VGImageFormat format, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); struct pipe_context *pipe = ctx->pipe; struct vg_image *image = CALLOC_STRUCT(vg_image); enum pipe_format pformat = vg_format_to_pipe(format); struct pipe_resource pt, *newtex; struct pipe_sampler_view view_templ; struct pipe_sampler_view *view; struct pipe_screen *screen = ctx->pipe->screen; vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE); image->format = format; image->width = width; image->height = height; image->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; image->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; image->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; image->sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST; image->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST; image->sampler.normalized_coords = 1; assert(screen->is_format_supported(screen, pformat, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW)); memset(&pt, 0, sizeof(pt)); pt.target = PIPE_TEXTURE_2D; pt.format = pformat; pt.last_level = 0; pt.width0 = width; pt.height0 = height; pt.depth0 = 1; pt.array_size = 1; pt.bind = PIPE_BIND_SAMPLER_VIEW; newtex = screen->resource_create(screen, &pt); debug_assert(newtex); u_sampler_view_default_template(&view_templ, newtex, newtex->format); /* R, G, and B are treated as 1.0 for alpha-only formats in OpenVG */ if (newtex->format == PIPE_FORMAT_A8_UNORM) { view_templ.swizzle_r = PIPE_SWIZZLE_ONE; view_templ.swizzle_g = PIPE_SWIZZLE_ONE; view_templ.swizzle_b = PIPE_SWIZZLE_ONE; } view = pipe->create_sampler_view(pipe, newtex, &view_templ); /* want the texture to go away if the view is freed */ pipe_resource_reference(&newtex, NULL); image->sampler_view = view; vg_context_add_object(ctx, &image->base); image_cleari(image, 0, 0, 0, image->width, image->height); return image; }
void renderer_copy_prepare(struct xa_context *r, struct pipe_surface *dst_surface, struct pipe_resource *src_texture, const enum xa_formats src_xa_format, const enum xa_formats dst_xa_format) { struct pipe_context *pipe = r->pipe; struct pipe_screen *screen = pipe->screen; struct xa_shader shader; uint32_t fs_traits = FS_COMPOSITE; assert(screen->is_format_supported(screen, dst_surface->format, PIPE_TEXTURE_2D, 0, PIPE_BIND_RENDER_TARGET)); (void)screen; /* set misc state we care about */ { struct pipe_blend_state blend; memset(&blend, 0, sizeof(blend)); blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE; blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE; blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; blend.rt[0].colormask = PIPE_MASK_RGBA; cso_set_blend(r->cso, &blend); } /* sampler */ { struct pipe_sampler_state sampler; 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_NONE; sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; sampler.normalized_coords = 1; cso_single_sampler(r->cso, 0, &sampler); cso_single_sampler_done(r->cso); } renderer_bind_destination(r, dst_surface, dst_surface->width, dst_surface->height); /* texture/sampler view */ { struct pipe_sampler_view templ; struct pipe_sampler_view *src_view; u_sampler_view_default_template(&templ, src_texture, src_texture->format); src_view = pipe->create_sampler_view(pipe, src_texture, &templ); cso_set_fragment_sampler_views(r->cso, 1, &src_view); pipe_sampler_view_reference(&src_view, NULL); } /* shaders */ if (src_texture->format == PIPE_FORMAT_L8_UNORM) fs_traits |= FS_SRC_LUMINANCE; if (dst_surface->format == PIPE_FORMAT_L8_UNORM) fs_traits |= FS_DST_LUMINANCE; if (xa_format_a(dst_xa_format) != 0 && xa_format_a(src_xa_format) == 0) fs_traits |= FS_SRC_SET_ALPHA; shader = xa_shaders_get(r->shaders, VS_COMPOSITE, fs_traits); cso_set_vertex_shader_handle(r->cso, shader.vs); cso_set_fragment_shader_handle(r->cso, shader.fs); r->buffer_size = 0; r->attrs_per_vertex = 2; }
struct pipe_sampler_view * vl_zscan_layout(struct pipe_context *pipe, const int layout[64], unsigned blocks_per_line) { const unsigned total_size = blocks_per_line * VL_BLOCK_WIDTH * VL_BLOCK_HEIGHT; int patched_layout[64]; struct pipe_resource res_tmpl, *res; struct pipe_sampler_view sv_tmpl, *sv; struct pipe_transfer *buf_transfer; unsigned x, y, i, pitch; float *f; struct pipe_box rect = { 0, 0, 0, VL_BLOCK_WIDTH * blocks_per_line, VL_BLOCK_HEIGHT, 1 }; assert(pipe && layout && blocks_per_line); for (i = 0; i < 64; ++i) patched_layout[layout[i]] = i; memset(&res_tmpl, 0, sizeof(res_tmpl)); res_tmpl.target = PIPE_TEXTURE_2D; res_tmpl.format = PIPE_FORMAT_R32_FLOAT; res_tmpl.width0 = VL_BLOCK_WIDTH * blocks_per_line; res_tmpl.height0 = VL_BLOCK_HEIGHT; res_tmpl.depth0 = 1; res_tmpl.array_size = 1; res_tmpl.usage = PIPE_USAGE_IMMUTABLE; res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW; res = pipe->screen->resource_create(pipe->screen, &res_tmpl); if (!res) goto error_resource; f = pipe->transfer_map(pipe, res, 0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE, &rect, &buf_transfer); if (!f) goto error_map; pitch = buf_transfer->stride / sizeof(float); for (i = 0; i < blocks_per_line; ++i) for (y = 0; y < VL_BLOCK_HEIGHT; ++y) for (x = 0; x < VL_BLOCK_WIDTH; ++x) { float addr = patched_layout[x + y * VL_BLOCK_WIDTH] + i * VL_BLOCK_WIDTH * VL_BLOCK_HEIGHT; addr /= total_size; f[i * VL_BLOCK_WIDTH + y * pitch + x] = addr; } pipe->transfer_unmap(pipe, buf_transfer); memset(&sv_tmpl, 0, sizeof(sv_tmpl)); u_sampler_view_default_template(&sv_tmpl, res, res->format); sv = pipe->create_sampler_view(pipe, res, &sv_tmpl); pipe_resource_reference(&res, NULL); if (!sv) goto error_map; return sv; error_map: pipe_resource_reference(&res, NULL); error_resource: return NULL; }
static void st_vdpau_map_surface(struct gl_context *ctx, GLenum target, GLenum access, GLboolean output, struct gl_texture_object *texObj, struct gl_texture_image *texImage, const void *vdpSurface, GLuint index) { struct st_context *st = st_context(ctx); struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); struct pipe_resource *res; struct pipe_sampler_view templ, **sampler_view; mesa_format texFormat; if (output) { res = st_vdpau_output_surface_dma_buf(ctx, vdpSurface); if (!res) res = st_vdpau_output_surface_gallium(ctx, vdpSurface); } else { res = st_vdpau_video_surface_dma_buf(ctx, vdpSurface, index); if (!res) res = st_vdpau_video_surface_gallium(ctx, vdpSurface, index); } if (!res) { _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); return; } /* do we have different screen objects ? */ if (res->screen != st->pipe->screen) { _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); return; } /* switch to surface based */ if (!stObj->surface_based) { _mesa_clear_texture_object(ctx, texObj); stObj->surface_based = GL_TRUE; } texFormat = st_pipe_format_to_mesa_format(res->format); _mesa_init_teximage_fields(ctx, texImage, res->width0, res->height0, 1, 0, GL_RGBA, texFormat); pipe_resource_reference(&stObj->pt, res); st_texture_release_all_sampler_views(st, stObj); pipe_resource_reference(&stImage->pt, res); u_sampler_view_default_template(&templ, res, res->format); templ.u.tex.first_layer = index & 1; templ.u.tex.last_layer = index & 1; templ.swizzle_r = GET_SWZ(stObj->base._Swizzle, 0); templ.swizzle_g = GET_SWZ(stObj->base._Swizzle, 1); templ.swizzle_b = GET_SWZ(stObj->base._Swizzle, 2); templ.swizzle_a = GET_SWZ(stObj->base._Swizzle, 3); sampler_view = st_texture_get_sampler_view(st, stObj); *sampler_view = st->pipe->create_sampler_view(st->pipe, res, &templ); stObj->surface_format = res->format; _mesa_dirty_texobj(ctx, texObj); }
/** * Create the texture map we'll use for antialiasing the lines. */ static boolean aaline_create_texture(struct aaline_stage *aaline) { struct pipe_context *pipe = aaline->stage.draw->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_resource texTemp; struct pipe_sampler_view viewTempl; uint level; memset(&texTemp, 0, sizeof(texTemp)); texTemp.target = PIPE_TEXTURE_2D; texTemp.format = PIPE_FORMAT_A8_UNORM; /* XXX verify supported by driver! */ texTemp.last_level = MAX_TEXTURE_LEVEL; texTemp.width0 = 1 << MAX_TEXTURE_LEVEL; texTemp.height0 = 1 << MAX_TEXTURE_LEVEL; texTemp.depth0 = 1; texTemp.array_size = 1; texTemp.bind = PIPE_BIND_SAMPLER_VIEW; aaline->texture = screen->resource_create(screen, &texTemp); if (!aaline->texture) return FALSE; u_sampler_view_default_template(&viewTempl, aaline->texture, aaline->texture->format); aaline->sampler_view = pipe->create_sampler_view(pipe, aaline->texture, &viewTempl); if (!aaline->sampler_view) { return FALSE; } /* Fill in mipmap images. * Basically each level is solid opaque, except for the outermost * texels which are zero. Special case the 1x1 and 2x2 levels * (though, those levels shouldn't be used - see the max_lod setting). */ for (level = 0; level <= MAX_TEXTURE_LEVEL; level++) { struct pipe_transfer *transfer; struct pipe_box box; const uint size = u_minify(aaline->texture->width0, level); ubyte *data; uint i, j; assert(aaline->texture->width0 == aaline->texture->height0); u_box_origin_2d( size, size, &box ); /* This texture is new, no need to flush. */ transfer = pipe->get_transfer(pipe, aaline->texture, level, PIPE_TRANSFER_WRITE, &box); data = pipe->transfer_map(pipe, transfer); if (data == NULL) return FALSE; for (i = 0; i < size; i++) { for (j = 0; j < size; j++) { ubyte d; if (size == 1) { d = 255; } else if (size == 2) { d = 200; /* tuneable */ } else if (i == 0 || j == 0 || i == size - 1 || j == size - 1) { d = 0; } else { d = 255; } data[i * transfer->stride + j] = d; } } /* unmap */ pipe->transfer_unmap(pipe, transfer); pipe->transfer_destroy(pipe, transfer); } return TRUE; }
/** * glGetTexImage() helper: decompress a compressed texture by rendering * a textured quad. Store the results in the user's buffer. */ static void decompress_with_blit(struct gl_context * ctx, GLenum format, GLenum type, GLvoid *pixels, struct gl_texture_image *texImage) { struct st_context *st = st_context(ctx); struct pipe_context *pipe = st->pipe; struct st_texture_image *stImage = st_texture_image(texImage); struct st_texture_object *stObj = st_texture_object(texImage->TexObject); struct pipe_sampler_view *src_view; const GLuint width = texImage->Width; const GLuint height = texImage->Height; struct pipe_surface *dst_surface; struct pipe_resource *dst_texture; struct pipe_transfer *tex_xfer; unsigned bind = (PIPE_BIND_RENDER_TARGET | /* util_blit may choose to render */ PIPE_BIND_TRANSFER_READ); /* create temp / dest surface */ if (!util_create_rgba_surface(pipe, width, height, bind, &dst_texture, &dst_surface)) { _mesa_problem(ctx, "util_create_rgba_surface() failed " "in decompress_with_blit()"); return; } /* Disable conditional rendering. */ if (st->render_condition) { pipe->render_condition(pipe, NULL, 0); } /* Create sampler view that limits fetches to the source mipmap level */ { struct pipe_sampler_view sv_temp; u_sampler_view_default_template(&sv_temp, stObj->pt, stObj->pt->format); sv_temp.format = util_format_linear(sv_temp.format); sv_temp.u.tex.first_level = sv_temp.u.tex.last_level = texImage->Level; src_view = pipe->create_sampler_view(pipe, stObj->pt, &sv_temp); if (!src_view) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); return; } } /* blit/render/decompress */ util_blit_pixels_tex(st->blit, src_view, /* pipe_resource (src) */ 0, 0, /* src x0, y0 */ width, height, /* src x1, y1 */ dst_surface, /* pipe_surface (dst) */ 0, 0, /* dst x0, y0 */ width, height, /* dst x1, y1 */ 0.0, /* z */ PIPE_TEX_MIPFILTER_NEAREST); /* Restore conditional rendering state. */ if (st->render_condition) { pipe->render_condition(pipe, st->render_condition, st->condition_mode); } /* map the dst_surface so we can read from it */ tex_xfer = pipe_get_transfer(pipe, dst_texture, 0, 0, PIPE_TRANSFER_READ, 0, 0, width, height); pixels = _mesa_map_pbo_dest(ctx, &ctx->Pack, pixels); /* copy/pack data into user buffer */ if (_mesa_format_matches_format_and_type(stImage->base.TexFormat, format, type, ctx->Pack.SwapBytes)) { /* memcpy */ const uint bytesPerRow = width * util_format_get_blocksize(stImage->pt->format); ubyte *map = pipe_transfer_map(pipe, tex_xfer); GLuint row; for (row = 0; row < height; row++) { GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width, height, format, type, row, 0); memcpy(dest, map, bytesPerRow); map += tex_xfer->stride; } pipe_transfer_unmap(pipe, tex_xfer); } else { /* format translation via floats */ GLuint row; enum pipe_format pformat = util_format_linear(dst_texture->format); GLfloat *rgba; rgba = (GLfloat *) malloc(width * 4 * sizeof(GLfloat)); if (!rgba) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()"); goto end; } for (row = 0; row < height; row++) { const GLbitfield transferOps = 0x0; /* bypassed for glGetTexImage() */ GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width, height, format, type, row, 0); if (ST_DEBUG & DEBUG_FALLBACK) debug_printf("%s: fallback format translation\n", __FUNCTION__); /* get float[4] rgba row from surface */ pipe_get_tile_rgba_format(pipe, tex_xfer, 0, row, width, 1, pformat, rgba); _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format, type, dest, &ctx->Pack, transferOps); } free(rgba); } end: _mesa_unmap_pbo_dest(ctx, &ctx->Pack); pipe->transfer_destroy(pipe, tex_xfer); /* destroy the temp / dest surface */ util_destroy_rgba_surface(dst_texture, dst_surface); pipe_sampler_view_release(pipe, &src_view); }
struct pipe_video_buffer * nouveau_vp3_video_buffer_create(struct pipe_context *pipe, const struct pipe_video_buffer *templat, int flags) { struct nouveau_vp3_video_buffer *buffer; struct pipe_resource templ; unsigned i, j, component; struct pipe_sampler_view sv_templ; struct pipe_surface surf_templ; assert(templat->interlaced); if (getenv("XVMC_VL") || templat->buffer_format != PIPE_FORMAT_NV12) return vl_video_buffer_create(pipe, templat); assert(templat->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420); buffer = CALLOC_STRUCT(nouveau_vp3_video_buffer); if (!buffer) return NULL; buffer->base.buffer_format = templat->buffer_format; buffer->base.context = pipe; buffer->base.destroy = nouveau_vp3_video_buffer_destroy; buffer->base.chroma_format = templat->chroma_format; buffer->base.width = templat->width; buffer->base.height = templat->height; buffer->base.get_sampler_view_planes = nouveau_vp3_video_buffer_sampler_view_planes; buffer->base.get_sampler_view_components = nouveau_vp3_video_buffer_sampler_view_components; buffer->base.get_surfaces = nouveau_vp3_video_buffer_surfaces; buffer->base.interlaced = true; memset(&templ, 0, sizeof(templ)); templ.target = PIPE_TEXTURE_2D_ARRAY; templ.depth0 = 1; templ.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; templ.format = PIPE_FORMAT_R8_UNORM; templ.width0 = buffer->base.width; templ.height0 = (buffer->base.height + 1)/2; templ.flags = flags; templ.array_size = 2; buffer->resources[0] = pipe->screen->resource_create(pipe->screen, &templ); if (!buffer->resources[0]) goto error; templ.format = PIPE_FORMAT_R8G8_UNORM; buffer->num_planes = 2; templ.width0 = (templ.width0 + 1) / 2; templ.height0 = (templ.height0 + 1) / 2; for (i = 1; i < buffer->num_planes; ++i) { buffer->resources[i] = pipe->screen->resource_create(pipe->screen, &templ); if (!buffer->resources[i]) goto error; } memset(&sv_templ, 0, sizeof(sv_templ)); for (component = 0, i = 0; i < buffer->num_planes; ++i ) { struct pipe_resource *res = buffer->resources[i]; unsigned nr_components = util_format_get_nr_components(res->format); u_sampler_view_default_template(&sv_templ, res, res->format); buffer->sampler_view_planes[i] = pipe->create_sampler_view(pipe, res, &sv_templ); if (!buffer->sampler_view_planes[i]) goto error; for (j = 0; j < nr_components; ++j, ++component) { sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = PIPE_SWIZZLE_RED + j; sv_templ.swizzle_a = PIPE_SWIZZLE_ONE; buffer->sampler_view_components[component] = pipe->create_sampler_view(pipe, res, &sv_templ); if (!buffer->sampler_view_components[component]) goto error; } } memset(&surf_templ, 0, sizeof(surf_templ)); for (j = 0; j < buffer->num_planes; ++j) { surf_templ.format = buffer->resources[j]->format; surf_templ.u.tex.first_layer = surf_templ.u.tex.last_layer = 0; buffer->surfaces[j * 2] = pipe->create_surface(pipe, buffer->resources[j], &surf_templ); if (!buffer->surfaces[j * 2]) goto error; surf_templ.u.tex.first_layer = surf_templ.u.tex.last_layer = 1; buffer->surfaces[j * 2 + 1] = pipe->create_surface(pipe, buffer->resources[j], &surf_templ); if (!buffer->surfaces[j * 2 + 1]) goto error; } return &buffer->base; error: nouveau_vp3_video_buffer_destroy(&buffer->base); return NULL; }
static void st_vdpau_map_surface(struct gl_context *ctx, GLenum target, GLenum access, GLboolean output, struct gl_texture_object *texObj, struct gl_texture_image *texImage, const GLvoid *vdpSurface, GLuint index) { int (*getProcAddr)(uint32_t device, uint32_t id, void **ptr); uint32_t device = (uintptr_t)ctx->vdpDevice; struct st_context *st = st_context(ctx); struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); struct pipe_resource *res; struct pipe_sampler_view *sv, templ; gl_format texFormat; getProcAddr = ctx->vdpGetProcAddress; if (output) { VdpOutputSurfaceGallium *f; if (getProcAddr(device, VDP_FUNC_ID_OUTPUT_SURFACE_GALLIUM, (void**)&f)) { _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); return; } res = f((uintptr_t)vdpSurface); if (!res) { _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); return; } } else { VdpVideoSurfaceGallium *f; struct pipe_video_buffer *buffer; struct pipe_sampler_view **samplers; if (getProcAddr(device, VDP_FUNC_ID_VIDEO_SURFACE_GALLIUM, (void**)&f)) { _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); return; } buffer = f((uintptr_t)vdpSurface); if (!buffer) { _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); return; } samplers = buffer->get_sampler_view_planes(buffer); if (!samplers) { _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); return; } sv = samplers[index >> 1]; if (!sv) { _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); return; } res = sv->texture; } if (!res) { _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); return; } /* do we have different screen objects ? */ if (res->screen != st->pipe->screen) { _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); return; } /* switch to surface based */ if (!stObj->surface_based) { _mesa_clear_texture_object(ctx, texObj); stObj->surface_based = GL_TRUE; } texFormat = st_pipe_format_to_mesa_format(res->format); _mesa_init_teximage_fields(ctx, texImage, res->width0, res->height0, 1, 0, GL_RGBA, texFormat); pipe_resource_reference(&stObj->pt, res); pipe_sampler_view_reference(&stObj->sampler_view, NULL); pipe_resource_reference(&stImage->pt, res); u_sampler_view_default_template(&templ, res, res->format); templ.u.tex.first_layer = index & 1; templ.u.tex.last_layer = index & 1; templ.swizzle_r = GET_SWZ(stObj->base._Swizzle, 0); templ.swizzle_g = GET_SWZ(stObj->base._Swizzle, 1); templ.swizzle_b = GET_SWZ(stObj->base._Swizzle, 2); templ.swizzle_a = GET_SWZ(stObj->base._Swizzle, 3); stObj->sampler_view = st->pipe->create_sampler_view(st->pipe, res, &templ); stObj->width0 = res->width0; stObj->height0 = res->height0; stObj->depth0 = 1; stObj->surface_format = res->format; _mesa_dirty_texobj(ctx, texObj); }
static void bind_samplers(struct exa_context *exa, int op, PicturePtr pSrcPicture, PicturePtr pMaskPicture, PicturePtr pDstPicture, struct exa_pixmap_priv *pSrc, struct exa_pixmap_priv *pMask, struct exa_pixmap_priv *pDst) { struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS] = {0}; struct pipe_sampler_state src_sampler, mask_sampler; struct pipe_sampler_view view_templ; struct pipe_sampler_view *src_view; struct pipe_context *pipe = exa->pipe; exa->num_bound_samplers = 0; memset(&src_sampler, 0, sizeof(struct pipe_sampler_state)); memset(&mask_sampler, 0, sizeof(struct pipe_sampler_state)); if (pSrcPicture && pSrc) { if (exa->has_solid_color) { debug_assert(!"solid color with textures"); samplers[0] = NULL; pipe_sampler_view_reference(&exa->bound_sampler_views[0], NULL); } else { unsigned src_wrap = render_repeat_to_gallium( pSrcPicture->repeatType); int filter; render_filter_to_gallium(pSrcPicture->filter, &filter); src_sampler.wrap_s = src_wrap; src_sampler.wrap_t = src_wrap; src_sampler.min_img_filter = filter; src_sampler.mag_img_filter = filter; src_sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; src_sampler.normalized_coords = 1; samplers[0] = &src_sampler; exa->num_bound_samplers = 1; u_sampler_view_default_template(&view_templ, pSrc->tex, pSrc->tex->format); src_view = pipe->create_sampler_view(pipe, pSrc->tex, &view_templ); pipe_sampler_view_reference(&exa->bound_sampler_views[0], NULL); exa->bound_sampler_views[0] = src_view; } } if (pMaskPicture && pMask) { unsigned mask_wrap = render_repeat_to_gallium( pMaskPicture->repeatType); int filter; render_filter_to_gallium(pMaskPicture->filter, &filter); mask_sampler.wrap_s = mask_wrap; mask_sampler.wrap_t = mask_wrap; mask_sampler.min_img_filter = filter; mask_sampler.mag_img_filter = filter; src_sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; mask_sampler.normalized_coords = 1; samplers[1] = &mask_sampler; exa->num_bound_samplers = 2; u_sampler_view_default_template(&view_templ, pMask->tex, pMask->tex->format); src_view = pipe->create_sampler_view(pipe, pMask->tex, &view_templ); pipe_sampler_view_reference(&exa->bound_sampler_views[1], NULL); exa->bound_sampler_views[1] = src_view; } cso_set_samplers(exa->renderer->cso, PIPE_SHADER_FRAGMENT, exa->num_bound_samplers, (const struct pipe_sampler_state **)samplers); cso_set_sampler_views(exa->renderer->cso, PIPE_SHADER_FRAGMENT, exa->num_bound_samplers, exa->bound_sampler_views); }
void renderer_copy_surface(struct renderer *ctx, struct pipe_surface *src, int srcX0, int srcY0, int srcX1, int srcY1, struct pipe_surface *dst, int dstX0, int dstY0, int dstX1, int dstY1, float z, unsigned filter) { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_sampler_view view_templ; struct pipe_sampler_view *view; struct pipe_box src_box; struct pipe_resource texTemp, *tex; const struct pipe_framebuffer_state *fb = &ctx->g3d.fb; const int srcW = abs(srcX1 - srcX0); const int srcH = abs(srcY1 - srcY0); const int srcLeft = MIN2(srcX0, srcX1); const int srcTop = MIN2(srcY0, srcY1); assert(filter == PIPE_TEX_MIPFILTER_NEAREST || filter == PIPE_TEX_MIPFILTER_LINEAR); if (srcLeft != srcX0) { /* left-right flip */ int tmp = dstX0; dstX0 = dstX1; dstX1 = tmp; } if (srcTop != srcY0) { /* up-down flip */ int tmp = dstY0; dstY0 = dstY1; dstY1 = tmp; } assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW)); assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW)); assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, 0, PIPE_BIND_RENDER_TARGET)); /* * XXX for now we're always creating a temporary texture. * Strictly speaking that's not always needed. */ /* create temp texture */ memset(&texTemp, 0, sizeof(texTemp)); texTemp.target = PIPE_TEXTURE_2D; texTemp.format = src->format; texTemp.last_level = 0; texTemp.width0 = srcW; texTemp.height0 = srcH; texTemp.depth0 = 1; texTemp.array_size = 1; texTemp.bind = PIPE_BIND_SAMPLER_VIEW; tex = screen->resource_create(screen, &texTemp); if (!tex) return; u_sampler_view_default_template(&view_templ, tex, tex->format); view = pipe->create_sampler_view(pipe, tex, &view_templ); if (!view) return; u_box_2d_zslice(srcLeft, srcTop, src->u.tex.first_layer, srcW, srcH, &src_box); pipe->resource_copy_region(pipe, tex, 0, 0, 0, 0, /* dest */ src->texture, 0, &src_box); assert(floatsEqual(z, 0.0f)); /* draw */ if (fb->cbufs[0] == dst) { /* transform back to surface coordinates */ dstY0 = dst->height - dstY0; dstY1 = dst->height - dstY1; if (renderer_drawtex_begin(ctx, view)) { renderer_drawtex(ctx, dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0, 0, 0, view->texture->width0, view->texture->height0); renderer_drawtex_end(ctx); } } else { if (renderer_copy_begin(ctx, dst, VG_TRUE, view)) { renderer_copy(ctx, dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0, 0, 0, view->texture->width0, view->texture->height0); renderer_copy_end(ctx); } } }
PUBLIC Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture *subpicture, unsigned short width, unsigned short height, int xvimage_id) { XvMCContextPrivate *context_priv; XvMCSubpicturePrivate *subpicture_priv; struct pipe_context *pipe; struct pipe_resource tex_templ, *tex; struct pipe_sampler_view sampler_templ; Status ret; XVMC_MSG(XVMC_TRACE, "[XvMC] Creating subpicture %p.\n", subpicture); assert(dpy); if (!context) return XvMCBadContext; context_priv = context->privData; pipe = context_priv->pipe; if (!subpicture) return XvMCBadSubpicture; if (width > context_priv->subpicture_max_width || height > context_priv->subpicture_max_height) return BadValue; ret = Validate(dpy, context->port, context->surface_type_id, xvimage_id); if (ret != Success) return ret; subpicture_priv = CALLOC(1, sizeof(XvMCSubpicturePrivate)); if (!subpicture_priv) return BadAlloc; memset(&tex_templ, 0, sizeof(tex_templ)); tex_templ.target = PIPE_TEXTURE_2D; tex_templ.format = XvIDToPipe(xvimage_id); tex_templ.last_level = 0; if (pipe->screen->get_video_param(pipe->screen, PIPE_VIDEO_PROFILE_UNKNOWN, PIPE_VIDEO_ENTRYPOINT_UNKNOWN, PIPE_VIDEO_CAP_NPOT_TEXTURES)) { tex_templ.width0 = width; tex_templ.height0 = height; } else { tex_templ.width0 = util_next_power_of_two(width); tex_templ.height0 = util_next_power_of_two(height); } tex_templ.depth0 = 1; tex_templ.array_size = 1; tex_templ.usage = PIPE_USAGE_DYNAMIC; tex_templ.bind = PIPE_BIND_SAMPLER_VIEW; tex_templ.flags = 0; tex = pipe->screen->resource_create(pipe->screen, &tex_templ); memset(&sampler_templ, 0, sizeof(sampler_templ)); u_sampler_view_default_template(&sampler_templ, tex, tex->format); subpicture_priv->sampler = pipe->create_sampler_view(pipe, tex, &sampler_templ); pipe_resource_reference(&tex, NULL); if (!subpicture_priv->sampler) { FREE(subpicture_priv); return BadAlloc; } subpicture_priv->context = context; subpicture->subpicture_id = XAllocID(dpy); subpicture->context_id = context->context_id; subpicture->xvimage_id = xvimage_id; subpicture->width = width; subpicture->height = height; subpicture->num_palette_entries = NumPaletteEntries4XvID(xvimage_id); subpicture->entry_bytes = PipeToComponentOrder(tex_templ.format, subpicture->component_order); subpicture->privData = subpicture_priv; if (subpicture->num_palette_entries > 0) { tex_templ.target = PIPE_TEXTURE_1D; tex_templ.format = PIPE_FORMAT_R8G8B8X8_UNORM; tex_templ.width0 = subpicture->num_palette_entries; tex_templ.height0 = 1; tex_templ.usage = PIPE_USAGE_DEFAULT; tex = pipe->screen->resource_create(pipe->screen, &tex_templ); memset(&sampler_templ, 0, sizeof(sampler_templ)); u_sampler_view_default_template(&sampler_templ, tex, tex->format); sampler_templ.swizzle_a = PIPE_SWIZZLE_ONE; subpicture_priv->palette = pipe->create_sampler_view(pipe, tex, &sampler_templ); pipe_resource_reference(&tex, NULL); if (!subpicture_priv->sampler) { FREE(subpicture_priv); return BadAlloc; } } SyncHandle(); XVMC_MSG(XVMC_TRACE, "[XvMC] Subpicture %p created.\n", subpicture); return Success; }
/** * Copy image data from application memory in a specific indexed format to * a VdpOutputSurface. */ VdpStatus vlVdpOutputSurfacePutBitsIndexed(VdpOutputSurface surface, VdpIndexedFormat source_indexed_format, void const *const *source_data, uint32_t const *source_pitch, VdpRect const *destination_rect, VdpColorTableFormat color_table_format, void const *color_table) { vlVdpOutputSurface *vlsurface; struct pipe_context *context; struct vl_compositor *compositor; struct vl_compositor_state *cstate; enum pipe_format index_format; enum pipe_format colortbl_format; struct pipe_resource *res, res_tmpl; struct pipe_sampler_view sv_tmpl; struct pipe_sampler_view *sv_idx = NULL, *sv_tbl = NULL; struct pipe_box box; struct u_rect dst_rect; vlsurface = vlGetDataHTAB(surface); if (!vlsurface) return VDP_STATUS_INVALID_HANDLE; context = vlsurface->device->context; compositor = &vlsurface->device->compositor; cstate = &vlsurface->cstate; index_format = FormatIndexedToPipe(source_indexed_format); if (index_format == PIPE_FORMAT_NONE) return VDP_STATUS_INVALID_INDEXED_FORMAT; if (!source_data || !source_pitch) return VDP_STATUS_INVALID_POINTER; colortbl_format = FormatColorTableToPipe(color_table_format); if (colortbl_format == PIPE_FORMAT_NONE) return VDP_STATUS_INVALID_COLOR_TABLE_FORMAT; if (!color_table) return VDP_STATUS_INVALID_POINTER; memset(&res_tmpl, 0, sizeof(res_tmpl)); res_tmpl.target = PIPE_TEXTURE_2D; res_tmpl.format = index_format; if (destination_rect) { res_tmpl.width0 = abs(destination_rect->x0-destination_rect->x1); res_tmpl.height0 = abs(destination_rect->y0-destination_rect->y1); } else { res_tmpl.width0 = vlsurface->surface->texture->width0; res_tmpl.height0 = vlsurface->surface->texture->height0; } res_tmpl.depth0 = 1; res_tmpl.array_size = 1; res_tmpl.usage = PIPE_USAGE_STAGING; res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW; pipe_mutex_lock(vlsurface->device->mutex); vlVdpResolveDelayedRendering(vlsurface->device, NULL, NULL); res = context->screen->resource_create(context->screen, &res_tmpl); if (!res) goto error_resource; box.x = box.y = box.z = 0; box.width = res->width0; box.height = res->height0; box.depth = res->depth0; context->transfer_inline_write(context, res, 0, PIPE_TRANSFER_WRITE, &box, source_data[0], source_pitch[0], source_pitch[0] * res->height0); memset(&sv_tmpl, 0, sizeof(sv_tmpl)); u_sampler_view_default_template(&sv_tmpl, res, res->format); sv_idx = context->create_sampler_view(context, res, &sv_tmpl); pipe_resource_reference(&res, NULL); if (!sv_idx) goto error_resource; memset(&res_tmpl, 0, sizeof(res_tmpl)); res_tmpl.target = PIPE_TEXTURE_1D; res_tmpl.format = colortbl_format; res_tmpl.width0 = 1 << util_format_get_component_bits( index_format, UTIL_FORMAT_COLORSPACE_RGB, 0); res_tmpl.height0 = 1; res_tmpl.depth0 = 1; res_tmpl.array_size = 1; res_tmpl.usage = PIPE_USAGE_STAGING; res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW; res = context->screen->resource_create(context->screen, &res_tmpl); if (!res) goto error_resource; box.x = box.y = box.z = 0; box.width = res->width0; box.height = res->height0; box.depth = res->depth0; context->transfer_inline_write(context, res, 0, PIPE_TRANSFER_WRITE, &box, color_table, util_format_get_stride(colortbl_format, res->width0), 0); memset(&sv_tmpl, 0, sizeof(sv_tmpl)); u_sampler_view_default_template(&sv_tmpl, res, res->format); sv_tbl = context->create_sampler_view(context, res, &sv_tmpl); pipe_resource_reference(&res, NULL); if (!sv_tbl) goto error_resource; vl_compositor_clear_layers(cstate); vl_compositor_set_palette_layer(cstate, compositor, 0, sv_idx, sv_tbl, NULL, NULL, false); vl_compositor_set_layer_dst_area(cstate, 0, RectToPipe(destination_rect, &dst_rect)); vl_compositor_render(cstate, compositor, vlsurface->surface, NULL); pipe_sampler_view_reference(&sv_idx, NULL); pipe_sampler_view_reference(&sv_tbl, NULL); pipe_mutex_unlock(vlsurface->device->mutex); return VDP_STATUS_OK; error_resource: pipe_sampler_view_reference(&sv_idx, NULL); pipe_sampler_view_reference(&sv_tbl, NULL); pipe_mutex_unlock(vlsurface->device->mutex); return VDP_STATUS_RESOURCES; }
struct pipe_sampler_view * vl_idct_upload_matrix(struct pipe_context *pipe, float scale) { struct pipe_resource tex_templ, *matrix; struct pipe_sampler_view sv_templ, *sv; struct pipe_transfer *buf_transfer; unsigned i, j, pitch; float *f; struct pipe_box rect = { 0, 0, 0, VL_BLOCK_WIDTH / 4, VL_BLOCK_HEIGHT, 1 }; assert(pipe); memset(&tex_templ, 0, sizeof(tex_templ)); tex_templ.target = PIPE_TEXTURE_2D; tex_templ.format = PIPE_FORMAT_R32G32B32A32_FLOAT; tex_templ.last_level = 0; tex_templ.width0 = 2; tex_templ.height0 = 8; tex_templ.depth0 = 1; tex_templ.array_size = 1; tex_templ.usage = PIPE_USAGE_IMMUTABLE; tex_templ.bind = PIPE_BIND_SAMPLER_VIEW; tex_templ.flags = 0; matrix = pipe->screen->resource_create(pipe->screen, &tex_templ); if (!matrix) goto error_matrix; f = pipe->transfer_map(pipe, matrix, 0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE, &rect, &buf_transfer); if (!f) goto error_map; pitch = buf_transfer->stride / sizeof(float); for(i = 0; i < VL_BLOCK_HEIGHT; ++i) for(j = 0; j < VL_BLOCK_WIDTH; ++j) // transpose and scale f[i * pitch + j] = ((const float (*)[8])const_matrix)[j][i] * scale; pipe->transfer_unmap(pipe, buf_transfer); memset(&sv_templ, 0, sizeof(sv_templ)); u_sampler_view_default_template(&sv_templ, matrix, matrix->format); sv = pipe->create_sampler_view(pipe, matrix, &sv_templ); pipe_resource_reference(&matrix, NULL); if (!sv) goto error_map; return sv; error_map: pipe_resource_reference(&matrix, NULL); error_matrix: return NULL; }
/** Run function of the MLAA filter. */ static void pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in, struct pipe_resource *out, unsigned int n, bool iscolor) { struct pp_program *p = ppq->p; struct pipe_depth_stencil_alpha_state mstencil; struct pipe_sampler_view v_tmp, *arr[3]; unsigned int w = 0; unsigned int h = 0; const struct pipe_stencil_ref ref = { {1} }; /* Insufficient initialization checks. */ assert(p); assert(ppq); assert(ppq->constbuf); assert(ppq->areamaptex); assert(ppq->inner_tmp); assert(ppq->shaders[n]); w = p->framebuffer.width; h = p->framebuffer.height; memset(&mstencil, 0, sizeof(mstencil)); cso_set_stencil_ref(p->cso, &ref); /* Init the pixel size constant */ if (dimensions[0] != p->framebuffer.width || dimensions[1] != p->framebuffer.height) { constants[0] = 1.0f / p->framebuffer.width; constants[1] = 1.0f / p->framebuffer.height; up_consts(ppq); dimensions[0] = p->framebuffer.width; dimensions[1] = p->framebuffer.height; } cso_set_constant_buffer_resource(p->cso, PIPE_SHADER_VERTEX, 0, ppq->constbuf); cso_set_constant_buffer_resource(p->cso, PIPE_SHADER_FRAGMENT, 0, ppq->constbuf); mstencil.stencil[0].enabled = 1; mstencil.stencil[0].valuemask = mstencil.stencil[0].writemask = ~0; mstencil.stencil[0].func = PIPE_FUNC_ALWAYS; mstencil.stencil[0].fail_op = PIPE_STENCIL_OP_KEEP; mstencil.stencil[0].zfail_op = PIPE_STENCIL_OP_KEEP; mstencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE; p->framebuffer.zsbuf = ppq->stencils; /* First pass: depth edge detection */ if (iscolor) pp_filter_setup_in(p, in); else pp_filter_setup_in(p, ppq->depth); pp_filter_setup_out(p, ppq->inner_tmp[0]); pp_filter_set_fb(p); pp_filter_misc_state(p); cso_set_depth_stencil_alpha(p->cso, &mstencil); p->pipe->clear(p->pipe, PIPE_CLEAR_STENCIL | PIPE_CLEAR_COLOR0, &p->clear_color, 0, 0); cso_single_sampler(p->cso, PIPE_SHADER_FRAGMENT, 0, &p->sampler_point); cso_single_sampler_done(p->cso, PIPE_SHADER_FRAGMENT); cso_set_sampler_views(p->cso, PIPE_SHADER_FRAGMENT, 1, &p->view); cso_set_vertex_shader_handle(p->cso, ppq->shaders[n][1]); /* offsetvs */ cso_set_fragment_shader_handle(p->cso, ppq->shaders[n][2]); pp_filter_draw(p); pp_filter_end_pass(p); /* Second pass: blend weights */ /* Sampler order: areamap, edgesmap, edgesmapL (reversed, thx compiler) */ mstencil.stencil[0].func = PIPE_FUNC_EQUAL; mstencil.stencil[0].zpass_op = PIPE_STENCIL_OP_KEEP; cso_set_depth_stencil_alpha(p->cso, &mstencil); pp_filter_setup_in(p, ppq->areamaptex); pp_filter_setup_out(p, ppq->inner_tmp[1]); u_sampler_view_default_template(&v_tmp, ppq->inner_tmp[0], ppq->inner_tmp[0]->format); arr[1] = arr[2] = p->pipe->create_sampler_view(p->pipe, ppq->inner_tmp[0], &v_tmp); pp_filter_set_clear_fb(p); cso_single_sampler(p->cso, PIPE_SHADER_FRAGMENT, 0, &p->sampler_point); cso_single_sampler(p->cso, PIPE_SHADER_FRAGMENT, 1, &p->sampler_point); cso_single_sampler(p->cso, PIPE_SHADER_FRAGMENT, 2, &p->sampler); cso_single_sampler_done(p->cso, PIPE_SHADER_FRAGMENT); arr[0] = p->view; cso_set_sampler_views(p->cso, PIPE_SHADER_FRAGMENT, 3, arr); cso_set_vertex_shader_handle(p->cso, ppq->shaders[n][0]); /* passvs */ cso_set_fragment_shader_handle(p->cso, ppq->shaders[n][3]); pp_filter_draw(p); pp_filter_end_pass(p); pipe_sampler_view_reference(&arr[1], NULL); /* Third pass: smoothed edges */ /* Sampler order: colormap, blendmap (wtf compiler) */ pp_filter_setup_in(p, ppq->inner_tmp[1]); pp_filter_setup_out(p, out); pp_filter_set_fb(p); /* Blit the input to the output */ pp_blit(p->pipe, in, 0, 0, w, h, 0, p->framebuffer.cbufs[0], 0, 0, w, h); u_sampler_view_default_template(&v_tmp, in, in->format); arr[0] = p->pipe->create_sampler_view(p->pipe, in, &v_tmp); cso_single_sampler(p->cso, PIPE_SHADER_FRAGMENT, 0, &p->sampler_point); cso_single_sampler(p->cso, PIPE_SHADER_FRAGMENT, 1, &p->sampler_point); cso_single_sampler_done(p->cso, PIPE_SHADER_FRAGMENT); arr[1] = p->view; cso_set_sampler_views(p->cso, PIPE_SHADER_FRAGMENT, 2, arr); cso_set_vertex_shader_handle(p->cso, ppq->shaders[n][1]); /* offsetvs */ cso_set_fragment_shader_handle(p->cso, ppq->shaders[n][4]); p->blend.rt[0].blend_enable = 1; cso_set_blend(p->cso, &p->blend); pp_filter_draw(p); pp_filter_end_pass(p); pipe_sampler_view_reference(&arr[0], NULL); p->blend.rt[0].blend_enable = 0; p->framebuffer.zsbuf = NULL; }
static void bind_samplers(struct xa_context *ctx, const struct xa_composite *comp) { struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state src_sampler, mask_sampler; struct pipe_sampler_view view_templ; struct pipe_sampler_view *src_view; struct pipe_context *pipe = ctx->pipe; struct xa_picture *src_pic = comp->src; struct xa_picture *mask_pic = comp->mask; ctx->num_bound_samplers = 0; memset(&src_sampler, 0, sizeof(struct pipe_sampler_state)); memset(&mask_sampler, 0, sizeof(struct pipe_sampler_state)); if (src_pic) { if (ctx->has_solid_color) { samplers[0] = NULL; pipe_sampler_view_reference(&ctx->bound_sampler_views[0], NULL); } else { unsigned src_wrap = xa_repeat_to_gallium(src_pic->wrap); int filter; (void) xa_filter_to_gallium(src_pic->filter, &filter); src_sampler.wrap_s = src_wrap; src_sampler.wrap_t = src_wrap; src_sampler.min_img_filter = filter; src_sampler.mag_img_filter = filter; src_sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; src_sampler.normalized_coords = 1; samplers[0] = &src_sampler; ctx->num_bound_samplers = 1; u_sampler_view_default_template(&view_templ, src_pic->srf->tex, src_pic->srf->tex->format); src_view = pipe->create_sampler_view(pipe, src_pic->srf->tex, &view_templ); pipe_sampler_view_reference(&ctx->bound_sampler_views[0], NULL); ctx->bound_sampler_views[0] = src_view; } } if (mask_pic) { unsigned mask_wrap = xa_repeat_to_gallium(mask_pic->wrap); int filter; (void) xa_filter_to_gallium(mask_pic->filter, &filter); mask_sampler.wrap_s = mask_wrap; mask_sampler.wrap_t = mask_wrap; mask_sampler.min_img_filter = filter; mask_sampler.mag_img_filter = filter; src_sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; mask_sampler.normalized_coords = 1; samplers[1] = &mask_sampler; ctx->num_bound_samplers = 2; u_sampler_view_default_template(&view_templ, mask_pic->srf->tex, mask_pic->srf->tex->format); src_view = pipe->create_sampler_view(pipe, mask_pic->srf->tex, &view_templ); pipe_sampler_view_reference(&ctx->bound_sampler_views[1], NULL); ctx->bound_sampler_views[1] = src_view; /* * If src is a solid color, we have no src view, so set up a * dummy one that will not be used anyway. */ if (ctx->bound_sampler_views[0] == NULL) pipe_sampler_view_reference(&ctx->bound_sampler_views[0], src_view); } cso_set_samplers(ctx->cso, PIPE_SHADER_FRAGMENT, ctx->num_bound_samplers, (const struct pipe_sampler_state **)samplers); cso_set_sampler_views(ctx->cso, PIPE_SHADER_FRAGMENT, ctx->num_bound_samplers, ctx->bound_sampler_views); }