Skip to content

Commit

Permalink
[host] d12: Use the gpu reported pitch instead of assuming w * 4
Browse files Browse the repository at this point in the history
  • Loading branch information
gnif committed Feb 23, 2024
1 parent 66049cf commit 2f3ca44
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions host/platform/Windows/capture/D12/d12.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct D12Interface
// capture format tracking
D3D12_RESOURCE_DESC captureFormat;
unsigned formatVer;
unsigned pitch;

// output format tracking
D3D12_RESOURCE_DESC dstFormat;
Expand Down Expand Up @@ -441,7 +442,6 @@ static CaptureResult d12_waitFrame(unsigned frameBufferIndex,
goto exit;
}


D3D12_RESOURCE_DESC srcFormat = ID3D12Resource_GetDesc(*src);
D3D12_RESOURCE_DESC dstFormat = this->dstFormat;

Expand Down Expand Up @@ -475,7 +475,19 @@ static CaptureResult d12_waitFrame(unsigned frameBufferIndex,
}
}

const unsigned int maxRows = maxFrameSize / (dstFormat.Width * 4);
D3D12_PLACED_SUBRESOURCE_FOOTPRINT layout;
ID3D12Device3_GetCopyableFootprints(*this->device,
&srcFormat,
0 , // FirstSubresource
1 , // NumSubresources
0 , // BaseOffset,
&layout , // pLayouts
NULL , // pNumRows,
NULL , // pRowSizeInBytes,
NULL); // pTotalBytes
this->pitch = layout.Footprint.RowPitch;

const unsigned int maxRows = maxFrameSize / layout.Footprint.RowPitch;

frame->formatVer = this->formatVer;
frame->screenWidth = srcFormat.Width;
Expand All @@ -485,8 +497,8 @@ static CaptureResult d12_waitFrame(unsigned frameBufferIndex,
frame->frameWidth = srcFormat.Width;
frame->frameHeight = srcFormat.Height;
frame->truncated = maxRows < dstFormat.Height;
frame->pitch = dstFormat.Width * 4;
frame->stride = dstFormat.Width;
frame->pitch = layout.Footprint.RowPitch;
frame->stride = layout.Footprint.RowPitch / 4;
frame->format = this->allowRGB24 ?
CAPTURE_FMT_BGR_32 : CAPTURE_FMT_BGRA;
frame->hdr = false;
Expand Down Expand Up @@ -584,7 +596,7 @@ static CaptureResult d12_getFrame(unsigned frameBufferIndex,
.Width = this->dstFormat.Width,
.Height = this->dstFormat.Height,
.Depth = 1,
.RowPitch = this->dstFormat.Width * 4
.RowPitch = this->pitch
}
}
};
Expand Down Expand Up @@ -678,7 +690,7 @@ static CaptureResult d12_getFrame(unsigned frameBufferIndex,

// signal the frame is complete
framebuffer_set_write_ptr(frameBuffer,
this->dstFormat.Height * this->dstFormat.Width * 4);
this->dstFormat.Height * this->pitch);

// reset the command queues
if (this->allowRGB24)
Expand Down

0 comments on commit 2f3ca44

Please sign in to comment.