Example #1
0
/**
 * Destroy the per-screen private information.
 *
 * \internal
 * This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls
 * drmClose(), and finally frees \p screenPrivate.
 */
static void driDestroyScreen(__DRIscreen *psp)
{
    if (psp) {
        /* No interaction with the X-server is possible at this point.  This
         * routine is called after XCloseDisplay, so there is no protocol
         * stream open to the X-server anymore.
         */

        _mesa_destroy_shader_compiler();

        if (psp->DriverAPI.DestroyScreen)
            (*psp->DriverAPI.DestroyScreen)(psp);

        if (!psp->dri2.enabled) {
            (void)drmUnmap((drmAddress)psp->pSAREA, SAREA_MAX);
            (void)drmUnmap((drmAddress)psp->pFB, psp->fbSize);
            (void)drmCloseOnce(psp->fd);
        } else {
            driDestroyOptionCache(&psp->optionCache);
            driDestroyOptionInfo(&psp->optionInfo);
        }

        free(psp);
    }
}
void
intelDestroyContext(__DRIcontext * driContextPriv)
{
   struct brw_context *brw =
      (struct brw_context *) driContextPriv->driverPrivate;
   struct gl_context *ctx = &brw->ctx;

   assert(brw); /* should never be null */
   if (!brw)
      return;

   /* Dump a final BMP in case the application doesn't call SwapBuffers */
   if (INTEL_DEBUG & DEBUG_AUB) {
      intel_batchbuffer_flush(brw);
      aub_dump_bmp(&brw->ctx);
   }

   _mesa_meta_free(&brw->ctx);

   if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
      /* Force a report. */
      brw->shader_time.report_time = 0;

      brw_collect_and_report_shader_time(brw);
      brw_destroy_shader_time(brw);
   }

   brw_destroy_state(brw);
   brw_draw_destroy(brw);

   drm_intel_bo_unreference(brw->curbe.curbe_bo);

   free(brw->curbe.last_buf);
   free(brw->curbe.next_buf);

   drm_intel_gem_context_destroy(brw->hw_ctx);

   if (ctx->swrast_context) {
      _swsetup_DestroyContext(&brw->ctx);
      _tnl_DestroyContext(&brw->ctx);
   }
   _vbo_DestroyContext(&brw->ctx);

   if (ctx->swrast_context)
      _swrast_DestroyContext(&brw->ctx);

   intel_batchbuffer_free(brw);

   drm_intel_bo_unreference(brw->first_post_swapbuffers_batch);
   brw->first_post_swapbuffers_batch = NULL;

   driDestroyOptionCache(&brw->optionCache);

   /* free the Mesa context */
   _mesa_free_context_data(&brw->ctx);

   ralloc_free(brw);
   driContextPriv->driverPrivate = NULL;
}
Example #3
0
void
intelDestroyContext(__DRIcontext * driContextPriv)
{
   struct intel_context *intel =
      (struct intel_context *) driContextPriv->driverPrivate;

   assert(intel);               /* should never be null */
   if (intel) {
      GLboolean release_texture_heaps;

      INTEL_FIREVERTICES(intel);

      _mesa_meta_free(&intel->ctx);

      meta_destroy_metaops(&intel->meta);

      intel->vtbl.destroy(intel);

      release_texture_heaps = (intel->ctx.Shared->RefCount == 1);
      _swsetup_DestroyContext(&intel->ctx);
      _tnl_DestroyContext(&intel->ctx);
      _vbo_DestroyContext(&intel->ctx);

      _swrast_DestroyContext(&intel->ctx);
      intel->Fallback = 0x0;      /* don't call _swrast_Flush later */

      intel_batchbuffer_free(intel->batch);
      intel->batch = NULL;

      free(intel->prim.vb);
      intel->prim.vb = NULL;
      dri_bo_unreference(intel->prim.vb_bo);
      intel->prim.vb_bo = NULL;
      dri_bo_unreference(intel->first_post_swapbuffers_batch);
      intel->first_post_swapbuffers_batch = NULL;

      if (release_texture_heaps) {
         /* Nothing is currently done here to free texture heaps;
          * but we're not using the texture heap utilities, so I
          * rather think we shouldn't.  I've taken a look, and can't
          * find any private texture data hanging around anywhere, but
          * I'm not yet certain there isn't any at all...
          */
         /* if (INTEL_DEBUG & DEBUG_TEXTURE)
            fprintf(stderr, "do something to free texture heaps\n");
          */
      }

      driDestroyOptionCache(&intel->optionCache);

      /* free the Mesa context */
      _mesa_free_context_data(&intel->ctx);

      FREE(intel);
      driContextPriv->driverPrivate = NULL;
   }
}
Example #4
0
void
intelDestroyContext(__DRIcontext * driContextPriv)
{
   struct intel_context *intel =
      (struct intel_context *) driContextPriv->driverPrivate;
   struct gl_context *ctx = &intel->ctx;

   assert(intel);               /* should never be null */
   if (intel) {
      INTEL_FIREVERTICES(intel);

      /* Dump a final BMP in case the application doesn't call SwapBuffers */
      if (INTEL_DEBUG & DEBUG_AUB) {
         intel_batchbuffer_flush(intel);
	 aub_dump_bmp(&intel->ctx);
      }

      _mesa_meta_free(&intel->ctx);

      intel->vtbl.destroy(intel);

      if (ctx->swrast_context) {
         _swsetup_DestroyContext(&intel->ctx);
         _tnl_DestroyContext(&intel->ctx);
      }
      _vbo_DestroyContext(&intel->ctx);

      if (ctx->swrast_context)
         _swrast_DestroyContext(&intel->ctx);
      intel->Fallback = 0x0;      /* don't call _swrast_Flush later */

      intel_batchbuffer_free(intel);

      free(intel->prim.vb);
      intel->prim.vb = NULL;
      drm_intel_bo_unreference(intel->prim.vb_bo);
      intel->prim.vb_bo = NULL;
      drm_intel_bo_unreference(intel->first_post_swapbuffers_batch);
      intel->first_post_swapbuffers_batch = NULL;

      driDestroyOptionCache(&intel->optionCache);

      /* free the Mesa context */
      _mesa_free_context_data(&intel->ctx);

      _math_matrix_dtr(&intel->ViewportMatrix);

      ralloc_free(intel);
      driContextPriv->driverPrivate = NULL;
   }
}
Example #5
0
static char *loader_get_dri_config_device_id(void)
{
   driOptionCache defaultInitOptions;
   driOptionCache userInitOptions;
   char *prime = NULL;

   driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader);
   driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "loader");
   if (driCheckOption(&userInitOptions, "device_id", DRI_STRING))
      prime = strdup(driQueryOptionstr(&userInitOptions, "device_id"));
   driDestroyOptionCache(&userInitOptions);
   driDestroyOptionInfo(&defaultInitOptions);

   return prime;
}
Example #6
0
/**
 * Destroy the per-screen private information.
 * 
 * \internal
 * This function calls __DriverAPIRec::DestroyScreen on \p screenPrivate, calls
 * drmClose(), and finally frees \p screenPrivate.
 */
