#include "pch.h" #include "../src/Common/VideoTypes.h" #include "SimpleGPURenderer_Headless.h" using namespace Vav2Player; // Simple GPU Integration Test - Tests GPU infrastructure with mock YUV data int TestSimpleGPUIntegration() { std::cout << "\n=== Simple GPU Integration Test ===" << std::endl; std::cout << "Testing GPU YUV-to-RGB conversion with mock data" << std::endl; try { // 1. Initialize GPU renderer auto gpuRenderer = std::make_unique(); // Test video dimensions (small test frame) const uint32_t width = 640; const uint32_t height = 480; HRESULT hr = gpuRenderer->Initialize(width, height); if (FAILED(hr)) { std::cout << "[FAIL] GPU renderer initialization failed: 0x" << std::hex << hr << std::endl; return 1; } std::cout << "[PASS] GPU renderer initialized (" << width << "x" << height << ")" << std::endl; // 2. Create mock YUV420P frame data std::cout << "[TEST] Creating mock YUV420P test data..." << std::endl; // YUV420P: Y is full size, U/V are quarter size const uint32_t y_size = width * height; const uint32_t uv_size = (width / 2) * (height / 2); auto mock_frame = std::make_unique(); if (!mock_frame->AllocateYUV420P(width, height)) { std::cout << "[FAIL] Failed to allocate mock YUV frame" << std::endl; return 1; } // Fill with test pattern: // Y plane: gradient from black to white // U plane: blue tint // V plane: red tint for (uint32_t y = 0; y < height; y++) { for (uint32_t x = 0; x < width; x++) { uint32_t idx = y * width + x; // Y: horizontal gradient mock_frame->y_plane[idx] = static_cast((x * 255) / width); } } // U and V planes: constant colors for test pattern std::memset(mock_frame->u_plane.get(), 128 + 32, uv_size); // Slight blue tint std::memset(mock_frame->v_plane.get(), 128 - 32, uv_size); // Slight red tint mock_frame->is_valid = true; mock_frame->frame_index = 0; mock_frame->timestamp_seconds = 0.0; std::cout << "[PASS] Mock YUV420P frame created (Y:" << y_size << ", UV:" << uv_size << " bytes each)" << std::endl; // 3. Test GPU rendering std::cout << "[TEST] Testing GPU YUV-to-RGB conversion..." << std::endl; hr = gpuRenderer->RenderVideoFrame(*mock_frame); if (FAILED(hr)) { std::cout << "[FAIL] GPU YUV-to-RGB conversion failed: 0x" << std::hex << hr << std::endl; return 1; } std::cout << "[PASS] GPU YUV-to-RGB conversion completed successfully" << std::endl; // 4. Performance test with multiple frames std::cout << "[TEST] GPU performance test with 60 mock frames..." << std::endl; const int test_frames = 60; auto start_time = std::chrono::high_resolution_clock::now(); for (int i = 0; i < test_frames; i++) { // Modify frame data slightly to simulate real video mock_frame->frame_index = i; mock_frame->timestamp_seconds = i / 30.0; // 30fps simulation // Add simple animation: shift the gradient uint8_t offset = static_cast((i * 4) % 256); for (uint32_t y = 0; y < height; y++) { for (uint32_t x = 0; x < width; x++) { uint32_t idx = y * width + x; mock_frame->y_plane[idx] = static_cast(((x * 255) / width + offset) % 256); } } hr = gpuRenderer->RenderVideoFrame(*mock_frame); if (FAILED(hr)) { std::cout << "[WARN] Frame " << i << " rendering failed: 0x" << std::hex << hr << std::endl; continue; } if (i % 20 == 0) { std::cout << "[INFO] Processed " << i << " frames..." << std::endl; } } auto end_time = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration(end_time - start_time); // 5. Performance analysis std::cout << "\n=== GPU Performance Results ===" << std::endl; std::cout << "Total frames: " << test_frames << std::endl; std::cout << "Total time: " << duration.count() << " ms" << std::endl; double avg_time_per_frame = duration.count() / test_frames; double fps = 1000.0 / avg_time_per_frame; std::cout << "Average time per frame: " << avg_time_per_frame << " ms" << std::endl; std::cout << "Effective GPU FPS: " << fps << std::endl; // Performance evaluation if (fps >= 30.0) { std::cout << "[PASS] GPU performance meets 30fps target" << std::endl; } else if (fps >= 24.0) { std::cout << "[WARN] GPU performance below 30fps but above 24fps" << std::endl; } else { std::cout << "[FAIL] GPU performance below acceptable threshold" << std::endl; } std::cout << "[SUCCESS] Simple GPU integration test completed!" << std::endl; return 0; } catch (const std::exception& e) { std::cout << "[FAIL] Exception during GPU integration test: " << e.what() << std::endl; return 1; } catch (...) { std::cout << "[FAIL] Unknown exception during GPU integration test" << std::endl; return 1; } }