diff --git a/CMakeLists.txt b/CMakeLists.txt index 06c6fcd..fd41d2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,14 +18,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") option(BUILD_GVFG_SAMPLES "Build GVFG customer samples" ON) -option(GVFG_ENABLE_INTERNAL_DEBUG_API "Export internal GVFG diagnostic APIs" OFF) option(BUILD_GVFG_INTERNAL_TOOLS "Build internal driver/FPGA diagnostic tools" OFF) -if (BUILD_GVFG_INTERNAL_TOOLS AND NOT GVFG_ENABLE_INTERNAL_DEBUG_API) - message(FATAL_ERROR - "BUILD_GVFG_INTERNAL_TOOLS requires GVFG_ENABLE_INTERNAL_DEBUG_API=ON") -endif() - if (NOT WIN32) message(FATAL_ERROR "GVFG currently supports Windows only.") endif() @@ -43,7 +37,7 @@ install(FILES DESTINATION ${CMAKE_INSTALL_DOCDIR} ) -if (GVFG_ENABLE_INTERNAL_DEBUG_API) +if (BUILD_GVFG_INTERNAL_TOOLS) install(FILES README.md docs/GVFG_INTERNAL_NOTES.md diff --git a/CaptureDemo/0714_y210/pcie_s2mm_driver/pcie_s2mm_driver.cat b/CaptureDemo/0714_y210/pcie_s2mm_driver/pcie_s2mm_driver.cat new file mode 100644 index 0000000..9b99380 Binary files /dev/null and b/CaptureDemo/0714_y210/pcie_s2mm_driver/pcie_s2mm_driver.cat differ diff --git a/CaptureDemo/0714_y210/pcie_s2mm_driver/pcie_s2mm_driver.inf b/CaptureDemo/0714_y210/pcie_s2mm_driver/pcie_s2mm_driver.inf new file mode 100644 index 0000000..058f96a --- /dev/null +++ b/CaptureDemo/0714_y210/pcie_s2mm_driver/pcie_s2mm_driver.inf @@ -0,0 +1,98 @@ +; +; pcie_s2mm_driver.inf +; + +[Version] +Signature="$WINDOWS NT$" +Class=Sample ; TODO: edit Class +ClassGuid={78A1C341-4539-11d3-B88D-00C04FAD5171} ; TODO: edit ClassGuid +Provider=%ManufacturerName% +CatalogFile=pcie_s2mm_driver.cat +DriverVer = 07/20/2026,15.7.4.909 + +[DestinationDirs] +DefaultDestDir = 12 +pcie_s2mm_driver_Device_CoInstaller_CopyFiles = 11 + +; ================= Class section ===================== + +[ClassInstall32] +Addreg=SampleClassReg + +[SampleClassReg] +HKR,,,0,%ClassName% +HKR,,Icon,,-5 + +[SourceDisksNames] +1 = %DiskName%,,,"" + +[SourceDisksFiles] +pcie_s2mm_driver.sys = 1,, +; + + +;***************************************** +; Install Section +;***************************************** + +[Manufacturer] +%ManufacturerName%=Standard,NTamd64 + +[Standard.NTamd64] +%pcie_s2mm_driver.DeviceDesc%=pcie_s2mm_driver_Device, PCI\VEN_10EE&DEV_7024 ; PCIe device match + +[pcie_s2mm_driver_Device.NT] +CopyFiles=Drivers_Dir + +[Drivers_Dir] +pcie_s2mm_driver.sys + +[pcie_s2mm_driver_Device.NT.HW] +AddReg = AddInterruptReg + +[AddInterruptReg] +HKR,"Interrupt Management",,0x00000010 +HKR,"Interrupt Management\MessageSignaledInterruptProperties",,0x00000010 +HKR,"Interrupt Management\MessageSignaledInterruptProperties",MSISupported,0x00010001,1 +HKR,"Interrupt Management\MessageSignaledInterruptPropperties",MessageNumberLimit,0x00010001,24 + +;-------------- Service installation +[pcie_s2mm_driver_Device.NT.Services] +AddService = pcie_s2mm_driver,%SPSVCINST_ASSOCSERVICE%, pcie_s2mm_driver_Service_Inst + +; -------------- pcie_s2mm_driver driver install sections +[pcie_s2mm_driver_Service_Inst] +DisplayName = %pcie_s2mm_driver.SVCDESC% +ServiceType = 1 ; SERVICE_KERNEL_DRIVER +StartType = 3 ; SERVICE_DEMAND_START +ErrorControl = 1 ; SERVICE_ERROR_NORMAL +ServiceBinary = %12%\pcie_s2mm_driver.sys + +; +;--- pcie_s2mm_driver_Device Coinstaller installation ------ +; + +[pcie_s2mm_driver_Device.NT.CoInstallers] +AddReg=pcie_s2mm_driver_Device_CoInstaller_AddReg +CopyFiles=pcie_s2mm_driver_Device_CoInstaller_CopyFiles + +[pcie_s2mm_driver_Device_CoInstaller_AddReg] +; + + +[pcie_s2mm_driver_Device_CoInstaller_CopyFiles] +; + + +[pcie_s2mm_driver_Device.NT.Wdf] +KmdfService = pcie_s2mm_driver, pcie_s2mm_driver_wdfsect +[pcie_s2mm_driver_wdfsect] +KmdfLibraryVersion = 1.15 + +[Strings] +SPSVCINST_ASSOCSERVICE= 0x00000002 +ManufacturerName="" ;TODO: Replace with your manufacturer name +ClassName="Samples" ; TODO: edit ClassName +DiskName = "pcie_s2mm_driver Installation Disk" +pcie_s2mm_driver.DeviceDesc = "pcie_s2mm_driver Device" +pcie_s2mm_driver.SVCDESC = "pcie_s2mm_driver Service" diff --git a/CaptureDemo/0714_y210/pcie_s2mm_driver/pcie_s2mm_driver.sys b/CaptureDemo/0714_y210/pcie_s2mm_driver/pcie_s2mm_driver.sys new file mode 100644 index 0000000..6cc5f9a Binary files /dev/null and b/CaptureDemo/0714_y210/pcie_s2mm_driver/pcie_s2mm_driver.sys differ diff --git a/helpers/gvfg_preview/src/d3d_preview_pipeline.cpp b/helpers/gvfg_preview/src/d3d_preview_pipeline.cpp index 3caf497..506f224 100644 --- a/helpers/gvfg_preview/src/d3d_preview_pipeline.cpp +++ b/helpers/gvfg_preview/src/d3d_preview_pipeline.cpp @@ -18,13 +18,6 @@ static void d3d_preview_log_debug(const char *message) OutputDebugStringA(message ? message : ""); } -static inline uint16_t normalize_y210_word_for_upload(uint16_t v) -{ - // Y210 stores each 10-bit component left-aligned in a 16-bit WORD. - // Bits [15:6] are valid, bits [5:0] are padding. - return static_cast((v >> 6) & 0x03FFu); -} - static const char *ss_dxgi_format_name(DXGI_FORMAT fmt) { switch (fmt) @@ -58,8 +51,6 @@ VSOut main(VSIn i){ } )"; - - // YUY2 4:2:2 packed input. // Each upload texture texel stores two pixels as R=Y0, G=U, B=Y1, A=V. // R=Y0, G=U, B=Y1, A=V @@ -170,12 +161,17 @@ float4 main(float4 pos:SV_Position, float2 uv:TEXCOORD0) : SV_Target } )"; -// Y210 4:2:2 packed input with each 10-bit component stored in a 16-bit word. -// Each upload texture texel stores two pixels as R=Y0, G=U, B=Y1, A=V. +// Raw FPGA Y210 payload with each 10-bit component left-aligned in a 16-bit word. +// Each upload texture texel stores two pixels as R=Y0, G=V, B=Y1, A=U. +// The shader performs the 10-bit normalization and U/V reorder. // texture width = ceil(w/2), format = R16G16B16A16_UINT static const char *g_ps_y210 = R"( Texture2D texP : register(t0); +// true: interpret the raw chroma words as Y0,V,Y1,U. +// false: interpret them as standard Y210 Y0,U,Y1,V. +static const bool kSwapUV = true; + cbuffer ProcAmp : register(b0) { uint width; @@ -231,7 +227,7 @@ float loadY(int x, int y) x = clamp(x, 0, (int)width - 1); y = clamp(y, 0, (int)height - 1); uint4 p = texP.Load(int3(x >> 1, y, 0)); - uint yy = ((x & 1) != 0) ? p.b : p.r; + uint yy = (((x & 1) != 0) ? p.b : p.r) >> 6; return (float)(yy & 1023) / 1023.0; } @@ -240,8 +236,21 @@ float2 loadUV01(int x, int y) x = clamp(x, 0, (int)width - 1); y = clamp(y, 0, (int)height - 1); uint4 p = texP.Load(int3(x >> 1, y, 0)); - float u = (float)(p.g & 1023) / 1023.0; - float v = (float)(p.a & 1023) / 1023.0; + uint chroma1 = (p.g >> 6) & 1023; + uint chroma2 = (p.a >> 6) & 1023; + uint u10 = kSwapUV ? chroma2 : chroma1; + uint v10 = kSwapUV ? chroma1 : chroma2; + // An odd-width tail has no complete second chroma word; match the old + // upload behavior by reusing the available chroma component. + if (((width & 1) != 0) && x == (int)width - 1) + { + if (kSwapUV) + u10 = v10; + else + v10 = u10; + } + float u = (float)u10 / 1023.0; + float v = (float)v10 / 1023.0; return float2(u, v); } @@ -268,7 +277,6 @@ float4 main(float4 pos:SV_Position, float2 uv:TEXCOORD0) : SV_Target } )"; - static const char *g_ps_fp16_to_rgba8 = R"( Texture2D tex0 : register(t0); SamplerState samL : register(s0); @@ -322,7 +330,7 @@ float4 main(PSIn i) : SV_Target )"; bool D3DPreviewPipeline::initialize(ID3D11Device *d3d, - ID3D11DeviceContext *ctx) + ID3D11DeviceContext *ctx) { d3d_ = d3d; ctx_ = ctx; @@ -655,31 +663,17 @@ bool D3DPreviewPipeline::upload_y210_frame(const uint8_t *data, int src_stride, if (FAILED(ctx_->Map(upload_y210_packed_.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &m))) return false; - const size_t rowBytes = (size_t)frame_w * 4u; + const size_t sourceRowBytes = (size_t)frame_w * 4u; + const size_t textureRowBytes = (size_t)w2 * 8u; for (int row = 0; row < frame_h; ++row) { const uint8_t *srcRow = data + (size_t)row * (size_t)effectiveStride; uint8_t *dstRow = static_cast(m.pData) + (size_t)row * (size_t)m.RowPitch; - const uint16_t *src16 = reinterpret_cast(srcRow); - uint16_t *dst16 = reinterpret_cast(dstRow); - const int rowWords = (int)(rowBytes / 2u); - - for (int x = 0; x < w2; ++x) - { - const int srcX = x * 4; - // Standard Y210 is Y0, Cb(U), Y1, Cr(V). The current FPGA DMA - // payload arrives as Y0, Cr(V), Y1, Cb(U), so normalize it here. - const uint16_t Y0 = normalize_y210_word_for_upload(src16[srcX + 0]); - const uint16_t V = normalize_y210_word_for_upload(src16[srcX + 1]); - const uint16_t Y1 = (srcX + 2 < rowWords) ? normalize_y210_word_for_upload(src16[srcX + 2]) : Y0; - const uint16_t U = (srcX + 3 < rowWords) ? normalize_y210_word_for_upload(src16[srcX + 3]) : V; - - uint16_t *d4 = dst16 + x * 4; - d4[0] = Y0; - d4[1] = U; - d4[2] = Y1; - d4[3] = V; - } + // Keep the FPGA payload unchanged. The pixel shader performs the + // left-aligned 10-bit normalization and U/V reorder on the GPU. + if (textureRowBytes > sourceRowBytes) + std::memset(dstRow, 0, textureRowBytes); + std::memcpy(dstRow, srcRow, sourceRowBytes); } ctx_->Unmap(upload_y210_packed_.Get(), 0); @@ -1149,4 +1143,3 @@ DXGI_FORMAT D3DPreviewPipeline::linear_fp16_texture_format() const rt_fp16_->GetDesc(&d); return d.Format; } - diff --git a/package_customer_release.bat b/package_customer_release.bat index e7744ad..38d9537 100644 --- a/package_customer_release.bat +++ b/package_customer_release.bat @@ -3,8 +3,10 @@ setlocal EnableExtensions set "PROJECT_DIR=%~dp0" set "PROJECT_DIR=%PROJECT_DIR:~0,-1%" -set "PROJECT_NAME=GVFG_Standalone" -set "CONFIG=Release" + +if not defined SOURCE_BIN set "SOURCE_BIN=%PROJECT_DIR%\build\Desktop_Qt_6_10_2_MSVC2022_64bit-Release\bin" +if not defined QT_BIN set "QT_BIN=C:\Qt\6.10.2\msvc2022_64\bin" +if not defined VSDEVCMD set "VSDEVCMD=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat" if "%~1"=="" ( set "OUTPUT_DIR=%PROJECT_DIR%\packages" @@ -12,153 +14,62 @@ if "%~1"=="" ( set "OUTPUT_DIR=%~1" ) -if not defined BUILD_DIR set "BUILD_DIR=%PROJECT_DIR%\build_customer_release" -if not defined QT_DIR set "QT_DIR=C:\Qt\6.10.2\msvc2022_64" -if not defined QT_BIN set "QT_BIN=%QT_DIR%\bin" -if not defined CMAKE_EXE set "CMAKE_EXE=C:\Qt\Tools\CMake_64\bin\cmake.exe" -if not exist "%CMAKE_EXE%" set "CMAKE_EXE=cmake" -if not defined VSDEVCMD set "VSDEVCMD=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat" - -set "Path=" -set "PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0" - for /f %%I in ('powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-Date -Format yyyyMMdd_HHmmss"') do set "STAMP=%%I" -set "PACKAGE_NAME=%PROJECT_NAME%_Customer_Release_%STAMP%" +set "PACKAGE_NAME=GVFG_Qt_Preview_Release_%STAMP%" set "ZIP_PATH=%OUTPUT_DIR%\%PACKAGE_NAME%.zip" set "STAGE_ROOT=%TEMP%\%PACKAGE_NAME%_%RANDOM%" set "STAGE_DIR=%STAGE_ROOT%\%PACKAGE_NAME%" +set "WINDEPLOYQT=%QT_BIN%\windeployqt.exe" -echo [release] Project: "%PROJECT_DIR%" -echo [release] Build: "%BUILD_DIR%" -echo [release] Output: "%ZIP_PATH%" +echo [package] Source: "%SOURCE_BIN%" +echo [package] Output: "%ZIP_PATH%" -if not exist "%OUTPUT_DIR%" ( - echo [release] Create output folder... - mkdir "%OUTPUT_DIR%" || goto fail +if not exist "%SOURCE_BIN%\gvfg_qt_preview.exe" ( + echo [package] ERROR: gvfg_qt_preview.exe not found. + goto fail ) - -if exist "%VSDEVCMD%" ( - echo [release] Load Visual Studio x64 build environment... - call "%VSDEVCMD%" -arch=x64 || goto fail -) else ( - echo [release] VSDEVCMD not found. Assuming this is already a Visual Studio developer shell. +if not exist "%SOURCE_BIN%\gvfg.dll" ( + echo [package] ERROR: gvfg.dll not found. + goto fail ) - -echo [release] Configure CMake... -"%CMAKE_EXE%" -S "%PROJECT_DIR%" -B "%BUILD_DIR%" -DBUILD_GVFG_SAMPLES=ON -DCMAKE_PREFIX_PATH="%QT_DIR%" -if errorlevel 1 goto fail - -echo [release] Build %CONFIG%... -"%CMAKE_EXE%" --build "%BUILD_DIR%" --target gvfg_qt_preview --config %CONFIG% -if errorlevel 1 goto fail - -set "BIN_DIR=%BUILD_DIR%\bin\%CONFIG%" -set "LIB_DIR=%BUILD_DIR%\lib\%CONFIG%" - -if not exist "%BIN_DIR%\gvfg.dll" ( - echo [release] ERROR: "%BIN_DIR%\gvfg.dll" not found. +if not exist "%SOURCE_BIN%\gvfg_preview.dll" ( + echo [package] ERROR: gvfg_preview.dll not found. goto fail ) - -if not exist "%LIB_DIR%\gvfg.lib" ( - echo [release] ERROR: "%LIB_DIR%\gvfg.lib" not found. - goto fail -) - -if not exist "%BIN_DIR%\gvfg_preview.dll" ( - echo [release] ERROR: "%BIN_DIR%\gvfg_preview.dll" not found. - goto fail -) - -if not exist "%LIB_DIR%\gvfg_preview.lib" ( - echo [release] ERROR: "%LIB_DIR%\gvfg_preview.lib" not found. - goto fail -) - -if not exist "%BIN_DIR%\gvfg_qt_preview.exe" ( - echo [release] ERROR: "%BIN_DIR%\gvfg_qt_preview.exe" not found. +if not exist "%WINDEPLOYQT%" ( + echo [package] ERROR: "%WINDEPLOYQT%" not found. goto fail ) +if not exist "%OUTPUT_DIR%" mkdir "%OUTPUT_DIR%" || goto fail if exist "%STAGE_ROOT%" rmdir /S /Q "%STAGE_ROOT%" || goto fail +mkdir "%STAGE_DIR%" || goto fail -echo [release] Stage customer package... -mkdir "%STAGE_DIR%\bin" || goto fail -mkdir "%STAGE_DIR%\lib" || goto fail -mkdir "%STAGE_DIR%\include" || goto fail -mkdir "%STAGE_DIR%\docs" || goto fail -mkdir "%STAGE_DIR%\samples\gvfg_qt_preview" || goto fail -mkdir "%STAGE_DIR%\samples\gvfg_qt_preview_source" || goto fail +echo [package] Copy application files... +copy /Y "%SOURCE_BIN%\gvfg_qt_preview.exe" "%STAGE_DIR%\" >nul || goto fail +copy /Y "%SOURCE_BIN%\gvfg.dll" "%STAGE_DIR%\" >nul || goto fail +copy /Y "%SOURCE_BIN%\gvfg_preview.dll" "%STAGE_DIR%\" >nul || goto fail -copy /Y "%PROJECT_DIR%\sdk\gvfg\include\gvfg_capture.h" "%STAGE_DIR%\include\" >nul || goto fail -copy /Y "%PROJECT_DIR%\helpers\gvfg_preview\include\gvfg_preview.h" "%STAGE_DIR%\include\" >nul || goto fail -copy /Y "%BIN_DIR%\gvfg.dll" "%STAGE_DIR%\bin\" >nul || goto fail -copy /Y "%BIN_DIR%\gvfg_preview.dll" "%STAGE_DIR%\bin\" >nul || goto fail -copy /Y "%LIB_DIR%\gvfg.lib" "%STAGE_DIR%\lib\" >nul || goto fail -copy /Y "%LIB_DIR%\gvfg_preview.lib" "%STAGE_DIR%\lib\" >nul || goto fail -copy /Y "%BIN_DIR%\gvfg_qt_preview.exe" "%STAGE_DIR%\samples\gvfg_qt_preview\" >nul || goto fail -copy /Y "%BIN_DIR%\gvfg.dll" "%STAGE_DIR%\samples\gvfg_qt_preview\" >nul || goto fail -copy /Y "%BIN_DIR%\gvfg_preview.dll" "%STAGE_DIR%\samples\gvfg_qt_preview\" >nul || goto fail -copy /Y "%PROJECT_DIR%\README.md" "%STAGE_DIR%\" >nul || goto fail -copy /Y "%PROJECT_DIR%\docs\GVFG_CUSTOMER_API.md" "%STAGE_DIR%\docs\" >nul || goto fail - -robocopy "%PROJECT_DIR%\samples\gvfg_qt_preview" "%STAGE_DIR%\samples\gvfg_qt_preview_source" ^ - /E ^ - /XF "*.user" "*.suo" "*.obj" "*.pdb" "*.ilk" "*.exp" "*.lib" "*.dll" "*.exe" "*.zip" ^ - /NFL /NDL /NJH /NJS /NP - -if errorlevel 8 ( - echo [release] ERROR: robocopy sample source failed. - goto fail -) - -echo [release] Deploy Qt runtime for sample... -if not exist "%QT_BIN%\windeployqt.exe" ( - echo [release] ERROR: "%QT_BIN%\windeployqt.exe" not found. - echo [release] Set QT_DIR or QT_BIN before running this script. - goto fail -) - -"%QT_BIN%\windeployqt.exe" --release --compiler-runtime --force "%STAGE_DIR%\samples\gvfg_qt_preview\gvfg_qt_preview.exe" +echo [package] Deploy Qt runtime... +if exist "%VSDEVCMD%" call "%VSDEVCMD%" -arch=x64 >nul || goto fail +"%WINDEPLOYQT%" --release --compiler-runtime --force --dir "%STAGE_DIR%" "%STAGE_DIR%\gvfg_qt_preview.exe" if errorlevel 1 goto fail -echo [release] Write package notes... -( - echo GVFG Standalone Customer Release - echo. - echo Layout: - echo include\gvfg_capture.h - echo include\gvfg_preview.h - echo lib\gvfg.lib - echo lib\gvfg_preview.lib - echo bin\gvfg.dll - echo bin\gvfg_preview.dll - echo samples\gvfg_qt_preview\gvfg_qt_preview.exe - echo samples\gvfg_qt_preview_source\ - echo docs\GVFG_CUSTOMER_API.md - echo. - echo Link with lib\gvfg.lib for capture. - echo Link with lib\gvfg_preview.lib only if the application uses the optional preview helper. - echo Deploy bin\gvfg.dll for capture and bin\gvfg_preview.dll only when preview is used; the preview DLL is standalone. - echo Run samples\gvfg_qt_preview\gvfg_qt_preview.exe to verify the packaged runtime. -) > "%STAGE_DIR%\PACKAGE_README.txt" - -echo [release] Create zip... +echo [package] Create zip... powershell -NoProfile -ExecutionPolicy Bypass -Command ^ "Compress-Archive -Path '%STAGE_DIR%' -DestinationPath '%ZIP_PATH%' -Force" if errorlevel 1 goto fail -echo [release] Clean staging folder... -rmdir /S /Q "%STAGE_ROOT%" || goto fail +rmdir /S /Q "%STAGE_ROOT%" -echo [release] Done. -echo [release] Zip: "%ZIP_PATH%" +echo [package] Done. +echo [package] Zip: "%ZIP_PATH%" if "%NO_PAUSE%"=="" pause exit /b 0 :fail -echo [release] FAILED. +echo [package] FAILED. if exist "%STAGE_ROOT%" rmdir /S /Q "%STAGE_ROOT%" >nul 2>nul if "%NO_PAUSE%"=="" pause exit /b 1 diff --git a/sdk/gvfg/CMakeLists.txt b/sdk/gvfg/CMakeLists.txt index cf91b29..7131fed 100644 --- a/sdk/gvfg/CMakeLists.txt +++ b/sdk/gvfg/CMakeLists.txt @@ -8,6 +8,7 @@ project(gvfg VERSION ${GVFG_SDK_VERSION} LANGUAGES CXX) add_library(gvfg SHARED include/gvfg_capture.h + include/gvfg_debug.h src/backend/pcies2mm/pcies2mm_backend_types.h src/backend/pcies2mm/pcies2mm_capture_session.cpp src/backend/pcies2mm/pcies2mm_capture_session.h @@ -20,10 +21,6 @@ add_library(gvfg SHARED src/gvfg_capture.cpp ) -if (GVFG_ENABLE_INTERNAL_DEBUG_API) - target_sources(gvfg PRIVATE include/gvfg_debug.h) -endif() - set_target_properties(gvfg PROPERTIES AUTOMOC OFF AUTOUIC OFF @@ -40,7 +37,6 @@ target_include_directories(gvfg target_compile_definitions(gvfg PRIVATE GVFG_BUILD GVFG_SDK_VERSION="${GVFG_SDK_VERSION}" - GVFG_ENABLE_INTERNAL_DEBUG_API=$ ) if (GVFG_PCIES2MM_DEBUG_LOG) @@ -65,10 +61,3 @@ install(TARGETS gvfg install(FILES include/gvfg_capture.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) - -if (GVFG_ENABLE_INTERNAL_DEBUG_API) - install(FILES include/gvfg_debug.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) -endif() - diff --git a/sdk/gvfg/include/gvfg_debug.h b/sdk/gvfg/include/gvfg_debug.h index 03f7935..a47674f 100644 --- a/sdk/gvfg/include/gvfg_debug.h +++ b/sdk/gvfg/include/gvfg_debug.h @@ -72,6 +72,22 @@ GVFG_API gvfg_status_t gvfg_debug_get_last_error_detail( _Out_writes_to_opt_(out_message_size, out_message_size) char *out_message, _In_ uint32_t out_message_size); +/* + * Read or write one 32-bit BAR-relative hardware register. + * + * The offset must be 4-byte aligned. Register writes can disrupt active DMA, + * interrupt handling, or video capture and are intended for internal tools. + */ +GVFG_API gvfg_status_t gvfg_debug_read_register( + _In_ gvfg_handle handle, + _In_ uint32_t offset, + _Out_ uint32_t *out_value); + +GVFG_API gvfg_status_t gvfg_debug_write_register( + _In_ gvfg_handle handle, + _In_ uint32_t offset, + _In_ uint32_t value); + #ifdef __cplusplus } #endif diff --git a/sdk/gvfg/src/backend/pcies2mm/pcies2mm_capture_session.cpp b/sdk/gvfg/src/backend/pcies2mm/pcies2mm_capture_session.cpp index 8eb6058..390c2ae 100644 --- a/sdk/gvfg/src/backend/pcies2mm/pcies2mm_capture_session.cpp +++ b/sdk/gvfg/src/backend/pcies2mm/pcies2mm_capture_session.cpp @@ -563,6 +563,16 @@ namespace gvfg::internal return true; } + pcies2mm_status_t PcieS2mmCaptureSession::debug_read_register(uint32_t offset, + uint32_t &outValue) const + { + if (!opened_ || device_ == INVALID_HANDLE_VALUE) + return PCIES2MM_ESTATE; + if ((offset & 0x3u) != 0) + return PCIES2MM_EINVAL; + return read_reg(offset, outValue) ? PCIES2MM_OK : fail(PCIES2MM_EIO, "debug_read_register"); + } + bool PcieS2mmCaptureSession::write_reg(uint32_t offset, uint32_t value) const { PCIES2MM_REG_ACCESS reg{}; @@ -579,6 +589,16 @@ namespace gvfg::internal nullptr) != FALSE; } + pcies2mm_status_t PcieS2mmCaptureSession::debug_write_register(uint32_t offset, + uint32_t value) const + { + if (!opened_ || device_ == INVALID_HANDLE_VALUE) + return PCIES2MM_ESTATE; + if ((offset & 0x3u) != 0) + return PCIES2MM_EINVAL; + return write_reg(offset, value) ? PCIES2MM_OK : fail(PCIES2MM_EIO, "debug_write_register"); + } + bool PcieS2mmCaptureSession::register_event(uint32_t channelIndex, uint32_t eventType, HANDLE eventHandle) { PCIES2MM_EVENT_REG eventReg{}; diff --git a/sdk/gvfg/src/backend/pcies2mm/pcies2mm_capture_session.h b/sdk/gvfg/src/backend/pcies2mm/pcies2mm_capture_session.h index 6057030..c7dab87 100644 --- a/sdk/gvfg/src/backend/pcies2mm/pcies2mm_capture_session.h +++ b/sdk/gvfg/src/backend/pcies2mm/pcies2mm_capture_session.h @@ -41,6 +41,8 @@ namespace gvfg::internal void get_debug_stats(pcies2mm_stream_stats_t &outStats, uint64_t &outWaitTimeouts, pcies2mm_debug_state_t &outDebugState) const; + pcies2mm_status_t debug_read_register(uint32_t offset, uint32_t &outValue) const; + pcies2mm_status_t debug_write_register(uint32_t offset, uint32_t value) const; private: pcies2mm_status_t open_device(const PcieS2mmDevice &device); diff --git a/sdk/gvfg/src/gvfg_capture.cpp b/sdk/gvfg/src/gvfg_capture.cpp index 1203c50..ec6012a 100644 --- a/sdk/gvfg/src/gvfg_capture.cpp +++ b/sdk/gvfg/src/gvfg_capture.cpp @@ -1,8 +1,6 @@ #include "gvfg_capture.h" -#if GVFG_ENABLE_INTERNAL_DEBUG_API #include "gvfg_debug.h" -#endif #include "pcies2mm_capture_session.h" #include @@ -569,7 +567,6 @@ struct gvfg_handle_t return GVFG_OK; } -#if GVFG_ENABLE_INTERNAL_DEBUG_API gvfg_status_t getDebugBackendStats(gvfg_debug_backend_stats_t &out) { std::memset(&out, 0, sizeof(out)); @@ -620,6 +617,20 @@ struct gvfg_handle_t return GVFG_OK; } + gvfg_status_t debugReadRegister(uint32_t offset, uint32_t &outValue) + { + if (!backend) + return GVFG_ESTATE; + return map_status(backend->debug_read_register(offset, outValue)); + } + + gvfg_status_t debugWriteRegister(uint32_t offset, uint32_t value) + { + if (!backend) + return GVFG_ESTATE; + return map_status(backend->debug_write_register(offset, value)); + } + gvfg_status_t getLastErrorDetail(char *outMessage, uint32_t outMessageSize) { if (!outMessage || outMessageSize == 0) @@ -631,7 +642,6 @@ struct gvfg_handle_t copy_cstr(outMessage, outMessageSize, backend ? backend->last_error() : ""); return GVFG_OK; } -#endif void recordError(const char *msg) { @@ -845,7 +855,6 @@ extern "C" } } -#if GVFG_ENABLE_INTERNAL_DEBUG_API gvfg_status_t gvfg_debug_get_backend_stats(gvfg_handle handle, gvfg_debug_backend_stats_t *out_stats) { @@ -869,7 +878,24 @@ extern "C" return GVFG_EINVAL; return handle->getLastErrorDetail(out_message, out_message_size); } -#endif + + gvfg_status_t gvfg_debug_read_register(gvfg_handle handle, + uint32_t offset, + uint32_t *out_value) + { + if (!handle || !out_value || (offset & 0x3u) != 0) + return GVFG_EINVAL; + return handle->debugReadRegister(offset, *out_value); + } + + gvfg_status_t gvfg_debug_write_register(gvfg_handle handle, + uint32_t offset, + uint32_t value) + { + if (!handle || (offset & 0x3u) != 0) + return GVFG_EINVAL; + return handle->debugWriteRegister(offset, value); + } }