static void driDestroyScreen(__DRIscreen *psp)
{
    if (psp) {
	/* No interaction with the X-server is possible at this point.  This
	 * routine is called after XCloseDisplay, so there is no protocol
	 * stream open to the X-server anymore.
	 */

	psp->driver->DestroyScreen(psp);

	driDestroyOptionCache(&psp->optionCache);
	driDestroyOptionInfo(&psp->optionInfo);

	free(psp);
    }
}
Example #7
0
/* Destroy the device specific context.
 */
void r128DestroyContext( __DRIcontextPrivate *driContextPriv  )
{
   r128ContextPtr rmesa = (r128ContextPtr) driContextPriv->driverPrivate;

   assert(rmesa);  /* should never be null */
   if ( rmesa ) {
      GLboolean   release_texture_heaps;


      release_texture_heaps = (rmesa->glCtx->Shared->RefCount == 1);

      _swsetup_DestroyContext( rmesa->glCtx );
      _tnl_DestroyContext( rmesa->glCtx );
      _vbo_DestroyContext( rmesa->glCtx );
      _swrast_DestroyContext( rmesa->glCtx );

      if ( release_texture_heaps ) {
         /* This share group is about to go away, free our private
          * texture object data.
          */
         int i;

         for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
	    driDestroyTextureHeap( rmesa->texture_heaps[ i ] );
	    rmesa->texture_heaps[ i ] = NULL;
         }

	 assert( is_empty_list( & rmesa->swapped ) );
      }

      /* free the Mesa context */
      rmesa->glCtx->DriverCtx = NULL;
      _mesa_destroy_context(rmesa->glCtx);

      /* free the option cache */
      driDestroyOptionCache (&rmesa->optionCache);

      FREE( rmesa );
   }

