Ejemplo n.º 1
0
int main()
{
    struct program *program = calloc(1, sizeof(struct program));

    struct pipe_loader_device **devs = NULL;
    const int max_devices = 32;

    int idev, ndev;

    /* find & list graphic devices */
    ndev = pipe_loader_probe(&program->dev, max_devices);

    devs = &program->dev;
    for (idev = 0; idev < ndev; idev++)
    {
        printf("driver name: %s; type: %d\n", devs[idev]->driver_name, devs[idev]->type);
    }

    /* init a pipe screen */
    program->screen = pipe_loader_create_screen(devs[0], PIPE_SEARCH_DIR);

    /* create the pipe driver context and cso context */
    program->pipe = program->screen->context_create(program->screen, NULL);
    program->cso = cso_create_context(program->pipe);

    /* destroy */
    cso_destroy_context(program->cso);
    program->pipe->destroy(program->pipe);
    program->screen->destroy(program->screen);

    return 0;
}
Ejemplo n.º 2
0
struct pipe_screen *
graw_create_window_and_screen(int x,
                              int y,
                              unsigned width,
                              unsigned height,
                              enum pipe_format format,
                              void **handle)
{
    struct sw_winsys *winsys = NULL;
    struct pipe_screen *screen = NULL;
    struct pipe_loader_device *dev;
	int ret;

    if (format != PIPE_FORMAT_B8G8R8X8_UNORM)
        goto fail;

    winsys = kos_create_sw_winsys();
    if (winsys == NULL)
        goto fail;

	/* find a hardware device */
	ret = pipe_loader_probe(&dev, 1);

	/* init a pipe screen */
	screen = pipe_loader_create_screen(dev, "drivers");
   
    if (screen == NULL)
        goto fail;

    BeginDraw();
    DrawWindow(x, y,width-1,height-1,
               NULL,0,0x41);
    EndDraw();
    
    *handle = (void *)winsys; 
    return (screen);

fail:
  
   if (screen)
      screen->destroy(screen);

   return NULL;
}
Ejemplo n.º 3
0
int
gallium_screen_create(struct gbm_gallium_drm_device *gdrm)
{
   struct pipe_loader_device *dev;
#ifdef HAVE_PIPE_LOADER_DRM
   int ret;

   ret = pipe_loader_drm_probe_fd(&dev, gdrm->base.base.fd);
   if (!ret)
      return -1;
#endif /* HAVE_PIPE_LOADER_DRM */

   gdrm->screen = pipe_loader_create_screen(dev, get_library_search_path());
   if (gdrm->screen == NULL) {
      debug_printf("failed to load driver: %s\n", gdrm->base.driver_name);
      pipe_loader_release(&dev, 1);
      return -1;
   };

   gdrm->driver = dev;
   gdrm->base.driver_name = strdup(dev->driver_name);
   return 0;
}
Ejemplo n.º 4
0
struct vl_screen *
vl_drm_screen_create(int fd)
{
   struct vl_screen *vscreen;
   int new_fd;

   vscreen = CALLOC_STRUCT(vl_screen);
   if (!vscreen)
      return NULL;

   if (fd < 0 || (new_fd = dup(fd)) < 0)
      goto free_screen;

   if (pipe_loader_drm_probe_fd(&vscreen->dev, new_fd))
      vscreen->pscreen = pipe_loader_create_screen(vscreen->dev);

   if (!vscreen->pscreen)
      goto release_pipe;

   vscreen->destroy = vl_drm_screen_destroy;
   vscreen->texture_from_drawable = NULL;
   vscreen->get_dirty_area = NULL;
   vscreen->get_timestamp = NULL;
   vscreen->set_next_timestamp = NULL;
   vscreen->get_private = NULL;
   return vscreen;

release_pipe:
   if (vscreen->dev)
      pipe_loader_release(&vscreen->dev, 1);
   else
      close(new_fd);

free_screen:
   FREE(vscreen);
   return NULL;
}
Ejemplo n.º 5
0
Archivo: drm.c Proyecto: tizbac/Mesa-3D
static HRESULT WINAPI
drm_create_adapter( int fd,
                    ID3DAdapter9 **ppAdapter )
{
    struct d3dadapter9drm_context *ctx = CALLOC_STRUCT(d3dadapter9drm_context);
    HRESULT hr;
    int i, different_device;
    const struct drm_conf_ret *throttle_ret = NULL;
    const struct drm_conf_ret *dmabuf_ret = NULL;
    driOptionCache defaultInitOptions;
    driOptionCache userInitOptions;
    int throttling_value_user = -2;

#if !GALLIUM_STATIC_TARGETS
    const char *paths[] = {
        getenv("D3D9_DRIVERS_PATH"),
        getenv("D3D9_DRIVERS_DIR"),
        PIPE_SEARCH_DIR
    };
#endif

    if (!ctx) { return E_OUTOFMEMORY; }

    ctx->base.destroy = drm_destroy;

    fd = loader_get_user_preferred_fd(fd, &different_device);
    ctx->fd = fd;
    ctx->base.linear_framebuffer = !!different_device;

#if GALLIUM_STATIC_TARGETS
    ctx->base.hal = dd_create_screen(fd);
#else
    /* use pipe-loader to dlopen appropriate drm driver */
    if (!pipe_loader_drm_probe_fd(&ctx->dev, fd, FALSE)) {
        ERR("Failed to probe drm fd %d.\n", fd);
        FREE(ctx);
        close(fd);
        return D3DERR_DRIVERINTERNALERROR;
    }

    /* use pipe-loader to create a drm screen (hal) */
    ctx->base.hal = NULL;
    for (i = 0; !ctx->base.hal && i < Elements(paths); ++i) {
        if (!paths[i]) { continue; }
        ctx->base.hal = pipe_loader_create_screen(ctx->dev, paths[i]);
    }
#endif
    if (!ctx->base.hal) {
        ERR("Unable to load requested driver.\n");
        drm_destroy(&ctx->base);
        return D3DERR_DRIVERINTERNALERROR;
    }

#if GALLIUM_STATIC_TARGETS
    dmabuf_ret = dd_configuration(DRM_CONF_SHARE_FD);
    throttle_ret = dd_configuration(DRM_CONF_THROTTLE);
#else
    dmabuf_ret = pipe_loader_configuration(ctx->dev, DRM_CONF_SHARE_FD);
    throttle_ret = pipe_loader_configuration(ctx->dev, DRM_CONF_THROTTLE);
#endif // GALLIUM_STATIC_TARGETS
    if (!dmabuf_ret || !dmabuf_ret->val.val_bool) {
        ERR("The driver is not capable of dma-buf sharing."
            "Abandon to load nine state tracker\n");
        drm_destroy(&ctx->base);
        return D3DERR_DRIVERINTERNALERROR;
    }

    if (throttle_ret && throttle_ret->val.val_int != -1) {
        ctx->base.throttling = TRUE;
        ctx->base.throttling_value = throttle_ret->val.val_int;
    } else
        ctx->base.throttling = FALSE;

    driParseOptionInfo(&defaultInitOptions, __driConfigOptionsNine);
    driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "nine");
    if (driCheckOption(&userInitOptions, "throttle_value", DRI_INT)) {
        throttling_value_user = driQueryOptioni(&userInitOptions, "throttle_value");
        if (throttling_value_user == -1)
            ctx->base.throttling = FALSE;
        else if (throttling_value_user >= 0) {
            ctx->base.throttling = TRUE;
            ctx->base.throttling_value = throttling_value_user;
        }
    }

    if (driCheckOption(&userInitOptions, "vblank_mode", DRI_ENUM))
        ctx->base.vblank_mode = driQueryOptioni(&userInitOptions, "vblank_mode");
    else
        ctx->base.vblank_mode = 1;

    if (driCheckOption(&userInitOptions, "thread_submit", DRI_BOOL)) {
        ctx->base.thread_submit = driQueryOptionb(&userInitOptions, "thread_submit");
        if (ctx->base.thread_submit && (throttling_value_user == -2 || throttling_value_user == 0)) {
            ctx->base.throttling_value = 0;
        } else if (ctx->base.thread_submit) {
            DBG("You have set a non standard throttling value in combination with thread_submit."
                "We advise to use a throttling value of -2/0");
        }
        if (ctx->base.thread_submit && !different_device)
            DBG("You have set thread_submit but do not use a different device than the server."
                "You should not expect any benefit.");
    }

    driDestroyOptionCache(&userInitOptions);
    driDestroyOptionInfo(&defaultInitOptions);

