에러 복구 메커니즘 강화 (슬롯 정리 로직 추가)

This commit is contained in:
2025-10-07 04:03:15 +09:00
parent 23e7956375
commit f3fc17c796
5 changed files with 154 additions and 14 deletions

View File

@@ -188,6 +188,16 @@ bool D3D12SurfaceHandler::SignalD3D12Fence(uint64_t fence_value)
return true;
}
void D3D12SurfaceHandler::ReleaseD3D12Resource(ID3D12Resource* resource)
{
if (!resource) {
return;
}
LOGF_DEBUG("[D3D12SurfaceHandler] Releasing D3D12 resource from cache");
m_cache->Release(resource);
}
bool D3D12SurfaceHandler::GetD3D12CUDAPointer(ID3D12Resource* resource, CUdeviceptr* out_ptr)
{
return m_cache->GetOrCreateExternalMemory(resource, out_ptr);
@@ -328,8 +338,10 @@ bool D3D12SurfaceHandler::CopyRGBAToSurfaceViaKernel(CUsurfObject dst_surface,
unsigned int grid_x = (width + 15) / 16;
unsigned int grid_y = (height + 15) / 16;
LOGF_DEBUG("[D3D12SurfaceHandler] Launching kernel via Driver API: grid=(%u,%u), block=(%u,%u)",
grid_x, grid_y, block_x, block_y);
LOGF_DEBUG("[D3D12SurfaceHandler] Launching kernel: surface=0x%llX, src_rgba=0x%llX, width=%u, height=%u, pitch=%u",
(unsigned long long)dst_surface, (unsigned long long)src_rgba, width, height, src_pitch);
LOGF_DEBUG("[D3D12SurfaceHandler] Kernel params: grid=(%u,%u), block=(%u,%u), stream=%p, kernel=%p",
grid_x, grid_y, block_x, block_y, stream, m_surfaceWriteKernel);
// Driver API Unified Implementation:
// - Surface created with cuSurfObjectCreate (Driver API)

View File

@@ -50,6 +50,9 @@ public:
// Signal D3D12 fence from CUDA stream (not implemented yet)
bool SignalD3D12Fence(uint64_t fence_value);
// Release D3D12 resource from external memory cache
void ReleaseD3D12Resource(ID3D12Resource* resource);
private:
// Get CUDA device pointer for D3D12 resource (uses cache)
bool GetD3D12CUDAPointer(ID3D12Resource* resource, CUdeviceptr* out_ptr);

View File

@@ -1391,6 +1391,9 @@ bool NVDECAV1Decoder::DecodeToSurface(const uint8_t* packet_data, size_t packet_
// Copy to D3D12 surface (use target_surface from slot)
ID3D12Resource* d3d12Resource = static_cast<ID3D12Resource*>(my_slot.target_surface);
// Track D3D12 texture in slot for cleanup on error
my_slot.d3d12_texture = d3d12Resource;
// Check D3D12 texture format to determine if RGBA conversion is needed
D3D12_RESOURCE_DESC desc = d3d12Resource->GetDesc();
bool isRGBAFormat = (desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM ||
@@ -1451,6 +1454,26 @@ bool NVDECAV1Decoder::DecodeToSurface(const uint8_t* packet_data, size_t packet_
if (!copySuccess) {
LOGF_ERROR("[DecodeToSurface] Frame copy failed");
// Cleanup D3D12 resources on error
if (target_type == VAVCORE_SURFACE_D3D12_RESOURCE) {
LOGF_DEBUG("[DecodeToSurface] Cleaning up D3D12 resources after error");
// Release D3D12 texture from external memory cache
if (my_slot.d3d12_texture) {
LOGF_DEBUG("[DecodeToSurface] Releasing D3D12 texture from cache");
m_d3d12Handler->ReleaseD3D12Resource(my_slot.d3d12_texture);
my_slot.d3d12_texture = nullptr;
}
// Reset NV12ToRGBAConverter to clean state (forces reinitialization on next frame)
if (m_rgbaConverter) {
m_rgbaConverter.reset();
m_rgbaConverter = std::make_unique<NV12ToRGBAConverter>();
LOGF_DEBUG("[DecodeToSurface] NV12ToRGBAConverter reset after error");
}
}
my_slot.in_use.store(false);
m_returnCounter.fetch_add(1);
return false;
@@ -1470,9 +1493,14 @@ bool NVDECAV1Decoder::DecodeToSurface(const uint8_t* packet_data, size_t packet_
output_frame.timestamp_seconds = static_cast<double>(m_framesDecoded) / 30.0;
}
// 9. Release slot
// 9. Release slot and cleanup resources
{
std::lock_guard<std::mutex> lock(my_slot.slot_mutex);
// Clear D3D12 resource tracking (resources are managed by external memory cache)
my_slot.d3d12_texture = nullptr;
my_slot.surface_object = 0;
my_slot.in_use.store(false);
}

View File

@@ -15,6 +15,10 @@ namespace VavCore {
class NV12ToRGBAConverter;
}
// Forward declarations for D3D12 and CUDA types
struct ID3D12Resource;
typedef unsigned long long CUsurfObject;
// Forward declaration for CUDA external memory type
typedef struct CUexternalMemory_st* cudaExternalMemory_t;
typedef struct CUexternalSemaphore_st* cudaExternalSemaphore_t;
@@ -167,6 +171,10 @@ private:
// NVDEC information (set by HandlePictureDecode callback)
int picture_index = -1; // CurrPicIdx from NVDEC (same as slot index)
// D3D12 resource tracking for cleanup on error
ID3D12Resource* d3d12_texture = nullptr;
CUsurfObject surface_object = 0;
// Synchronization primitives
std::condition_variable frame_ready; // Signaled when decode complete
std::mutex slot_mutex; // Protects this slot's state