d3d12: Don't allocate mappable textures

There's not really a reason to directly map textures. Doing so
requires the texture to be allocated in system RAM instead of
video RAM, which means all GPU access to it would be needlessly slow.

Notably, the one texture type that was allocated this way is the
display target texture for the software driver path. Instead, use
pipe_transfer_map to be able to copy the texture to system RAM.

Reviewed-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8095>
This commit is contained in:
Jesse Natalie
2020-12-14 11:59:53 -08:00
parent 34bae108df
commit 0034f7b209
2 changed files with 19 additions and 23 deletions

View File

@@ -45,10 +45,9 @@
static bool
can_map_directly(struct pipe_resource *pres)
{
return pres->bind & (PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | PIPE_BIND_LINEAR) ||
(pres->target == PIPE_BUFFER &&
return pres->target == PIPE_BUFFER &&
pres->usage != PIPE_USAGE_DEFAULT &&
pres->usage != PIPE_USAGE_IMMUTABLE);
pres->usage != PIPE_USAGE_IMMUTABLE;
}
static void
@@ -217,16 +216,7 @@ init_texture(struct d3d12_screen *screen,
PIPE_BIND_SHARED | PIPE_BIND_LINEAR))
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
D3D12_HEAP_TYPE heap_type = D3D12_HEAP_TYPE_DEFAULT;
if (templ->bind & (PIPE_BIND_DISPLAY_TARGET |
PIPE_BIND_SCANOUT |
PIPE_BIND_SHARED))
heap_type = D3D12_HEAP_TYPE_READBACK;
else if (templ->usage == PIPE_USAGE_STAGING)
heap_type = D3D12_HEAP_TYPE_UPLOAD;
D3D12_HEAP_PROPERTIES heap_pris = screen->dev->GetCustomHeapProperties(0, heap_type);
D3D12_HEAP_PROPERTIES heap_pris = screen->dev->GetCustomHeapProperties(0, D3D12_HEAP_TYPE_DEFAULT);
HRESULT hres = screen->dev->CreateCommittedResource(&heap_pris,
D3D12_HEAP_FLAG_NONE,
@@ -237,9 +227,7 @@ init_texture(struct d3d12_screen *screen,
if (FAILED(hres))
return false;
if (screen->winsys && (templ->bind & (PIPE_BIND_DISPLAY_TARGET |
PIPE_BIND_SCANOUT |
PIPE_BIND_SHARED))) {
if (screen->winsys && (templ->bind & PIPE_BIND_DISPLAY_TARGET)) {
struct sw_winsys *winsys = screen->winsys;
res->dt = winsys->displaytarget_create(screen->winsys,
res->base.bind,

View File

@@ -621,27 +621,35 @@ d3d12_flush_frontbuffer(struct pipe_screen * pscreen,
struct d3d12_screen *screen = d3d12_screen(pscreen);
struct sw_winsys *winsys = screen->winsys;
struct d3d12_resource *res = d3d12_resource(pres);
ID3D12Resource *d3d12_res = d3d12_resource_resource(res);
if (!winsys)
if (!winsys || !pctx)
return;
if (pctx)
d3d12_flush_cmdlist_and_wait(d3d12_context(pctx));
assert(res->dt);
void *map = winsys->displaytarget_map(winsys, res->dt, 0);
if (map) {
d3d12_res->ReadFromSubresource(map, res->dt_stride, 0, 0, NULL);
pipe_transfer *transfer = nullptr;
void *res_map = pipe_transfer_map(pctx, pres, level, layer, PIPE_MAP_READ, 0, 0,
u_minify(pres->width0, level),
u_minify(pres->height0, level),
&transfer);
if (res_map) {
util_copy_rect((ubyte*)map, pres->format, res->dt_stride, 0, 0,
transfer->box.width, transfer->box.height,
(const ubyte*)res_map, transfer->stride, 0, 0);
pipe_transfer_unmap(pctx, transfer);
}
winsys->displaytarget_unmap(winsys, res->dt);
}
#ifdef _WIN32
// WindowFromDC is Windows-only, and this method requires an HWND, so only use it on Windows
ID3D12SharingContract *sharing_contract;
if (SUCCEEDED(screen->cmdqueue->QueryInterface(IID_PPV_ARGS(&sharing_contract))))
if (SUCCEEDED(screen->cmdqueue->QueryInterface(IID_PPV_ARGS(&sharing_contract)))) {
ID3D12Resource *d3d12_res = d3d12_resource_resource(res);
sharing_contract->Present(d3d12_res, 0, WindowFromDC((HDC)winsys_drawable_handle));
}
#endif
winsys->displaytarget_display(winsys, res->dt, winsys_drawable_handle, sub_box);