#if 0
   /* Use this to force shared object profiling. */
   glx_fini_prof();
#endif
}
Example #8
0
void
intelDestroyContext(__DRIcontext * driContextPriv)
{
   struct brw_context *brw =
      (struct brw_context *) driContextPriv->driverPrivate;
   struct gl_context *ctx = &brw->ctx;

   assert(brw); /* should never be null */
   if (brw) {
      /* Dump a final BMP in case the application doesn't call SwapBuffers */
      if (INTEL_DEBUG & DEBUG_AUB) {
         intel_batchbuffer_flush(brw);
	 aub_dump_bmp(&brw->ctx);
      }

      _mesa_meta_free(&brw->ctx);

      brw->vtbl.destroy(brw);

      if (ctx->swrast_context) {
         _swsetup_DestroyContext(&brw->ctx);
         _tnl_DestroyContext(&brw->ctx);
      }
      _vbo_DestroyContext(&brw->ctx);

      if (ctx->swrast_context)
         _swrast_DestroyContext(&brw->ctx);

      intel_batchbuffer_free(brw);

      drm_intel_bo_unreference(brw->first_post_swapbuffers_batch);
      brw->first_post_swapbuffers_batch = NULL;

      driDestroyOptionCache(&brw->optionCache);

      /* free the Mesa context */
      _mesa_free_context_data(&brw->ctx);

      ralloc_free(brw);
      driContextPriv->driverPrivate = NULL;
   }
}
Example #9
0
File: drm.c Project: 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;
}
Example #10
0
/* Destroy the Mesa and driver specific context data.
 */
void r200DestroyContext( __DRIcontextPrivate *driContextPriv )
{
   GET_CURRENT_CONTEXT(ctx);
   r200ContextPtr rmesa = (r200ContextPtr) driContextPriv->driverPrivate;
   r200ContextPtr current = ctx ? R200_CONTEXT(ctx) : NULL;

   /* check if we're deleting the currently bound context */
   if (rmesa == current) {
      R200_FIREVERTICES( rmesa );
      _mesa_make_current(NULL, NULL, NULL);
   }

   /* Free r200 context resources */
   assert(rmesa); /* should never be null */
   if ( rmesa ) {
      GLboolean   release_texture_heaps;


      release_texture_heaps = (rmesa->glCtx->Shared->RefCount == 1);
      _swsetup_DestroyContext( rmesa->glCtx );
      _tnl_DestroyContext( rmesa->glCtx );
      _vbo_DestroyContext( rmesa->glCtx );
      _swrast_DestroyContext( rmesa->glCtx );

      r200DestroySwtcl( rmesa->glCtx );
      r200ReleaseArrays( rmesa->glCtx, ~0 );

      if (rmesa->dma.current.buf) {
	 r200ReleaseDmaRegion( rmesa, &rmesa->dma.current, __FUNCTION__ );
	 r200FlushCmdBuf( rmesa, __FUNCTION__ );
      }

      if (rmesa->state.scissor.pClipRects) {
	 FREE(rmesa->state.scissor.pClipRects);
	 rmesa->state.scissor.pClipRects = NULL;
      }

      if ( release_texture_heaps ) {
         /* This share group is about to go away, free our private
          * texture object data.
          */
         int i;

         for ( i = 0 ; i < rmesa->nr_heaps ; i++ ) {
	    driDestroyTextureHeap( rmesa->texture_heaps[ i ] );
	    rmesa->texture_heaps[ i ] = NULL;
         }

	 assert( is_empty_list( & rmesa->swapped ) );
      }

      /* free the Mesa context */
      rmesa->glCtx->DriverCtx = NULL;
      _mesa_destroy_context( rmesa->glCtx );

      /* free the option cache */
      driDestroyOptionCache (&rmesa->optionCache);

      FREE( rmesa );
   }
}
Example #11
0
File: drm.c Project: 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;
}