mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 06:47:19 +00:00
dxgi: cosmetics
This commit is contained in:
parent
cff64ee7d3
commit
f8b4874799
@ -132,7 +132,8 @@ static bool d3d12_create(struct DXGIInterface * intf)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
D3D12_COMMAND_QUEUE_DESC queueDesc = {
|
D3D12_COMMAND_QUEUE_DESC queueDesc =
|
||||||
|
{
|
||||||
.Type = D3D12_COMMAND_LIST_TYPE_COPY,
|
.Type = D3D12_COMMAND_LIST_TYPE_COPY,
|
||||||
.Priority = D3D12_COMMAND_QUEUE_PRIORITY_GLOBAL_REALTIME,
|
.Priority = D3D12_COMMAND_QUEUE_PRIORITY_GLOBAL_REALTIME,
|
||||||
.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE,
|
.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE,
|
||||||
@ -154,7 +155,8 @@ static bool d3d12_create(struct DXGIInterface * intf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dxgi->pitch = ALIGN_TO(dxgi->width * dxgi->bpp, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
|
dxgi->pitch = ALIGN_TO(dxgi->width * dxgi->bpp,
|
||||||
|
D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
|
||||||
dxgi->stride = dxgi->pitch / dxgi->bpp;
|
dxgi->stride = dxgi->pitch / dxgi->bpp;
|
||||||
|
|
||||||
this->texture = calloc(dxgi->maxTextures, sizeof(struct D3D12Texture));
|
this->texture = calloc(dxgi->maxTextures, sizeof(struct D3D12Texture));
|
||||||
@ -180,11 +182,13 @@ static bool d3d12_create(struct DXGIInterface * intf)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
D3D12_HEAP_PROPERTIES readbackHeapProperties = {
|
D3D12_HEAP_PROPERTIES readbackHeapProperties =
|
||||||
|
{
|
||||||
.Type = D3D12_HEAP_TYPE_READBACK,
|
.Type = D3D12_HEAP_TYPE_READBACK,
|
||||||
};
|
};
|
||||||
|
|
||||||
D3D12_RESOURCE_DESC texDesc = {
|
D3D12_RESOURCE_DESC texDesc =
|
||||||
|
{
|
||||||
.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER,
|
.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER,
|
||||||
.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT,
|
.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT,
|
||||||
.Width = dxgi->pitch * dxgi->height,
|
.Width = dxgi->pitch * dxgi->height,
|
||||||
@ -200,8 +204,15 @@ static bool d3d12_create(struct DXGIInterface * intf)
|
|||||||
|
|
||||||
for (int i = 0; i < dxgi->maxTextures; ++i)
|
for (int i = 0; i < dxgi->maxTextures; ++i)
|
||||||
{
|
{
|
||||||
status = ID3D12Device_CreateCommittedResource(this->device, &readbackHeapProperties, D3D12_HEAP_FLAG_NONE,
|
status = ID3D12Device_CreateCommittedResource(this->device,
|
||||||
&texDesc, D3D12_RESOURCE_STATE_COPY_DEST, NULL, &IID_ID3D12Resource, (void **)&this->texture[i].tex);
|
&readbackHeapProperties,
|
||||||
|
D3D12_HEAP_FLAG_NONE,
|
||||||
|
&texDesc,
|
||||||
|
D3D12_RESOURCE_STATE_COPY_DEST,
|
||||||
|
NULL,
|
||||||
|
&IID_ID3D12Resource,
|
||||||
|
(void **)&this->texture[i].tex);
|
||||||
|
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to create texture", status);
|
DEBUG_WINERROR("Failed to create texture", status);
|
||||||
@ -224,25 +235,36 @@ static bool d3d12_create(struct DXGIInterface * intf)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = ID3D12Device_CreateCommandAllocator(this->device, D3D12_COMMAND_LIST_TYPE_COPY,
|
status = ID3D12Device_CreateCommandAllocator(this->device,
|
||||||
&IID_ID3D12CommandAllocator, (void **)&this->texture[i].commandAllocator);
|
D3D12_COMMAND_LIST_TYPE_COPY,
|
||||||
|
&IID_ID3D12CommandAllocator,
|
||||||
|
(void **)&this->texture[i].commandAllocator);
|
||||||
|
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to create D3D12 command allocator", status);
|
DEBUG_WINERROR("Failed to create D3D12 command allocator", status);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = ID3D12Device_CreateCommandList(this->device, 0, D3D12_COMMAND_LIST_TYPE_COPY,
|
status = ID3D12Device_CreateCommandList(this->device,
|
||||||
this->texture[i].commandAllocator, NULL, &IID_ID3D12GraphicsCommandList,
|
0,
|
||||||
(void **)&this->texture[i].graphicsCommandList);
|
D3D12_COMMAND_LIST_TYPE_COPY,
|
||||||
|
this->texture[i].commandAllocator,
|
||||||
|
NULL,
|
||||||
|
&IID_ID3D12GraphicsCommandList,
|
||||||
|
(void **)&this->texture[i].graphicsCommandList);
|
||||||
|
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to create D3D12 command list", status);
|
DEBUG_WINERROR("Failed to create D3D12 command list", status);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = ID3D12GraphicsCommandList_QueryInterface(this->texture[i].graphicsCommandList,
|
status = ID3D12GraphicsCommandList_QueryInterface(
|
||||||
&IID_ID3D12CommandList, (void **)&this->texture[i].commandList);
|
this->texture[i].graphicsCommandList,
|
||||||
|
&IID_ID3D12CommandList,
|
||||||
|
(void **)&this->texture[i].commandList);
|
||||||
|
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to convert D3D12 command list", status);
|
DEBUG_WINERROR("Failed to convert D3D12 command list", status);
|
||||||
@ -337,14 +359,18 @@ static bool d3d12_copyFrame(Texture * parent, ID3D11Texture2D * src)
|
|||||||
|
|
||||||
if (handle == INVALID_HANDLE_VALUE)
|
if (handle == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
status = ID3D11Texture2D_QueryInterface(src, &IID_IDXGIResource1, (void **)&res1);
|
status = ID3D11Texture2D_QueryInterface(src,
|
||||||
|
&IID_IDXGIResource1, (void **)&res1);
|
||||||
|
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to get IDXGIResource1 from texture", status);
|
DEBUG_WINERROR("Failed to get IDXGIResource1 from texture", status);
|
||||||
return CAPTURE_RESULT_ERROR;
|
return CAPTURE_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = IDXGIResource1_CreateSharedHandle(res1, NULL, DXGI_SHARED_RESOURCE_READ, NULL, &handle);
|
status = IDXGIResource1_CreateSharedHandle(res1,
|
||||||
|
NULL, DXGI_SHARED_RESOURCE_READ, NULL, &handle);
|
||||||
|
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to get create shared handle for texture", status);
|
DEBUG_WINERROR("Failed to get create shared handle for texture", status);
|
||||||
@ -368,7 +394,9 @@ static bool d3d12_copyFrame(Texture * parent, ID3D11Texture2D * src)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status = ID3D12Device_OpenSharedHandle(this->device, handle, &IID_ID3D12Resource, (void **)&this->src);
|
status = ID3D12Device_OpenSharedHandle(this->device,
|
||||||
|
handle, &IID_ID3D12Resource, (void **)&this->src);
|
||||||
|
|
||||||
if (this->handleCacheCount == -1)
|
if (this->handleCacheCount == -1)
|
||||||
CloseHandle(handle);
|
CloseHandle(handle);
|
||||||
|
|
||||||
@ -379,18 +407,22 @@ static bool d3d12_copyFrame(Texture * parent, ID3D11Texture2D * src)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
D3D12_TEXTURE_COPY_LOCATION srcLoc = {
|
D3D12_TEXTURE_COPY_LOCATION srcLoc =
|
||||||
|
{
|
||||||
.pResource = this->src,
|
.pResource = this->src,
|
||||||
.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
|
.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
|
||||||
.SubresourceIndex = 0
|
.SubresourceIndex = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
D3D12_TEXTURE_COPY_LOCATION destLoc = {
|
D3D12_TEXTURE_COPY_LOCATION destLoc =
|
||||||
|
{
|
||||||
.pResource = tex->tex,
|
.pResource = tex->tex,
|
||||||
.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
|
.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
|
||||||
.PlacedFootprint = {
|
.PlacedFootprint =
|
||||||
|
{
|
||||||
.Offset = 0,
|
.Offset = 0,
|
||||||
.Footprint = {
|
.Footprint =
|
||||||
|
{
|
||||||
.Format = dxgi->dxgiFormat,
|
.Format = dxgi->dxgiFormat,
|
||||||
.Width = dxgi->width,
|
.Width = dxgi->width,
|
||||||
.Height = dxgi->height,
|
.Height = dxgi->height,
|
||||||
@ -401,19 +433,24 @@ static bool d3d12_copyFrame(Texture * parent, ID3D11Texture2D * src)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (parent->texDamageCount < 0)
|
if (parent->texDamageCount < 0)
|
||||||
ID3D12GraphicsCommandList_CopyTextureRegion(tex->graphicsCommandList, &destLoc,
|
ID3D12GraphicsCommandList_CopyTextureRegion(tex->graphicsCommandList,
|
||||||
0, 0, 0, &srcLoc, NULL);
|
&destLoc, 0, 0, 0, &srcLoc, NULL);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i = 0; i < parent->texDamageCount; ++i)
|
for (int i = 0; i < parent->texDamageCount; ++i)
|
||||||
{
|
{
|
||||||
FrameDamageRect * rect = parent->texDamageRects + i;
|
FrameDamageRect * rect = parent->texDamageRects + i;
|
||||||
D3D12_BOX box = {
|
D3D12_BOX box =
|
||||||
.left = rect->x, .top = rect->y, .front = 0, .back = 1,
|
{
|
||||||
.right = rect->x + rect->width, .bottom = rect->y + rect->height,
|
.left = rect->x,
|
||||||
|
.top = rect->y,
|
||||||
|
.front = 0,
|
||||||
|
.back = 1,
|
||||||
|
.right = rect->x + rect->width,
|
||||||
|
.bottom = rect->y + rect->height,
|
||||||
};
|
};
|
||||||
ID3D12GraphicsCommandList_CopyTextureRegion(tex->graphicsCommandList, &destLoc,
|
ID3D12GraphicsCommandList_CopyTextureRegion(tex->graphicsCommandList,
|
||||||
rect->x, rect->y, 0, &srcLoc, &box);
|
&destLoc, rect->x, rect->y, 0, &srcLoc, &box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,9 +462,11 @@ static bool d3d12_copyFrame(Texture * parent, ID3D11Texture2D * src)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ID3D12CommandQueue_ExecuteCommandLists(this->commandQueue, 1, &tex->commandList);
|
ID3D12CommandQueue_ExecuteCommandLists(this->commandQueue,
|
||||||
|
1, &tex->commandList);
|
||||||
|
|
||||||
status = ID3D12CommandQueue_Signal(this->commandQueue, this->fence, ++this->fenceValue);
|
status = ID3D12CommandQueue_Signal(this->commandQueue,
|
||||||
|
this->fence, ++this->fenceValue);
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to signal capture fence", status);
|
DEBUG_WINERROR("Failed to signal capture fence", status);
|
||||||
@ -436,7 +475,8 @@ static bool d3d12_copyFrame(Texture * parent, ID3D11Texture2D * src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResetEvent(this->event);
|
ResetEvent(this->event);
|
||||||
status = ID3D12Fence_SetEventOnCompletion(this->fence, this->fenceValue, this->event);
|
status = ID3D12Fence_SetEventOnCompletion(this->fence,
|
||||||
|
this->fenceValue, this->event);
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to signal capture fence event", status);
|
DEBUG_WINERROR("Failed to signal capture fence event", status);
|
||||||
@ -444,7 +484,8 @@ static bool d3d12_copyFrame(Texture * parent, ID3D11Texture2D * src)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = ID3D12CommandQueue_Signal(this->commandQueue, tex->fence, ++tex->fenceValue);
|
status = ID3D12CommandQueue_Signal(this->commandQueue,
|
||||||
|
tex->fence, ++tex->fenceValue);
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to signal texture fence", status);
|
DEBUG_WINERROR("Failed to signal texture fence", status);
|
||||||
@ -452,7 +493,8 @@ static bool d3d12_copyFrame(Texture * parent, ID3D11Texture2D * src)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = ID3D12Fence_SetEventOnCompletion(tex->fence, tex->fenceValue, tex->event);
|
status = ID3D12Fence_SetEventOnCompletion(tex->fence,
|
||||||
|
tex->fenceValue, tex->event);
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to signal texture fence event", status);
|
DEBUG_WINERROR("Failed to signal texture fence event", status);
|
||||||
@ -480,14 +522,19 @@ static CaptureResult d3d12_mapTexture(Texture * parent)
|
|||||||
return CAPTURE_RESULT_ERROR;
|
return CAPTURE_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = ID3D12GraphicsCommandList_Reset(tex->graphicsCommandList, tex->commandAllocator, NULL);
|
status = ID3D12GraphicsCommandList_Reset(tex->graphicsCommandList,
|
||||||
|
tex->commandAllocator, NULL);
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
{
|
{
|
||||||
DEBUG_WINERROR("Failed to reset command list", status);
|
DEBUG_WINERROR("Failed to reset command list", status);
|
||||||
return CAPTURE_RESULT_ERROR;
|
return CAPTURE_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
D3D12_RANGE range = { .Begin = 0, .End = dxgi->pitch * dxgi->height };
|
D3D12_RANGE range =
|
||||||
|
{
|
||||||
|
.Begin = 0,
|
||||||
|
.End = dxgi->pitch * dxgi->height
|
||||||
|
};
|
||||||
status = ID3D12Resource_Map(tex->tex, 0, &range, &parent->map);
|
status = ID3D12Resource_Map(tex->tex, 0, &range, &parent->map);
|
||||||
|
|
||||||
if (FAILED(status))
|
if (FAILED(status))
|
||||||
@ -503,7 +550,11 @@ static void d3d12_unmapTexture(Texture * parent)
|
|||||||
{
|
{
|
||||||
struct D3D12Texture * tex = parent->impl;
|
struct D3D12Texture * tex = parent->impl;
|
||||||
|
|
||||||
D3D12_RANGE range = { .Begin = 0, .End = 0 };
|
D3D12_RANGE range =
|
||||||
|
{
|
||||||
|
.Begin = 0,
|
||||||
|
.End = 0
|
||||||
|
};
|
||||||
ID3D12Resource_Unmap(tex->tex, 0, &range);
|
ID3D12Resource_Unmap(tex->tex, 0, &range);
|
||||||
parent->map = NULL;
|
parent->map = NULL;
|
||||||
}
|
}
|
||||||
@ -519,7 +570,8 @@ static void d3d12_preRelease(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DXGICopyBackend copyBackendD3D12 = {
|
struct DXGICopyBackend copyBackendD3D12 =
|
||||||
|
{
|
||||||
.name = "Direct3D 12",
|
.name = "Direct3D 12",
|
||||||
.code = "d3d12",
|
.code = "d3d12",
|
||||||
.create = d3d12_create,
|
.create = d3d12_create,
|
||||||
|
Loading…
Reference in New Issue
Block a user