WIP
This commit is contained in:
@@ -96,6 +96,78 @@ bool D3D12SurfaceHandler::CopyNV12Frame(CUdeviceptr src_frame,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool D3D12SurfaceHandler::CopySeparateNV12Frame(CUdeviceptr src_frame,
|
||||
uint32_t src_pitch,
|
||||
ID3D12Resource* y_texture,
|
||||
ID3D12Resource* uv_texture,
|
||||
uint32_t width,
|
||||
uint32_t height)
|
||||
{
|
||||
// Get CUDA pointers for both Y and UV textures
|
||||
CUdeviceptr y_dst_ptr = 0;
|
||||
CUdeviceptr uv_dst_ptr = 0;
|
||||
|
||||
if (!GetD3D12CUDAPointer(y_texture, &y_dst_ptr)) {
|
||||
LOGF_ERROR("[D3D12SurfaceHandler] Failed to get CUDA pointer for Y texture");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GetD3D12CUDAPointer(uv_texture, &uv_dst_ptr)) {
|
||||
LOGF_ERROR("[D3D12SurfaceHandler] Failed to get CUDA pointer for UV texture");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get Y texture layout (R8_UNORM, ROW_MAJOR)
|
||||
D3D12_RESOURCE_DESC y_desc = y_texture->GetDesc();
|
||||
D3D12_PLACED_SUBRESOURCE_FOOTPRINT y_layout;
|
||||
UINT y_num_rows = 0;
|
||||
UINT64 y_row_size = 0;
|
||||
UINT64 y_total_bytes = 0;
|
||||
|
||||
m_device->GetCopyableFootprints(&y_desc, 0, 1, 0,
|
||||
&y_layout, &y_num_rows, &y_row_size, &y_total_bytes);
|
||||
|
||||
uint32_t y_dst_pitch = y_layout.Footprint.RowPitch;
|
||||
|
||||
// Get UV texture layout (RG8_UNORM, ROW_MAJOR)
|
||||
D3D12_RESOURCE_DESC uv_desc = uv_texture->GetDesc();
|
||||
D3D12_PLACED_SUBRESOURCE_FOOTPRINT uv_layout;
|
||||
UINT uv_num_rows = 0;
|
||||
UINT64 uv_row_size = 0;
|
||||
UINT64 uv_total_bytes = 0;
|
||||
|
||||
m_device->GetCopyableFootprints(&uv_desc, 0, 1, 0,
|
||||
&uv_layout, &uv_num_rows, &uv_row_size, &uv_total_bytes);
|
||||
|
||||
uint32_t uv_dst_pitch = uv_layout.Footprint.RowPitch;
|
||||
|
||||
LOGF_DEBUG("[D3D12SurfaceHandler] Separate textures: Y ptr=0x%llX, UV ptr=0x%llX", y_dst_ptr, uv_dst_ptr);
|
||||
LOGF_DEBUG("[D3D12SurfaceHandler] Y: width=%u, height=%u, pitch=%u, rows=%u",
|
||||
width, height, y_dst_pitch, y_num_rows);
|
||||
LOGF_DEBUG("[D3D12SurfaceHandler] UV: width=%u, height=%u, pitch=%u, rows=%u",
|
||||
width, height / 2, uv_dst_pitch, uv_num_rows);
|
||||
|
||||
// Copy Y plane
|
||||
if (!CopyYPlane(src_frame, src_pitch,
|
||||
y_dst_ptr, y_dst_pitch,
|
||||
width, y_num_rows)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy UV plane
|
||||
// NVDEC stores UV plane after Y plane with actual allocated rows
|
||||
CUdeviceptr src_uv = src_frame + (static_cast<UINT64>(src_pitch) * y_num_rows);
|
||||
|
||||
if (!CopyUVPlane(src_uv, src_pitch,
|
||||
uv_dst_ptr, uv_dst_pitch,
|
||||
width, uv_num_rows)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGF_DEBUG("[D3D12SurfaceHandler] Separate NV12 frame copied successfully");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool D3D12SurfaceHandler::SignalD3D12Fence(uint64_t fence_value)
|
||||
{
|
||||
// TODO: Implement fence signaling
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
D3D12SurfaceHandler(ID3D12Device* device, CUcontext cuda_context);
|
||||
~D3D12SurfaceHandler();
|
||||
|
||||
// Copy NV12 frame from CUDA to D3D12 texture
|
||||
// Copy NV12 frame from CUDA to D3D12 texture (legacy combined NV12 texture)
|
||||
// Returns true on success
|
||||
bool CopyNV12Frame(CUdeviceptr src_frame,
|
||||
uint32_t src_pitch,
|
||||
@@ -25,6 +25,17 @@ public:
|
||||
uint32_t width,
|
||||
uint32_t height);
|
||||
|
||||
// Copy NV12 frame from CUDA to separate Y and UV D3D12 textures
|
||||
// Y Plane: DXGI_FORMAT_R8_UNORM (width x height)
|
||||
// UV Plane: DXGI_FORMAT_R8G8_UNORM (width x height/2)
|
||||
// Returns true on success
|
||||
bool CopySeparateNV12Frame(CUdeviceptr src_frame,
|
||||
uint32_t src_pitch,
|
||||
ID3D12Resource* y_texture,
|
||||
ID3D12Resource* uv_texture,
|
||||
uint32_t width,
|
||||
uint32_t height);
|
||||
|
||||
// Signal D3D12 fence from CUDA stream (not implemented yet)
|
||||
bool SignalD3D12Fence(uint64_t fence_value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user