HRESULT WINAPI GaNineD3DAdapter9Create(struct pipe_screen *s, ID3DAdapter9 **ppOut) { HRESULT hr; struct d3dadapter9_context_wddm *pCtx = NULL; hr = d3dadapter9_context_wddm_create(&pCtx, s); if (SUCCEEDED(hr)) { hr = NineAdapter9_new(&pCtx->base, (struct NineAdapter9 **)ppOut); if (FAILED(hr)) { /// @todo NineAdapter9_new calls this as ctx->base.destroy, // and will not call if memory allocation fails. // wddm_destroy(&pCtx->base); } } return hr; }
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; }
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; }
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; }