#if GALLIUM_STATIC_TARGETS
    ctx->base.ref = ninesw_create_screen(ctx->base.hal);
#else
    /* wrap it to create a software screen that can share resources */
    if (pipe_loader_sw_probe_wrapped(&ctx->swdev, ctx->base.hal)) {
        ctx->base.ref = NULL;
        for (i = 0; !ctx->base.ref && i < Elements(paths); ++i) {
            if (!paths[i]) { continue; }
            ctx->base.ref = pipe_loader_create_screen(ctx->swdev, paths[i]);
        }
    }
#endif
    if (!ctx->base.ref) {
        ERR("Couldn't wrap drm screen to swrast screen. Software devices "
            "will be unavailable.\n");
    }

    /* read out PCI info */
    read_descriptor(&ctx->base, fd);

    /* create and return new ID3DAdapter9 */
    hr = NineAdapter9_new(&ctx->base, (struct NineAdapter9 **)ppAdapter);
    if (FAILED(hr)) {
        drm_destroy(&ctx->base);
        return hr;
    }

    return D3D_OK;
}
Ejemplo n.º 6
0
struct vl_screen *
vl_dri3_screen_create(Display *display, int screen)
{
   struct vl_dri3_screen *scrn;
   const xcb_query_extension_reply_t *extension;
   xcb_dri3_open_cookie_t open_cookie;
   xcb_dri3_open_reply_t *open_reply;
   xcb_get_geometry_cookie_t geom_cookie;
   xcb_get_geometry_reply_t *geom_reply;
   int is_different_gpu;
   int fd;

   assert(display);

   scrn = CALLOC_STRUCT(vl_dri3_screen);
   if (!scrn)
      return NULL;

   scrn->conn = XGetXCBConnection(display);
   if (!scrn->conn)
      goto free_screen;

   xcb_prefetch_extension_data(scrn->conn , &xcb_dri3_id);
   xcb_prefetch_extension_data(scrn->conn, &xcb_present_id);
   extension = xcb_get_extension_data(scrn->conn, &xcb_dri3_id);
   if (!(extension && extension->present))
      goto free_screen;
   extension = xcb_get_extension_data(scrn->conn, &xcb_present_id);
   if (!(extension && extension->present))
      goto free_screen;

   open_cookie = xcb_dri3_open(scrn->conn, RootWindow(display, screen), None);
   open_reply = xcb_dri3_open_reply(scrn->conn, open_cookie, NULL);
   if (!open_reply)
      goto free_screen;
   if (open_reply->nfd != 1) {
      free(open_reply);
      goto free_screen;
   }

   fd = xcb_dri3_open_reply_fds(scrn->conn, open_reply)[0];
   if (fd < 0) {
      free(open_reply);
      goto free_screen;
   }
   fcntl(fd, F_SETFD, FD_CLOEXEC);
   free(open_reply);

   fd = loader_get_user_preferred_fd(fd, &is_different_gpu);
   /* TODO support different GPU */
   if (is_different_gpu)
      goto close_fd;

   geom_cookie = xcb_get_geometry(scrn->conn, RootWindow(display, screen));
   geom_reply = xcb_get_geometry_reply(scrn->conn, geom_cookie, NULL);
   if (!geom_reply)
      goto close_fd;
   /* TODO support depth other than 24 */
   if (geom_reply->depth != 24) {
      free(geom_reply);
      goto close_fd;
   }
   free(geom_reply);

   if (pipe_loader_drm_probe_fd(&scrn->base.dev, fd))
      scrn->base.pscreen = pipe_loader_create_screen(scrn->base.dev);

   if (!scrn->base.pscreen)
      goto release_pipe;

   scrn->base.destroy = vl_dri3_screen_destroy;
   scrn->base.texture_from_drawable = vl_dri3_screen_texture_from_drawable;
   scrn->base.get_dirty_area = vl_dri3_screen_get_dirty_area;
   scrn->base.get_timestamp = vl_dri3_screen_get_timestamp;
   scrn->base.set_next_timestamp = vl_dri3_screen_set_next_timestamp;
   scrn->base.get_private = vl_dri3_screen_get_private;
   scrn->base.pscreen->flush_frontbuffer = vl_dri3_flush_frontbuffer;

   return &scrn->base;

release_pipe:
   if (scrn->base.dev) {
      pipe_loader_release(&scrn->base.dev, 1);
      fd = -1;
   }
close_fd:
   if (fd != -1)
      close(fd);
free_screen:
   FREE(scrn);
   return 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.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);
}
Ejemplo n.º 8
0
XA_EXPORT struct xa_tracker *
xa_tracker_create(int drm_fd)
{
    struct xa_tracker *xa = calloc(1, sizeof(struct xa_tracker));
    enum xa_surface_type stype;
    unsigned int num_formats;
    int loader_fd;

    if (!xa)
	return NULL;

    loader_fd = dup(drm_fd);
    if (loader_fd == -1)
        return NULL;
    if (pipe_loader_drm_probe_fd(&xa->dev, loader_fd, false))
	xa->screen = pipe_loader_create_screen(xa->dev, PIPE_SEARCH_DIR);
    if (!xa->screen)
	goto out_no_screen;

    xa->default_ctx = xa_context_create(xa);
    if (!xa->default_ctx)
	goto out_no_pipe;

    num_formats = 0;
    for (stype = 0; stype < XA_LAST_SURFACE_TYPE; ++stype)
	num_formats += num_preferred[stype];

    num_formats += 1;
    xa->supported_formats = calloc(num_formats, sizeof(*xa->supported_formats));
    if (!xa->supported_formats)
	goto out_sf_alloc_fail;

    xa->supported_formats[0] = xa_format_unknown;
    num_formats = 1;
    memset(xa->format_map, 0, sizeof(xa->format_map));

    for (stype = 0; stype < XA_LAST_SURFACE_TYPE; ++stype) {
	unsigned int bind = stype_bind[stype];
	enum xa_formats xa_format;
	int i;

	for (i = 0; i < num_preferred[stype]; ++i) {
	    xa_format = preferred[stype][i];

	    struct xa_format_descriptor fdesc = xa_get_pipe_format(xa_format);

	    if (xa->screen->is_format_supported(xa->screen, fdesc.format,
						PIPE_TEXTURE_2D, 0, bind)) {
		if (xa->format_map[stype][0] == 0)
		    xa->format_map[stype][0] = num_formats;
		xa->format_map[stype][1] = num_formats;
		xa->supported_formats[num_formats++] = xa_format;
	    }
	}
    }
    return xa;

 out_sf_alloc_fail:
    xa_context_destroy(xa->default_ctx);
 out_no_pipe:
    xa->screen->destroy(xa->screen);
 out_no_screen:
    if (xa->dev)
	pipe_loader_release(&xa->dev, 1);
    free(xa);
    return NULL;
}
Ejemplo n.º 9
0
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);
}
Ejemplo n.º 10
0
static HRESULT WINAPI
drm_create_adapter( int fd,
                    ID3DAdapter9 **ppAdapter )
{
    struct d3dadapter9drm_context *ctx = CALLOC_STRUCT(d3dadapter9drm_context);
    HRESULT hr;
    int i;
    
    const char *paths[] = {
        getenv("D3D9_DRIVERS_PATH"),
        getenv("D3D9_DRIVERS_DIR"),
        PIPE_SEARCH_DIR
    };
    
    if (!ctx) { return E_OUTOFMEMORY; }

    ctx->base.resource_from_present = drm_resource_from_present;
    ctx->base.destroy = drm_destroy;

    /* use pipe-loader to dlopen appropriate drm driver */
    if (!pipe_loader_drm_probe_fd(&ctx->dev, fd, FALSE)) {
        DBG("Failed to probe drm fd %d.\n", fd);
        FREE(ctx);
        close(fd);
        return D3DERR_DRIVERINTERNALERROR;
    }

    /* use pipe-loader to create a drm screen (hal) */
    ctx->base.hal = NULL;
    for (i = 0; !ctx->base.hal && i < Elements(paths); ++i) {
        if (!paths[i]) { continue; }
        ctx->base.hal = pipe_loader_create_screen(ctx->dev, paths[i]);
    }
    if (!ctx->base.hal) {
        DBG("Unable to load requested driver.\n");
        pipe_loader_release(&ctx->dev, 1);
        FREE(ctx);
        return D3DERR_DRIVERINTERNALERROR;
    }
    
    /* wrap it to create a software screen that can share resources */
    if (pipe_loader_sw_probe_wrapped(&ctx->swdev, ctx->base.hal)) {
        ctx->base.ref = NULL;
        for (i = 0; !ctx->base.ref && i < Elements(paths); ++i) {
            if (!paths[i]) { continue; }
            ctx->base.ref = pipe_loader_create_screen(ctx->swdev, paths[i]);
        }
    }
    if (!ctx->base.ref) {
        DBG("Couldn't wrap drm screen to swrast screen. Software devices "
            "will be unavailable.\n");
    }
    
    /* read out PCI info */
    read_descriptor(&ctx->base, fd);

    /* create and return new ID3DAdapter9 */
    hr = NineAdapter9_new(&ctx->base, (struct NineAdapter9 **)ppAdapter);
    if (FAILED(hr)) {
        if (ctx->swdev) { pipe_loader_release(&ctx->swdev, 1); }
        pipe_loader_release(&ctx->dev, 1);
        FREE(ctx);
        return hr;
    }
    
    return D3D_OK;
}
Ejemplo n.º 11
0
Archivo: drm.c Proyecto: iXit/Mesa-3D
static HRESULT WINAPI
drm_create_adapter( int fd,
                    ID3DAdapter9 **ppAdapter )
{
    struct d3dadapter9drm_context *ctx = CALLOC_STRUCT(d3dadapter9drm_context);
    HRESULT hr;
    bool different_device;
    driOptionCache defaultInitOptions;
    driOptionCache userInitOptions;
    int throttling_value_user = -2;
    int override_vendorid = -1;

    if (!ctx) { return E_OUTOFMEMORY; }

    ctx->base.destroy = drm_destroy;

    /* Although the fd is provided from external source, mesa/nine
     * takes ownership of it. */
    fd = loader_get_user_preferred_fd(fd, &different_device);
    ctx->fd = fd;
    ctx->base.linear_framebuffer = different_device;

    if (!pipe_loader_drm_probe_fd(&ctx->dev, fd)) {
        ERR("Failed to probe drm fd %d.\n", fd);
        FREE(ctx);
        close(fd);
        return D3DERR_DRIVERINTERNALERROR;
    }

    ctx->base.hal = pipe_loader_create_screen(ctx->dev);
    if (!ctx->base.hal) {
        ERR("Unable to load requested driver.\n");
        drm_destroy(&ctx->base);
        return D3DERR_DRIVERINTERNALERROR;
    }

    if (!ctx->base.hal->get_param(ctx->base.hal, PIPE_CAP_DMABUF)) {
        ERR("The driver is not capable of dma-buf sharing."
            "Abandon to load nine state tracker\n");
        drm_destroy(&ctx->base);
        return D3DERR_DRIVERINTERNALERROR;
    }

    /* Previously was set to PIPE_CAP_MAX_FRAMES_IN_FLIGHT,
     * but the change of value of this cap to 1 seems to cause
     * regressions. */
    ctx->base.throttling_value = 2;
    ctx->base.throttling = ctx->base.throttling_value > 0;

    driParseOptionInfo(&defaultInitOptions, __driConfigOptionsNine);
    driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "nine", NULL);
    if (driCheckOption(&userInitOptions, "throttle_value", DRI_INT)) {
        throttling_value_user = driQueryOptioni(&userInitOptions, "throttle_value");
        if (throttling_value_user == -1)
            ctx->base.throttling = FALSE;
        else if (throttling_value_user >= 0) {
            ctx->base.throttling = TRUE;
            ctx->base.throttling_value = throttling_value_user;
        }
    }

    if (driCheckOption(&userInitOptions, "vblank_mode", DRI_ENUM))
        ctx->base.vblank_mode = driQueryOptioni(&userInitOptions, "vblank_mode");
    else
        ctx->base.vblank_mode = 1;

    if (driCheckOption(&userInitOptions, "thread_submit", DRI_BOOL))
        ctx->base.thread_submit = driQueryOptionb(&userInitOptions, "thread_submit");
    else
        ctx->base.thread_submit = different_device;

    if (driCheckOption(&userInitOptions, "override_vendorid", DRI_INT)) {
        override_vendorid = driQueryOptioni(&userInitOptions, "override_vendorid");
    }

    if (driCheckOption(&userInitOptions, "discard_delayed_release", DRI_BOOL))
        ctx->base.discard_delayed_release = driQueryOptionb(&userInitOptions, "discard_delayed_release");
    else
        ctx->base.discard_delayed_release = TRUE;

    if (driCheckOption(&userInitOptions, "tearfree_discard", DRI_BOOL))
        ctx->base.tearfree_discard = driQueryOptionb(&userInitOptions, "tearfree_discard");
    else
        ctx->base.tearfree_discard = FALSE;

    if (ctx->base.tearfree_discard && !ctx->base.discard_delayed_release) {
        ERR("tearfree_discard requires discard_delayed_release\n");
        ctx->base.tearfree_discard = FALSE;
    }

    if (driCheckOption(&userInitOptions, "csmt_force", DRI_INT))
        ctx->base.csmt_force = driQueryOptioni(&userInitOptions, "csmt_force");
    else
        ctx->base.csmt_force = -1;

    if (driCheckOption(&userInitOptions, "dynamic_texture_workaround", DRI_BOOL))
        ctx->base.dynamic_texture_workaround = driQueryOptionb(&userInitOptions, "dynamic_texture_workaround");
    else
        ctx->base.dynamic_texture_workaround = FALSE;

    if (driCheckOption(&userInitOptions, "shader_inline_constants", DRI_BOOL))
        ctx->base.shader_inline_constants = driQueryOptionb(&userInitOptions, "shader_inline_constants");
    else
        ctx->base.shader_inline_constants = FALSE;

    driDestroyOptionCache(&userInitOptions);
    driDestroyOptionInfo(&defaultInitOptions);

    /* wrap it to create a software screen that can share resources */
    if (pipe_loader_sw_probe_wrapped(&ctx->swdev, ctx->base.hal))
        ctx->base.ref = pipe_loader_create_screen(ctx->swdev);

    if (!ctx->base.ref) {
        ERR("Couldn't wrap drm screen to swrast screen. Software devices "
            "will be unavailable.\n");
    }

    /* read out PCI info */
    read_descriptor(&ctx->base, fd, override_vendorid);

    /* create and return new ID3DAdapter9 */
    hr = NineAdapter9_new(&ctx->base, (struct NineAdapter9 **)ppAdapter);
    if (FAILED(hr)) {
        drm_destroy(&ctx->base);
        return hr;
    }

    return D3D_OK;
}
Ejemplo n.º 12
0
struct vl_screen *
vl_dri2_screen_create(Display *display, int screen)
{
   struct vl_dri_screen *scrn;
   const xcb_query_extension_reply_t *extension;
   xcb_dri2_query_version_cookie_t dri2_query_cookie;
   xcb_dri2_query_version_reply_t *dri2_query = NULL;
   xcb_dri2_connect_cookie_t connect_cookie;
   xcb_dri2_connect_reply_t *connect = NULL;
   xcb_dri2_authenticate_cookie_t authenticate_cookie;
   xcb_dri2_authenticate_reply_t *authenticate = NULL;
   xcb_screen_iterator_t s;
   xcb_generic_error_t *error = NULL;
   char *device_name;
   int fd, device_name_length;
   unsigned driverType;

   drm_magic_t magic;

   assert(display);

   scrn = CALLOC_STRUCT(vl_dri_screen);
   if (!scrn)
      return NULL;

   scrn->conn = XGetXCBConnection(display);
   if (!scrn->conn)
      goto free_screen;

   xcb_prefetch_extension_data(scrn->conn, &xcb_dri2_id);

   extension = xcb_get_extension_data(scrn->conn, &xcb_dri2_id);
   if (!(extension && extension->present))
      goto free_screen;

   dri2_query_cookie = xcb_dri2_query_version (scrn->conn,
                                               XCB_DRI2_MAJOR_VERSION,
                                               XCB_DRI2_MINOR_VERSION);
   dri2_query = xcb_dri2_query_version_reply (scrn->conn, dri2_query_cookie, &error);
   if (dri2_query == NULL || error != NULL || dri2_query->minor_version < 2)
      goto free_query;

   s = xcb_setup_roots_iterator(xcb_get_setup(scrn->conn));
   scrn->base.xcb_screen = get_xcb_screen(s, screen);
   if (!scrn->base.xcb_screen)
      goto free_query;

   driverType = XCB_DRI2_DRIVER_TYPE_DRI;
   {
      char *prime = getenv("DRI_PRIME");
      if (prime) {
         unsigned primeid;
         errno = 0;
         primeid = strtoul(prime, NULL, 0);
         if (errno == 0)
            driverType |=
               ((primeid & DRI2DriverPrimeMask) << DRI2DriverPrimeShift);
      }
   }

   connect_cookie = xcb_dri2_connect_unchecked(
      scrn->conn, ((xcb_screen_t *)(scrn->base.xcb_screen))->root, driverType);
   connect = xcb_dri2_connect_reply(scrn->conn, connect_cookie, NULL);
   if (connect == NULL ||
       connect->driver_name_length + connect->device_name_length == 0)
      goto free_connect;

   device_name_length = xcb_dri2_connect_device_name_length(connect);
   device_name = CALLOC(1, device_name_length + 1);
   if (!device_name)
      goto free_connect;
   memcpy(device_name, xcb_dri2_connect_device_name(connect), device_name_length);
   fd = loader_open_device(device_name);
   free(device_name);

   if (fd < 0)
      goto free_connect;

   if (drmGetMagic(fd, &magic))
      goto close_fd;

   authenticate_cookie = xcb_dri2_authenticate_unchecked(
      scrn->conn, ((xcb_screen_t *)(scrn->base.xcb_screen))->root, magic);
   authenticate = xcb_dri2_authenticate_reply(scrn->conn, authenticate_cookie, NULL);

   if (authenticate == NULL || !authenticate->authenticated)
      goto free_authenticate;

   if (pipe_loader_drm_probe_fd(&scrn->base.dev, fd))
      scrn->base.pscreen = pipe_loader_create_screen(scrn->base.dev);

   if (!scrn->base.pscreen)
      goto release_pipe;

   scrn->base.destroy = vl_dri2_screen_destroy;
   scrn->base.texture_from_drawable = vl_dri2_screen_texture_from_drawable;
   scrn->base.get_dirty_area = vl_dri2_screen_get_dirty_area;
   scrn->base.get_timestamp = vl_dri2_screen_get_timestamp;
   scrn->base.set_next_timestamp = vl_dri2_screen_set_next_timestamp;
   scrn->base.get_private = vl_dri2_screen_get_private;
   scrn->base.pscreen->flush_frontbuffer = vl_dri2_flush_frontbuffer;
   vl_compositor_reset_dirty_area(&scrn->dirty_areas[0]);
   vl_compositor_reset_dirty_area(&scrn->dirty_areas[1]);

   /* The pipe loader duplicates the fd */
   close(fd);
   free(authenticate);
   free(connect);
   free(dri2_query);
   free(error);

   return &scrn->base;

release_pipe:
   if (scrn->base.dev)
      pipe_loader_release(&scrn->base.dev, 1);
free_authenticate:
   free(authenticate);
close_fd:
   close(fd);
free_connect:
   free(connect);
free_query:
   free(dri2_query);
   free(error);

free_screen:
   FREE(scrn);
   return NULL;
}
Ejemplo n.º 13
0
struct vl_screen *
vl_dri3_screen_create(Display *display, int screen)
{
   struct vl_dri3_screen *scrn;
   const xcb_query_extension_reply_t *extension;
   xcb_dri3_open_cookie_t open_cookie;
   xcb_dri3_open_reply_t *open_reply;
   xcb_get_geometry_cookie_t geom_cookie;
   xcb_get_geometry_reply_t *geom_reply;
   xcb_xfixes_query_version_cookie_t xfixes_cookie;
   xcb_xfixes_query_version_reply_t *xfixes_reply;
   xcb_generic_error_t *error;
   int fd;

   assert(display);

   scrn = CALLOC_STRUCT(vl_dri3_screen);
   if (!scrn)
      return NULL;

   scrn->conn = XGetXCBConnection(display);
   if (!scrn->conn)
      goto free_screen;

   xcb_prefetch_extension_data(scrn->conn , &xcb_dri3_id);
   xcb_prefetch_extension_data(scrn->conn, &xcb_present_id);
   xcb_prefetch_extension_data (scrn->conn, &xcb_xfixes_id);
   extension = xcb_get_extension_data(scrn->conn, &xcb_dri3_id);
   if (!(extension && extension->present))
      goto free_screen;
   extension = xcb_get_extension_data(scrn->conn, &xcb_present_id);
   if (!(extension && extension->present))
      goto free_screen;
   extension = xcb_get_extension_data(scrn->conn, &xcb_xfixes_id);
   if (!(extension && extension->present))
      goto free_screen;

   xfixes_cookie = xcb_xfixes_query_version(scrn->conn, XCB_XFIXES_MAJOR_VERSION,
                                            XCB_XFIXES_MINOR_VERSION);
   xfixes_reply = xcb_xfixes_query_version_reply(scrn->conn, xfixes_cookie, &error);
   if (!xfixes_reply || error || xfixes_reply->major_version < 2) {
      free(error);
      free(xfixes_reply);
      goto free_screen;
   }
   free(xfixes_reply);

   open_cookie = xcb_dri3_open(scrn->conn, RootWindow(display, screen), None);
   open_reply = xcb_dri3_open_reply(scrn->conn, open_cookie, NULL);
   if (!open_reply)
      goto free_screen;
   if (open_reply->nfd != 1) {
      free(open_reply);
      goto free_screen;
   }

   fd = xcb_dri3_open_reply_fds(scrn->conn, open_reply)[0];
   if (fd < 0) {
      free(open_reply);
      goto free_screen;
   }
   fcntl(fd, F_SETFD, FD_CLOEXEC);
   free(open_reply);

   fd = loader_get_user_preferred_fd(fd, &scrn->is_different_gpu);

   geom_cookie = xcb_get_geometry(scrn->conn, RootWindow(display, screen));
   geom_reply = xcb_get_geometry_reply(scrn->conn, geom_cookie, NULL);
   if (!geom_reply)
      goto close_fd;

   scrn->base.xcb_screen = dri3_get_screen_for_root(scrn->conn, geom_reply->root);
   if (!scrn->base.xcb_screen) {
      free(geom_reply);
      goto close_fd;
   }

   /* TODO support depth other than 24 or 30 */
   if (geom_reply->depth != 24 && geom_reply->depth != 30) {
      free(geom_reply);
      goto close_fd;
   }
   scrn->base.color_depth = geom_reply->depth;
   free(geom_reply);

   if (pipe_loader_drm_probe_fd(&scrn->base.dev, fd))
      scrn->base.pscreen = pipe_loader_create_screen(scrn->base.dev);

   if (!scrn->base.pscreen)
      goto release_pipe;

   scrn->pipe = scrn->base.pscreen->context_create(scrn->base.pscreen,
                                                   NULL, 0);
   if (!scrn->pipe)
       goto no_context;

   scrn->base.destroy = vl_dri3_screen_destroy;
   scrn->base.texture_from_drawable = vl_dri3_screen_texture_from_drawable;
   scrn->base.get_dirty_area = vl_dri3_screen_get_dirty_area;
   scrn->base.get_timestamp = vl_dri3_screen_get_timestamp;
   scrn->base.set_next_timestamp = vl_dri3_screen_set_next_timestamp;
   scrn->base.get_private = vl_dri3_screen_get_private;
   scrn->base.pscreen->flush_frontbuffer = vl_dri3_flush_frontbuffer;
   scrn->base.set_back_texture_from_output = vl_dri3_screen_set_back_texture_from_output;

   scrn->next_back = 1;
   return &scrn->base;

no_context:
   scrn->base.pscreen->destroy(scrn->base.pscreen);
release_pipe:
   if (scrn->base.dev) {
      pipe_loader_release(&scrn->base.dev, 1);
      fd = -1;
   }
close_fd:
   if (fd != -1)
      close(fd);
free_screen:
   FREE(scrn);
   return NULL;
}