Integrate GPU conversion and update capture pipeline
This commit is contained in:
+1
-11
@@ -18,7 +18,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|||||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
||||||
|
|
||||||
option(BUILD_GVFG_SAMPLES "Build GVFG customer samples" ON)
|
option(BUILD_GVFG_SAMPLES "Build GVFG customer samples" ON)
|
||||||
option(BUILD_GVFG_INTERNAL_TOOLS "Build internal driver/FPGA diagnostic tools" OFF)
|
|
||||||
|
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
message(FATAL_ERROR "GVFG currently supports Windows only.")
|
message(FATAL_ERROR "GVFG currently supports Windows only.")
|
||||||
@@ -26,9 +25,8 @@ endif()
|
|||||||
|
|
||||||
add_subdirectory(sdk/gvfg)
|
add_subdirectory(sdk/gvfg)
|
||||||
add_subdirectory(helpers/gvfg_preview)
|
add_subdirectory(helpers/gvfg_preview)
|
||||||
add_subdirectory(helpers/gvfg_convert)
|
|
||||||
|
|
||||||
if (BUILD_GVFG_SAMPLES OR BUILD_GVFG_INTERNAL_TOOLS)
|
if (BUILD_GVFG_SAMPLES)
|
||||||
add_subdirectory(samples/gvfg_qt_preview)
|
add_subdirectory(samples/gvfg_qt_preview)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -36,11 +34,3 @@ install(FILES
|
|||||||
docs/GVFG_CUSTOMER_API.md
|
docs/GVFG_CUSTOMER_API.md
|
||||||
DESTINATION ${CMAKE_INSTALL_DOCDIR}
|
DESTINATION ${CMAKE_INSTALL_DOCDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (BUILD_GVFG_INTERNAL_TOOLS)
|
|
||||||
install(FILES
|
|
||||||
README.md
|
|
||||||
docs/GVFG_INTERNAL_NOTES.md
|
|
||||||
DESTINATION ${CMAKE_INSTALL_DOCDIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|||||||
Binary file not shown.
@@ -1,98 +0,0 @@
|
|||||||
;
|
|
||||||
; 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/14/2026,14.48.21.148
|
|
||||||
|
|
||||||
[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="<Your manufacturer name>" ;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"
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,86 @@
|
|||||||
|
;
|
||||||
|
; vfg100.inf
|
||||||
|
;
|
||||||
|
|
||||||
|
[Version]
|
||||||
|
Signature="$WINDOWS NT$"
|
||||||
|
Class=%ClassName%
|
||||||
|
ClassGuid={78A1C341-4539-11d3-B88D-00C04FAD5171}
|
||||||
|
Provider=%ManufacturerName%
|
||||||
|
CatalogFile=vfg100.cat
|
||||||
|
DriverVer = 08/05/2026,9.18.54.856
|
||||||
|
PnpLockdown = 1
|
||||||
|
|
||||||
|
|
||||||
|
[DestinationDirs]
|
||||||
|
DefaultDestDir = 12
|
||||||
|
|
||||||
|
; ================= Class section =====================
|
||||||
|
|
||||||
|
[ClassInstall32]
|
||||||
|
Addreg=SampleClassReg
|
||||||
|
|
||||||
|
[SampleClassReg]
|
||||||
|
HKR,,,0,%ClassName%
|
||||||
|
HKR,,Icon,,-5
|
||||||
|
|
||||||
|
|
||||||
|
[SourceDisksNames]
|
||||||
|
1 = %DiskName%,,,""
|
||||||
|
|
||||||
|
[SourceDisksFiles]
|
||||||
|
vfg100.sys = 1,,
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
;*****************************************
|
||||||
|
; Install Section
|
||||||
|
;*****************************************
|
||||||
|
|
||||||
|
[Manufacturer]
|
||||||
|
%ManufacturerName%=Standard,NTamd64
|
||||||
|
|
||||||
|
[Standard.NTamd64]
|
||||||
|
; DisplayName Section DeviceId
|
||||||
|
; ----------- ------- --------
|
||||||
|
%vfg100.DeviceDesc%= vfg100_Inst, PCI\VEN_10EE&DEV_7024
|
||||||
|
%vfg100.DeviceDesc%= vfg100_Inst, PCI\VEN_1458&DEV_7024
|
||||||
|
|
||||||
|
[vfg100_Inst.NT]
|
||||||
|
CopyFiles=Drivers_Dir
|
||||||
|
|
||||||
|
[Drivers_Dir]
|
||||||
|
vfg100.sys
|
||||||
|
|
||||||
|
[vfg100_Inst.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
|
||||||
|
[vfg100_Inst.NT.Services]
|
||||||
|
AddService = vfg100,%SPSVCINST_ASSOCSERVICE%,vfg100_Service_Inst
|
||||||
|
|
||||||
|
[vfg100_Service_Inst]
|
||||||
|
DisplayName = %vfg100.SVCDESC%
|
||||||
|
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
|
||||||
|
StartType = 3 ; SERVICE_DEMAND_START
|
||||||
|
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
|
||||||
|
ServiceBinary = %12%\vfg100.sys
|
||||||
|
|
||||||
|
[vfg100_Inst.NT.Wdf]
|
||||||
|
KmdfService = vfg100, vfg100_wdfsect
|
||||||
|
[vfg100_wdfsect]
|
||||||
|
KmdfLibraryVersion = 1.15
|
||||||
|
|
||||||
|
[Strings]
|
||||||
|
SPSVCINST_ASSOCSERVICE= 0x00000002
|
||||||
|
ManufacturerName="GIGABYTE"
|
||||||
|
ClassName="GIGABYTE Video Capture"
|
||||||
|
DiskName = "GIGABYTE VFG100 WDF Installation Disk"
|
||||||
|
vfg100.DeviceDesc = "GIGABYTE VFG100 WDF"
|
||||||
|
vfg100.SVCDESC = "GIGABYTE VFG100 Service"
|
||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
pnputil /add-driver ".\pcie_s2mm_driver.inf" /install
|
||||||
@@ -9,9 +9,7 @@ import library、runtime DLL 來使用 GVFG,不要直接把 GVFG source 編進
|
|||||||
|
|
||||||
- `sdk/gvfg`:GVFG customer C API、internal debug API、PCIES2MM backend。
|
- `sdk/gvfg`:GVFG customer C API、internal debug API、PCIES2MM backend。
|
||||||
- `helpers/gvfg_preview`:可選的 preview helper DLL,在 `gvfg_read_frame()` 後使用。
|
- `helpers/gvfg_preview`:可選的 preview helper DLL,在 `gvfg_read_frame()` 後使用。
|
||||||
- `helpers/gvfg_convert`:可選的 snapshot/export conversion helper DLL。
|
- `samples/gvfg_qt_preview`:Qt preview sample;診斷功能由 build option 控制。
|
||||||
- `samples/gvfg_qt_preview`:customer-facing Qt preview sample;internal build
|
|
||||||
會另外產生 `gvfg_qt_diagnostic`。
|
|
||||||
- `docs`:API 與整合說明。
|
- `docs`:API 與整合說明。
|
||||||
|
|
||||||
客戶端 API 細節在 `docs/GVFG_CUSTOMER_API.md`。內部架構、package
|
客戶端 API 細節在 `docs/GVFG_CUSTOMER_API.md`。內部架構、package
|
||||||
@@ -33,23 +31,14 @@ cmake --build build --target gvfg_qt_preview --config Release
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
BUILD_GVFG_SAMPLES=ON
|
BUILD_GVFG_SAMPLES=ON
|
||||||
GVFG_ENABLE_INTERNAL_DEBUG_API=OFF
|
|
||||||
BUILD_GVFG_INTERNAL_TOOLS=OFF
|
|
||||||
GVFG_PCIES2MM_DEBUG_LOG=OFF
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Customer build 必須保持 `GVFG_ENABLE_INTERNAL_DEBUG_API=OFF`。這會移除
|
|
||||||
`gvfg_debug_*` DLL exports,install tree 也不會包含 `gvfg_debug.h`。
|
|
||||||
|
|
||||||
公司內部 diagnostic build 使用:
|
公司內部 diagnostic build 使用:
|
||||||
|
|
||||||
```bat
|
```bat
|
||||||
cmake -S . -B build_internal ^
|
cmake -S . -B build_internal ^
|
||||||
-DBUILD_GVFG_SAMPLES=OFF ^
|
|
||||||
-DGVFG_ENABLE_INTERNAL_DEBUG_API=ON ^
|
|
||||||
-DBUILD_GVFG_INTERNAL_TOOLS=ON ^
|
|
||||||
-DCMAKE_PREFIX_PATH=C:\Qt\6.10.2\msvc2022_64
|
-DCMAKE_PREFIX_PATH=C:\Qt\6.10.2\msvc2022_64
|
||||||
cmake --build build_internal --target gvfg_qt_diagnostic --config Release
|
cmake --build build_internal --target gvfg_qt_preview --config Debug
|
||||||
```
|
```
|
||||||
|
|
||||||
Build 產物:
|
Build 產物:
|
||||||
@@ -57,10 +46,8 @@ Build 產物:
|
|||||||
```text
|
```text
|
||||||
build/.../bin/gvfg.dll
|
build/.../bin/gvfg.dll
|
||||||
build/.../bin/gvfg_preview.dll
|
build/.../bin/gvfg_preview.dll
|
||||||
build/.../bin/gvfg_convert.dll
|
|
||||||
build/.../lib/gvfg.lib
|
build/.../lib/gvfg.lib
|
||||||
build/.../lib/gvfg_preview.lib
|
build/.../lib/gvfg_preview.lib
|
||||||
build/.../lib/gvfg_convert.lib
|
|
||||||
build/.../bin/gvfg_qt_preview.exe
|
build/.../bin/gvfg_qt_preview.exe
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -85,13 +72,7 @@ lib/gvfg_preview.lib
|
|||||||
bin/gvfg_preview.dll
|
bin/gvfg_preview.dll
|
||||||
```
|
```
|
||||||
|
|
||||||
需要 snapshot/export conversion 時,再加:
|
GPU snapshot/export conversion 已整合在 `gvfg.dll`,不需要額外 helper DLL。
|
||||||
|
|
||||||
```text
|
|
||||||
include/gvfg_convert.h
|
|
||||||
lib/gvfg_convert.lib
|
|
||||||
bin/gvfg_convert.dll
|
|
||||||
```
|
|
||||||
|
|
||||||
Customer/demo package 不應包含 `gvfg_debug.h`、SDK source、PCIES2MM backend
|
Customer/demo package 不應包含 `gvfg_debug.h`、SDK source、PCIES2MM backend
|
||||||
headers、IRQ details 或 helper source。這些只屬於 internal
|
headers、IRQ details 或 helper source。這些只屬於 internal
|
||||||
|
|||||||
@@ -22,6 +22,9 @@
|
|||||||
<mxCell id="publicHeader" parent="apiLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;fontSize=14;" value="sdk/gvfg/include/gvfg_capture.h<br>customer-facing C API" vertex="1">
|
<mxCell id="publicHeader" parent="apiLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;fontSize=14;" value="sdk/gvfg/include/gvfg_capture.h<br>customer-facing C API" vertex="1">
|
||||||
<mxGeometry height="58" width="280" x="450" y="50" as="geometry" />
|
<mxGeometry height="58" width="280" x="450" y="50" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
|
<mxCell id="gpuConvert" parent="apiLayer" style="rounded=1;whiteSpace=wrap;html=1;arcSize=8;fillColor=#ffffff;strokeColor=#82b366;fontSize=14;" value="sdk/gvfg/src/gpu<br>D3D11 YUY2/Y210 conversion<br>BGRA8 / RGB10A2 readback" vertex="1">
|
||||||
|
<mxGeometry height="72" width="300" x="820" y="45" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
<mxCell id="backendLayer" parent="1" style="swimlane;html=1;startSize=34;horizontal=1;fillColor=#fff2cc;strokeColor=#d6b656;fontStyle=1;align=left;" value="3. SDK Internal Backend / Data Flow" vertex="1">
|
<mxCell id="backendLayer" parent="1" style="swimlane;html=1;startSize=34;horizontal=1;fillColor=#fff2cc;strokeColor=#d6b656;fontStyle=1;align=left;" value="3. SDK Internal Backend / Data Flow" vertex="1">
|
||||||
<mxGeometry height="275" width="1180" x="50" y="515" as="geometry">
|
<mxGeometry height="275" width="1180" x="50" y="515" as="geometry">
|
||||||
<mxRectangle height="34" width="240" x="50" y="515" as="alternateBounds" />
|
<mxRectangle height="34" width="240" x="50" y="515" as="alternateBounds" />
|
||||||
@@ -68,6 +71,12 @@
|
|||||||
<mxCell id="e3" edge="1" parent="1" source="publicHeader" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="facade" value="exports">
|
<mxCell id="e3" edge="1" parent="1" source="publicHeader" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="facade" value="exports">
|
||||||
<mxGeometry relative="1" as="geometry" />
|
<mxGeometry relative="1" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
|
<mxCell id="eGpu" edge="1" parent="1" source="publicHeader" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="gpuConvert" value="gvfg_gpu_convert_to_buffer">
|
||||||
|
<mxGeometry relative="1" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="ePreviewGpu" edge="1" parent="1" source="render" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;dashed=1;" target="gpuConvert" value="shared pipeline source">
|
||||||
|
<mxGeometry relative="1" as="geometry" />
|
||||||
|
</mxCell>
|
||||||
<mxCell id="e4" edge="1" parent="1" source="qtSample" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="render" value="private preview">
|
<mxCell id="e4" edge="1" parent="1" source="qtSample" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=block;strokeWidth=2;" target="render" value="private preview">
|
||||||
<mxGeometry relative="1" as="geometry" />
|
<mxGeometry relative="1" as="geometry" />
|
||||||
</mxCell>
|
</mxCell>
|
||||||
|
|||||||
+24
-82
@@ -3,9 +3,9 @@
|
|||||||
本文說明客戶端使用的 GVFG capture API,主要 public header 是
|
本文說明客戶端使用的 GVFG capture API,主要 public header 是
|
||||||
`sdk/gvfg/include/gvfg_capture.h`。
|
`sdk/gvfg/include/gvfg_capture.h`。
|
||||||
|
|
||||||
Customer SDK 的 core API 只負責 capture。它不 expose SDK-managed preview、
|
Customer SDK 的 core `gvfg.dll` 負責 capture 與 explicit GPU buffer conversion。
|
||||||
driver registers、DMA internals 或 FPGA debug controls。Preview rendering、
|
它不 expose SDK-managed preview、driver registers、DMA internals 或 FPGA debug
|
||||||
snapshot conversion 這類功能放在 helper DLL,使用者需要時再另外 link。
|
controls。Preview rendering 仍由 optional `gvfg_preview.dll` 提供。
|
||||||
|
|
||||||
Customer 交付內容只包含 public headers 與 public DLL functions。Customer
|
Customer 交付內容只包含 public headers 與 public DLL functions。Customer
|
||||||
sample 只記錄 signal events、API failures、capture stall/recovery 與
|
sample 只記錄 signal events、API failures、capture stall/recovery 與
|
||||||
@@ -152,48 +152,28 @@ typedef struct
|
|||||||
|
|
||||||
板子只提供兩種 tightly packed native capture layout:
|
板子只提供兩種 tightly packed native capture layout:
|
||||||
|
|
||||||
- `YUY2`:`row_stride_bytes = width * 2`。
|
- `YVYU`:`row_stride_bytes = width * 2`。
|
||||||
- `Y210`:`row_stride_bytes = width * 4`。
|
- `Y210`:`row_stride_bytes = width * 4`。
|
||||||
|
|
||||||
其他 native input format 不在 SDK 支援範圍,會回傳 `GVFG_ENOTSUP`。
|
其他 native input format 不在 SDK 支援範圍,會回傳 `GVFG_ENOTSUP`。
|
||||||
|
|
||||||
### `gvfg_convert_frame`
|
### `gvfg_gpu_output_buffer_t`
|
||||||
|
|
||||||
Optional `gvfg_convert.dll` 使用的 helper-owned destination frame。
|
`gvfg.dll` 的 GPU conversion API 使用 caller-owned destination buffer:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
typedef struct gvfg_convert_frame_t *gvfg_convert_frame;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int width;
|
void *data;
|
||||||
int height;
|
|
||||||
int pixel_format;
|
|
||||||
int row_bytes;
|
|
||||||
uint64_t data_size;
|
uint64_t data_size;
|
||||||
} gvfg_convert_frame_desc_t;
|
int row_bytes;
|
||||||
|
int pixel_format;
|
||||||
|
} gvfg_gpu_output_buffer_t;
|
||||||
```
|
```
|
||||||
|
|
||||||
這個設計接近 Blackmagic-style conversion:application 先建立 destination
|
支援 `GVFG_GPU_OUTPUT_BGRA8` 與 packed `GVFG_GPU_OUTPUT_RGB10A2`;兩者皆為
|
||||||
frame,再明確把 source frame convert 進去。Core capture API 仍然回傳
|
每像素四 bytes。Core capture API 仍回傳 hardware/native buffer,不會在
|
||||||
hardware/native buffer,不會在 `gvfg_read_frame()` 裡偷偷轉格式。
|
`gvfg_read_frame()` 裡自動轉換。
|
||||||
|
|
||||||
Snapshot 用途可以把 `width`、`height`、`row_bytes` 設成 0,讓 helper 依照
|
|
||||||
captured source frame 自動決定大小。
|
|
||||||
|
|
||||||
第一版 destination formats:
|
|
||||||
|
|
||||||
- `GVFG_CONVERT_FMT_BGRA8`:8-bit BGRA,alpha 255。
|
|
||||||
- `GVFG_CONVERT_FMT_RGB48`:16-bit RGB container,適合 10-bit-friendly snapshot。
|
|
||||||
- `GVFG_CONVERT_FMT_RGBA64`:16-bit RGBA container,alpha 65535。
|
|
||||||
|
|
||||||
第一版 conversions:
|
|
||||||
|
|
||||||
- `YUY2 -> BGRA8 / RGB48 / RGBA64`
|
|
||||||
- `Y210 -> BGRA8 / RGB48 / RGBA64`
|
|
||||||
|
|
||||||
Conversion 使用 BT.709 limited-range YUV to RGB,和 preview path 對齊。其他
|
|
||||||
source 或 destination format 會回傳 `GVFG_ENOTSUP`。
|
|
||||||
|
|
||||||
### `gvfg_event_type_t`
|
### `gvfg_event_type_t`
|
||||||
|
|
||||||
@@ -271,69 +251,31 @@ gvfg_status_t gvfg_read_frame(gvfg_handle handle,
|
|||||||
- `GVFG_ETIMEOUT`:timeout 前沒有 frame。
|
- `GVFG_ETIMEOUT`:timeout 前沒有 frame。
|
||||||
- `GVFG_ESTATE`:capture 尚未 running,或上一個 frame 還沒 release。
|
- `GVFG_ESTATE`:capture 尚未 running,或上一個 frame 還沒 release。
|
||||||
|
|
||||||
### `gvfg_convert_create_frame` / `gvfg_convert_destroy_frame`
|
### `gvfg_gpu_convert_to_buffer`
|
||||||
|
|
||||||
```c
|
```c
|
||||||
gvfg_status_t gvfg_convert_create_frame(const gvfg_convert_frame_desc_t *desc,
|
gvfg_status_t gvfg_gpu_convert_to_buffer(const gvfg_frame_t *source,
|
||||||
gvfg_convert_frame *out_frame);
|
const gvfg_gpu_output_buffer_t *output);
|
||||||
gvfg_status_t gvfg_convert_destroy_frame(gvfg_convert_frame frame);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
建立或銷毀 helper-owned destination frame。Caller 主要設定
|
用 D3D11 shader 同步轉換 captured YVYU/Y210 frame,並 readback 到 caller buffer。
|
||||||
`desc.pixel_format`;`width`、`height`、`row_bytes` 可以是 0,讓
|
函式返回前 source 與 output memory 必須保持有效;SDK 不保留兩者的 pointer。
|
||||||
`gvfg_convert_frame_from_capture()` 依照 source frame 自動 configure。
|
|
||||||
|
|
||||||
### `gvfg_convert_frame_from_capture`
|
|
||||||
|
|
||||||
```c
|
|
||||||
gvfg_status_t gvfg_convert_frame_from_capture(const gvfg_frame_t *src,
|
|
||||||
gvfg_convert_frame dst_frame);
|
|
||||||
```
|
|
||||||
|
|
||||||
把 captured native frame 轉進 helper-owned destination frame。這不會改變
|
|
||||||
capture output format。
|
|
||||||
|
|
||||||
Snapshot buffer flow 範例:
|
|
||||||
|
|
||||||
```c
|
```c
|
||||||
#include <gvfg_capture.h>
|
#include <gvfg_capture.h>
|
||||||
#include <gvfg_convert.h>
|
|
||||||
|
|
||||||
gvfg_frame_t frame = {};
|
gvfg_frame_t frame = {};
|
||||||
if (gvfg_read_frame(h, &frame, 1000) == GVFG_OK) {
|
if (gvfg_read_frame(h, &frame, 1000) == GVFG_OK) {
|
||||||
gvfg_convert_frame_desc_t desc = {};
|
gvfg_gpu_output_buffer_t output = {};
|
||||||
desc.pixel_format = GVFG_CONVERT_FMT_RGB48;
|
output.data = canvas_data;
|
||||||
|
output.data_size = canvas_size;
|
||||||
gvfg_convert_frame image = NULL;
|
output.row_bytes = frame.width * 4;
|
||||||
if (gvfg_convert_create_frame(&desc, &image) == GVFG_OK &&
|
output.pixel_format = GVFG_GPU_OUTPUT_BGRA8;
|
||||||
gvfg_convert_frame_from_capture(&frame, image) == GVFG_OK) {
|
gvfg_gpu_convert_to_buffer(&frame, &output);
|
||||||
const void *data = NULL;
|
|
||||||
uint64_t size = 0;
|
|
||||||
gvfg_convert_get_buffer(image, &data, &size);
|
|
||||||
gvfg_convert_frame_desc_t actual = {};
|
|
||||||
gvfg_convert_get_frame_desc(image, &actual);
|
|
||||||
/* data contains RGB48 rows using actual.row_bytes. */
|
|
||||||
}
|
|
||||||
|
|
||||||
gvfg_convert_destroy_frame(image);
|
|
||||||
gvfg_release_frame(h, &frame);
|
gvfg_release_frame(h, &frame);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `gvfg_convert_get_frame_desc` / `gvfg_convert_get_buffer`
|
|
||||||
|
|
||||||
```c
|
|
||||||
gvfg_status_t gvfg_convert_get_frame_desc(gvfg_convert_frame frame,
|
|
||||||
gvfg_convert_frame_desc_t *out_desc);
|
|
||||||
gvfg_status_t gvfg_convert_get_buffer(gvfg_convert_frame frame,
|
|
||||||
const void **out_data,
|
|
||||||
uint64_t *out_size);
|
|
||||||
```
|
|
||||||
|
|
||||||
在 `gvfg_convert_frame_from_capture()` 後,用這些 API 取得 converted image
|
|
||||||
buffer;width、height、format、`row_bytes` 與 data size 由 frame descriptor
|
|
||||||
提供。
|
|
||||||
|
|
||||||
### `gvfg_release_frame`
|
### `gvfg_release_frame`
|
||||||
|
|
||||||
```c
|
```c
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
<mxCell id="select" value="wait_frame() selects newest ready slot
slot.ready = false
slot.in_use = true
out.data = slot.data.data()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14" vertex="1" parent="1">
|
<mxCell id="select" value="wait_frame() selects newest ready slot
slot.ready = false
slot.in_use = true
out.data = slot.data.data()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14" vertex="1" parent="1">
|
||||||
<mxGeometry x="430" y="540" width="310" height="120" as="geometry"/>
|
<mxGeometry x="430" y="540" width="310" height="120" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="render" value="optional gvfg_preview.dll
uses frame before release" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14" vertex="1" parent="1">
|
<mxCell id="render" value="optional frame consumers before release
gvfg_preview_render_frame()
gvfg_gpu_convert_to_buffer()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14" vertex="1" parent="1">
|
||||||
<mxGeometry x="820" y="540" width="270" height="90" as="geometry"/>
|
<mxGeometry x="820" y="540" width="270" height="90" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="appUse" value="app uses frame
data valid until gvfg_release_frame()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14" vertex="1" parent="1">
|
<mxCell id="appUse" value="app uses frame
data valid until gvfg_release_frame()" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14" vertex="1" parent="1">
|
||||||
|
|||||||
+17
-47
@@ -10,19 +10,15 @@ GVFG 目前切成幾個清楚的模組:
|
|||||||
```text
|
```text
|
||||||
sdk/gvfg/
|
sdk/gvfg/
|
||||||
gvfg.dll
|
gvfg.dll
|
||||||
capture API, handle lifecycle, pull frame/event bridge, internal debug API
|
capture API, GPU buffer conversion, handle lifecycle, pull frame/event bridge,
|
||||||
|
internal debug API
|
||||||
|
|
||||||
helpers/gvfg_preview/
|
helpers/gvfg_preview/
|
||||||
gvfg_preview.dll
|
gvfg_preview.dll
|
||||||
optional display helper; renders gvfg_frame_t after gvfg_read_frame()
|
optional display helper; renders gvfg_frame_t after gvfg_read_frame()
|
||||||
|
|
||||||
helpers/gvfg_convert/
|
|
||||||
gvfg_convert.dll
|
|
||||||
optional snapshot/export helper; converts native capture frames on request
|
|
||||||
|
|
||||||
samples/gvfg_qt_preview/
|
samples/gvfg_qt_preview/
|
||||||
gvfg_qt_preview: customer-facing, uses public APIs only
|
gvfg_qt_preview: diagnostics are selected at configure time
|
||||||
gvfg_qt_diagnostic: internal build, additionally uses gvfg_debug.h
|
|
||||||
```
|
```
|
||||||
|
|
||||||
從 customer 角度看,core SDK 必須維持 driver-neutral。PCIES2MM、IRQ、DMA counters、
|
從 customer 角度看,core SDK 必須維持 driver-neutral。PCIES2MM、IRQ、DMA counters、
|
||||||
@@ -48,11 +44,11 @@ pcies2mm_reg.h
|
|||||||
FPGA register offsets and bit masks
|
FPGA register offsets and bit masks
|
||||||
|
|
||||||
pcies2mm_video_format.{h,cpp}
|
pcies2mm_video_format.{h,cpp}
|
||||||
native YUY2/Y210 layout rules and format-register decoding
|
native YVYU/Y210 layout rules and format-register decoding
|
||||||
```
|
```
|
||||||
|
|
||||||
`pcies2mm_ioctl.h` 與 `pcies2mm_reg.h` 都不是 customer public header,不可放進
|
`pcies2mm_ioctl.h` 與 `pcies2mm_reg.h` 都不是 customer public header,不可放進
|
||||||
SDK customer include package。目前板卡只接受 YUY2 與 Y210;這個 FPGA revision 即使
|
SDK customer include package。目前板卡只輸出 YVYU 與 Y210;這個 FPGA revision 即使
|
||||||
format register 回報 v210,DMA payload 仍由 `pcies2mm_video_format.cpp` 解讀為 Y210。
|
format register 回報 v210,DMA payload 仍由 `pcies2mm_video_format.cpp` 解讀為 Y210。
|
||||||
上述拆分只分離程式責任,不會增加 capture thread。
|
上述拆分只分離程式責任,不會增加 capture thread。
|
||||||
|
|
||||||
@@ -70,11 +66,6 @@ flowchart TD
|
|||||||
PreviewPipe["private D3D preview pipeline"]
|
PreviewPipe["private D3D preview pipeline"]
|
||||||
end
|
end
|
||||||
|
|
||||||
subgraph Convert["Optional Convert Helper: gvfg_convert.dll"]
|
|
||||||
ConvertApi["helpers/gvfg_convert/include/gvfg_convert.h"]
|
|
||||||
ConvertPipe["private CPU/GPU conversion path"]
|
|
||||||
end
|
|
||||||
|
|
||||||
subgraph SDK["Core SDK: gvfg.dll"]
|
subgraph SDK["Core SDK: gvfg.dll"]
|
||||||
CaptureApi["sdk/gvfg/include/gvfg_capture.h"]
|
CaptureApi["sdk/gvfg/include/gvfg_capture.h"]
|
||||||
DebugApi["sdk/gvfg/include/gvfg_debug.h\ninternal only"]
|
DebugApi["sdk/gvfg/include/gvfg_debug.h\ninternal only"]
|
||||||
@@ -89,13 +80,11 @@ flowchart TD
|
|||||||
|
|
||||||
CustomerApp --> CaptureApi
|
CustomerApp --> CaptureApi
|
||||||
CustomerApp -. optional display .-> PreviewApi
|
CustomerApp -. optional display .-> PreviewApi
|
||||||
CustomerApp -. optional snapshot .-> ConvertApi
|
CustomerApp -. GPU buffer conversion .-> CaptureApi
|
||||||
QtApp --> CaptureApi
|
QtApp --> CaptureApi
|
||||||
QtApp --> DebugApi
|
QtApp --> DebugApi
|
||||||
QtApp --> PreviewApi
|
QtApp --> PreviewApi
|
||||||
PreviewApi --> PreviewPipe
|
PreviewApi --> PreviewPipe
|
||||||
ConvertApi --> ConvertPipe
|
|
||||||
ConvertApi --> CaptureApi
|
|
||||||
CaptureApi --> Facade
|
CaptureApi --> Facade
|
||||||
DebugApi --> Facade
|
DebugApi --> Facade
|
||||||
Facade --> PcieS2mm
|
Facade --> PcieS2mm
|
||||||
@@ -203,7 +192,7 @@ Released : ready=false, in_use=false
|
|||||||
- `frame.data` 在 `gvfg_release_frame()` 前有效。
|
- `frame.data` 在 `gvfg_release_frame()` 前有效。
|
||||||
- `frame.row_stride_bytes` 是相鄰兩列起點之間的 byte 距離;consumer 不應自行
|
- `frame.row_stride_bytes` 是相鄰兩列起點之間的 byte 距離;consumer 不應自行
|
||||||
由 width/format 猜 stride。
|
由 width/format 猜 stride。
|
||||||
- 現行 YUY2/Y210 都是 single-plane packed buffers,因此不公開 plane-layout API。
|
- 現行 YVYU/Y210 都是 single-plane packed buffers,因此不公開 plane-layout API。
|
||||||
- 未來真的加入 multi-plane format 時,再新增獨立的 plane-layout query。
|
- 未來真的加入 multi-plane format 時,再新增獨立的 plane-layout query。
|
||||||
- `gvfg_handle` 永遠 opaque;stable release 後 `gvfg_frame_t` 凍結,只有 major
|
- `gvfg_handle` 永遠 opaque;stable release 後 `gvfg_frame_t` 凍結,只有 major
|
||||||
version 可以破壞既有 ABI。
|
version 可以破壞既有 ABI。
|
||||||
@@ -211,8 +200,8 @@ Released : ready=false, in_use=false
|
|||||||
`gvfg_get_frame_color_info()` 與 `gvfg_get_frame_timestamp_info()`。不要預先在每個
|
`gvfg_get_frame_color_info()` 與 `gvfg_get_frame_timestamp_info()`。不要預先在每個
|
||||||
struct 放大型 reserved array;等 metadata 類型真的很多再考慮 side data。
|
struct 放大型 reserved array;等 metadata 類型真的很多再考慮 side data。
|
||||||
- `gvfg_preview.dll` 直接使用 capture frame 的 `row_stride_bytes`。
|
- `gvfg_preview.dll` 直接使用 capture frame 的 `row_stride_bytes`。
|
||||||
- `gvfg_convert.dll` 負責 explicit snapshot/export conversion。不要把 color
|
- `gvfg.dll` 提供 explicit GPU buffer conversion;API 不負責 image export、
|
||||||
conversion、image export、GPU conversion policy 搬進 `gvfg.dll`。
|
thread、queue 或 frame ownership policy。
|
||||||
- 同一個 handle 一次最多 hold 一個 frame。
|
- 同一個 handle 一次最多 hold 一個 frame。
|
||||||
- Application 如果 release 後還要用 data,必須自己 copy frame。
|
- Application 如果 release 後還要用 data,必須自己 copy frame。
|
||||||
- `gvfg_preview_render_frame()` 是 synchronous,應該在 `gvfg_release_frame()` 前呼叫。
|
- `gvfg_preview_render_frame()` 是 synchronous,應該在 `gvfg_release_frame()` 前呼叫。
|
||||||
@@ -277,7 +266,6 @@ Customer/demo 可見:
|
|||||||
```text
|
```text
|
||||||
include/gvfg_capture.h
|
include/gvfg_capture.h
|
||||||
include/gvfg_preview.h when display helper is used
|
include/gvfg_preview.h when display helper is used
|
||||||
include/gvfg_convert.h when snapshot/export conversion is used
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Internal debug only:
|
Internal debug only:
|
||||||
@@ -301,13 +289,10 @@ Include:
|
|||||||
```text
|
```text
|
||||||
include/gvfg_capture.h
|
include/gvfg_capture.h
|
||||||
include/gvfg_preview.h when the demo shows video
|
include/gvfg_preview.h when the demo shows video
|
||||||
include/gvfg_convert.h when the demo exports snapshots
|
|
||||||
lib/gvfg.lib
|
lib/gvfg.lib
|
||||||
lib/gvfg_preview.lib when the demo shows video
|
lib/gvfg_preview.lib when the demo shows video
|
||||||
lib/gvfg_convert.lib when the demo exports snapshots
|
|
||||||
bin/gvfg.dll
|
bin/gvfg.dll
|
||||||
bin/gvfg_preview.dll when the demo shows video
|
bin/gvfg_preview.dll when the demo shows video
|
||||||
bin/gvfg_convert.dll when the demo exports snapshots
|
|
||||||
samples/customer-facing source
|
samples/customer-facing source
|
||||||
docs/GVFG_CUSTOMER_API.md
|
docs/GVFG_CUSTOMER_API.md
|
||||||
```
|
```
|
||||||
@@ -332,22 +317,19 @@ Include:
|
|||||||
include/gvfg_capture.h
|
include/gvfg_capture.h
|
||||||
include/gvfg_debug.h
|
include/gvfg_debug.h
|
||||||
include/gvfg_preview.h
|
include/gvfg_preview.h
|
||||||
include/gvfg_convert.h
|
|
||||||
lib/gvfg.lib
|
lib/gvfg.lib
|
||||||
lib/gvfg_preview.lib
|
lib/gvfg_preview.lib
|
||||||
lib/gvfg_convert.lib
|
|
||||||
bin/gvfg.dll
|
bin/gvfg.dll
|
||||||
bin/gvfg_preview.dll
|
bin/gvfg_preview.dll
|
||||||
bin/gvfg_convert.dll
|
bin/gvfg_qt_preview.exe
|
||||||
bin/gvfg_qt_diagnostic.exe
|
|
||||||
PDB symbols
|
PDB symbols
|
||||||
internal debug notes
|
internal debug notes
|
||||||
```
|
```
|
||||||
|
|
||||||
### Full Release Package
|
### Full Release Package
|
||||||
|
|
||||||
Full application release 可以使用 `gvfg.dll`、`gvfg_preview.dll` 和
|
Full application release 可以使用 `gvfg.dll` 與 `gvfg_preview.dll`,再加上
|
||||||
`gvfg_convert.dll`,再加上 licensing 與 closed-source application integration。
|
licensing 與 closed-source application integration。
|
||||||
不要把 full release package 當成 daily driver/FPGA bring-up vehicle。
|
不要把 full release package 當成 daily driver/FPGA bring-up vehicle。
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
@@ -356,40 +338,28 @@ Top-level CMake 會 build core SDK、helpers 和 optional sample:
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
BUILD_GVFG_SAMPLES=ON
|
BUILD_GVFG_SAMPLES=ON
|
||||||
GVFG_ENABLE_INTERNAL_DEBUG_API=OFF
|
|
||||||
BUILD_GVFG_INTERNAL_TOOLS=OFF
|
|
||||||
GVFG_PCIES2MM_DEBUG_LOG=OFF
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Customer build 使用 `GVFG_ENABLE_INTERNAL_DEBUG_API=OFF`。此時 `gvfg.dll`
|
Internal diagnostic build 使用 Debug configuration:
|
||||||
不 export `gvfg_debug_get_backend_stats()` 或
|
|
||||||
`gvfg_debug_get_last_error_detail()`,install tree 也不包含
|
|
||||||
`gvfg_debug.h`。
|
|
||||||
|
|
||||||
Internal diagnostic build 使用:
|
|
||||||
|
|
||||||
```text
|
```text
|
||||||
BUILD_GVFG_SAMPLES=OFF
|
cmake --build build --target gvfg_qt_preview --config Debug
|
||||||
GVFG_ENABLE_INTERNAL_DEBUG_API=ON
|
|
||||||
BUILD_GVFG_INTERNAL_TOOLS=ON
|
|
||||||
```
|
```
|
||||||
|
|
||||||
只有這個 build 會產生 `gvfg_qt_diagnostic.exe` 並安裝
|
這個 build 仍產生 `gvfg_qt_preview.exe`,但會把 internal diagnostics
|
||||||
`gvfg_debug.h`。
|
編譯進同一個執行檔。
|
||||||
|
|
||||||
輸出產物:
|
輸出產物:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
bin/gvfg.dll
|
bin/gvfg.dll
|
||||||
bin/gvfg_preview.dll
|
bin/gvfg_preview.dll
|
||||||
bin/gvfg_convert.dll
|
|
||||||
lib/gvfg.lib
|
lib/gvfg.lib
|
||||||
lib/gvfg_preview.lib
|
lib/gvfg_preview.lib
|
||||||
lib/gvfg_convert.lib
|
|
||||||
bin/gvfg_qt_preview.exe
|
bin/gvfg_qt_preview.exe
|
||||||
```
|
```
|
||||||
|
|
||||||
`GVFG_PCIES2MM_DEBUG_LOG=ON` 會打開 internal backend 的 verbose PCIES2MM flow logging。
|
Debug configuration 也會打開 internal backend 的 verbose PCIES2MM flow logging。
|
||||||
|
|
||||||
## Draw.io Files
|
## Draw.io Files
|
||||||
|
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
project(gvfg_convert LANGUAGES CXX)
|
|
||||||
|
|
||||||
add_library(gvfg_convert SHARED
|
|
||||||
include/gvfg_convert.h
|
|
||||||
src/gvfg_convert.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set_target_properties(gvfg_convert PROPERTIES
|
|
||||||
AUTOMOC OFF
|
|
||||||
AUTOUIC OFF
|
|
||||||
AUTORCC OFF
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(gvfg_convert
|
|
||||||
PUBLIC
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
||||||
)
|
|
||||||
|
|
||||||
target_compile_definitions(gvfg_convert PRIVATE
|
|
||||||
GVFG_CONVERT_BUILD
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(gvfg_convert PUBLIC
|
|
||||||
gvfg
|
|
||||||
)
|
|
||||||
|
|
||||||
if (MSVC)
|
|
||||||
target_compile_options(gvfg_convert PRIVATE /utf-8 /EHsc)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
install(TARGETS gvfg_convert
|
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(FILES include/gvfg_convert.h
|
|
||||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
)
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Optional GVFG frame conversion helper.
|
|
||||||
*
|
|
||||||
* Link this helper only when the application needs snapshot/export-friendly
|
|
||||||
* buffers. Core capture frames from gvfg.dll remain native hardware buffers.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <gvfg_capture.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#ifdef GVFG_CONVERT_BUILD
|
|
||||||
#define GVFG_CONVERT_API __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define GVFG_CONVERT_API __declspec(dllimport)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define GVFG_CONVERT_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
GVFG_CONVERT_FMT_BGRA8 = 1, /* 8-bit BGRA, alpha 255. */
|
|
||||||
GVFG_CONVERT_FMT_RGB48 = 2, /* 16-bit RGB container, useful for 10-bit snapshots. */
|
|
||||||
GVFG_CONVERT_FMT_RGBA64 = 3 /* 16-bit RGBA container, alpha 65535. */
|
|
||||||
} gvfg_convert_format_t;
|
|
||||||
|
|
||||||
typedef struct gvfg_convert_frame_t *gvfg_convert_frame;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int width; /* Frame width in pixels. Use 0 to size from source during conversion. */
|
|
||||||
int height; /* Frame height in pixels. Use 0 to size from source during conversion. */
|
|
||||||
int pixel_format; /* gvfg_convert_format_t destination format. */
|
|
||||||
int row_bytes; /* Destination row stride in bytes. Use 0 for helper default. */
|
|
||||||
uint64_t data_size; /* Output buffer size in bytes, filled after create/convert. */
|
|
||||||
} gvfg_convert_frame_desc_t;
|
|
||||||
|
|
||||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_create_frame(
|
|
||||||
_In_ const gvfg_convert_frame_desc_t *desc,
|
|
||||||
_Outptr_ gvfg_convert_frame *out_frame);
|
|
||||||
|
|
||||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_destroy_frame(
|
|
||||||
_In_opt_ gvfg_convert_frame frame);
|
|
||||||
|
|
||||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_frame_from_capture(
|
|
||||||
_In_ const gvfg_frame_t *src,
|
|
||||||
_In_ gvfg_convert_frame dst_frame);
|
|
||||||
|
|
||||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_frame_desc(
|
|
||||||
_In_ gvfg_convert_frame frame,
|
|
||||||
_Out_ gvfg_convert_frame_desc_t *out_desc);
|
|
||||||
|
|
||||||
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_buffer(
|
|
||||||
_In_ gvfg_convert_frame frame,
|
|
||||||
_Out_ const void **out_data,
|
|
||||||
_Out_ uint64_t *out_size);
|
|
||||||
|
|
||||||
GVFG_CONVERT_API const char *gvfg_convert_strerror(
|
|
||||||
_In_ gvfg_status_t status);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,428 +0,0 @@
|
|||||||
#include "gvfg_convert.h"
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <climits>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstring>
|
|
||||||
#include <limits>
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
bool checked_mul_u64(uint64_t a, uint64_t b, uint64_t &out)
|
|
||||||
{
|
|
||||||
if (a != 0 && b > UINT64_MAX / a)
|
|
||||||
return false;
|
|
||||||
out = a * b;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int convert_format_bytes_per_pixel(int fmt)
|
|
||||||
{
|
|
||||||
switch (fmt)
|
|
||||||
{
|
|
||||||
case GVFG_CONVERT_FMT_BGRA8:
|
|
||||||
return 4;
|
|
||||||
case GVFG_CONVERT_FMT_RGB48:
|
|
||||||
return 6;
|
|
||||||
case GVFG_CONVERT_FMT_RGBA64:
|
|
||||||
return 8;
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t clamp_u8(double v)
|
|
||||||
{
|
|
||||||
if (v <= 0.0)
|
|
||||||
return 0;
|
|
||||||
if (v >= 255.0)
|
|
||||||
return 255;
|
|
||||||
return static_cast<uint8_t>(v + 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t clamp_u16(double v)
|
|
||||||
{
|
|
||||||
if (v <= 0.0)
|
|
||||||
return 0;
|
|
||||||
if (v >= 65535.0)
|
|
||||||
return 65535;
|
|
||||||
return static_cast<uint16_t>(v + 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
void yuv709_limited_to_rgb01(double y01,
|
|
||||||
double u01,
|
|
||||||
double v01,
|
|
||||||
double &r,
|
|
||||||
double &g,
|
|
||||||
double &b)
|
|
||||||
{
|
|
||||||
const double y = y01 * 255.0;
|
|
||||||
const double u = (u01 - 0.5) * 255.0;
|
|
||||||
const double v = (v01 - 0.5) * 255.0;
|
|
||||||
const double c = y - 16.0;
|
|
||||||
r = (1.164383 * c + 1.792741 * v) / 255.0;
|
|
||||||
g = (1.164383 * c - 0.213249 * u - 0.532909 * v) / 255.0;
|
|
||||||
b = (1.164383 * c + 2.112402 * u) / 255.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void store_converted_pixel(uint8_t *dst,
|
|
||||||
int dstFormat,
|
|
||||||
double r,
|
|
||||||
double g,
|
|
||||||
double b)
|
|
||||||
{
|
|
||||||
switch (dstFormat)
|
|
||||||
{
|
|
||||||
case GVFG_CONVERT_FMT_BGRA8:
|
|
||||||
dst[0] = clamp_u8(b * 255.0);
|
|
||||||
dst[1] = clamp_u8(g * 255.0);
|
|
||||||
dst[2] = clamp_u8(r * 255.0);
|
|
||||||
dst[3] = 255;
|
|
||||||
break;
|
|
||||||
case GVFG_CONVERT_FMT_RGB48:
|
|
||||||
{
|
|
||||||
auto *out = reinterpret_cast<uint16_t *>(dst);
|
|
||||||
out[0] = clamp_u16(r * 65535.0);
|
|
||||||
out[1] = clamp_u16(g * 65535.0);
|
|
||||||
out[2] = clamp_u16(b * 65535.0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case GVFG_CONVERT_FMT_RGBA64:
|
|
||||||
{
|
|
||||||
auto *out = reinterpret_cast<uint16_t *>(dst);
|
|
||||||
out[0] = clamp_u16(r * 65535.0);
|
|
||||||
out[1] = clamp_u16(g * 65535.0);
|
|
||||||
out[2] = clamp_u16(b * 65535.0);
|
|
||||||
out[3] = 65535;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t y210_word_to_10bit(uint16_t value)
|
|
||||||
{
|
|
||||||
return static_cast<uint16_t>((value >> 6) & 0x03ffu);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct gvfg_convert_frame_t
|
|
||||||
{
|
|
||||||
gvfg_convert_frame_desc_t request{};
|
|
||||||
gvfg_convert_frame_desc_t desc{};
|
|
||||||
std::vector<uint8_t> buffer;
|
|
||||||
|
|
||||||
gvfg_status_t configure(int width, int height, int pixelFormat, int rowBytes)
|
|
||||||
{
|
|
||||||
if (width <= 0 || height <= 0 || convert_format_bytes_per_pixel(pixelFormat) <= 0)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
const int bytesPerPixel = convert_format_bytes_per_pixel(pixelFormat);
|
|
||||||
uint64_t minStride64 = 0;
|
|
||||||
if (!checked_mul_u64(static_cast<uint64_t>(width),
|
|
||||||
static_cast<uint64_t>(bytesPerPixel),
|
|
||||||
minStride64) ||
|
|
||||||
minStride64 > static_cast<uint64_t>(INT_MAX))
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
const int minStride = static_cast<int>(minStride64);
|
|
||||||
const int actualStride = rowBytes > 0 ? rowBytes : minStride;
|
|
||||||
if (actualStride < minStride)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
uint64_t size = 0;
|
|
||||||
if (!checked_mul_u64(static_cast<uint64_t>(actualStride),
|
|
||||||
static_cast<uint64_t>(height),
|
|
||||||
size) ||
|
|
||||||
size > static_cast<uint64_t>((std::numeric_limits<size_t>::max)()))
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
desc = request;
|
|
||||||
desc.width = width;
|
|
||||||
desc.height = height;
|
|
||||||
desc.pixel_format = pixelFormat;
|
|
||||||
desc.row_bytes = actualStride;
|
|
||||||
desc.data_size = size;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
buffer.resize(static_cast<size_t>(size));
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
buffer.clear();
|
|
||||||
desc.data_size = 0;
|
|
||||||
return GVFG_EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
return GVFG_OK;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
gvfg_status_t create_or_reconfigure_frame(const gvfg_frame_t &src,
|
|
||||||
gvfg_convert_frame_t &dst)
|
|
||||||
{
|
|
||||||
const int requestedWidth = dst.request.width;
|
|
||||||
const int requestedHeight = dst.request.height;
|
|
||||||
const int targetWidth = requestedWidth > 0 ? requestedWidth : src.width;
|
|
||||||
const int targetHeight = requestedHeight > 0 ? requestedHeight : src.height;
|
|
||||||
|
|
||||||
if (targetWidth != src.width || targetHeight != src.height)
|
|
||||||
return GVFG_ENOTSUP;
|
|
||||||
|
|
||||||
if (!dst.buffer.empty() &&
|
|
||||||
dst.desc.width == targetWidth &&
|
|
||||||
dst.desc.height == targetHeight &&
|
|
||||||
dst.desc.pixel_format == dst.request.pixel_format &&
|
|
||||||
dst.desc.row_bytes > 0)
|
|
||||||
return GVFG_OK;
|
|
||||||
|
|
||||||
return dst.configure(targetWidth, targetHeight, dst.request.pixel_format, dst.request.row_bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
gvfg_status_t convert_yuy2_to_frame(const gvfg_frame_t &src,
|
|
||||||
gvfg_convert_frame_t &dst)
|
|
||||||
{
|
|
||||||
if (!src.data || src.row_stride_bytes < src.width * 2)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
uint64_t requiredSize = 0;
|
|
||||||
if (!checked_mul_u64(static_cast<uint64_t>(src.row_stride_bytes),
|
|
||||||
static_cast<uint64_t>(src.height),
|
|
||||||
requiredSize) ||
|
|
||||||
requiredSize > src.data_size)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
const auto *srcBase = static_cast<const uint8_t *>(src.data);
|
|
||||||
const int srcStride = src.row_stride_bytes;
|
|
||||||
const int bytesPerPixel = convert_format_bytes_per_pixel(dst.desc.pixel_format);
|
|
||||||
if (bytesPerPixel <= 0)
|
|
||||||
return GVFG_ENOTSUP;
|
|
||||||
|
|
||||||
for (int y = 0; y < src.height; ++y)
|
|
||||||
{
|
|
||||||
const uint8_t *srcRow = srcBase + static_cast<size_t>(y) * static_cast<size_t>(srcStride);
|
|
||||||
uint8_t *dstRow = dst.buffer.data() + static_cast<size_t>(y) * static_cast<size_t>(dst.desc.row_bytes);
|
|
||||||
|
|
||||||
for (int x = 0; x < src.width; x += 2)
|
|
||||||
{
|
|
||||||
const int sx = x * 2;
|
|
||||||
const uint8_t y0 = srcRow[sx + 0];
|
|
||||||
const uint8_t u = srcRow[sx + 1];
|
|
||||||
const uint8_t y1 = (x + 1 < src.width) ? srcRow[sx + 2] : y0;
|
|
||||||
const uint8_t v = (x + 1 < src.width) ? srcRow[sx + 3] : srcRow[sx + 1];
|
|
||||||
|
|
||||||
double r = 0.0, g = 0.0, b = 0.0;
|
|
||||||
yuv709_limited_to_rgb01(static_cast<double>(y0) / 255.0,
|
|
||||||
static_cast<double>(u) / 255.0,
|
|
||||||
static_cast<double>(v) / 255.0,
|
|
||||||
r,
|
|
||||||
g,
|
|
||||||
b);
|
|
||||||
store_converted_pixel(dstRow + static_cast<size_t>(x) * static_cast<size_t>(bytesPerPixel),
|
|
||||||
dst.desc.pixel_format,
|
|
||||||
r,
|
|
||||||
g,
|
|
||||||
b);
|
|
||||||
|
|
||||||
if (x + 1 < src.width)
|
|
||||||
{
|
|
||||||
yuv709_limited_to_rgb01(static_cast<double>(y1) / 255.0,
|
|
||||||
static_cast<double>(u) / 255.0,
|
|
||||||
static_cast<double>(v) / 255.0,
|
|
||||||
r,
|
|
||||||
g,
|
|
||||||
b);
|
|
||||||
store_converted_pixel(dstRow + static_cast<size_t>(x + 1) * static_cast<size_t>(bytesPerPixel),
|
|
||||||
dst.desc.pixel_format,
|
|
||||||
r,
|
|
||||||
g,
|
|
||||||
b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return GVFG_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
gvfg_status_t convert_y210_to_frame(const gvfg_frame_t &src,
|
|
||||||
gvfg_convert_frame_t &dst)
|
|
||||||
{
|
|
||||||
if (!src.data || src.row_stride_bytes < src.width * 4)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
uint64_t requiredSize = 0;
|
|
||||||
if (!checked_mul_u64(static_cast<uint64_t>(src.row_stride_bytes),
|
|
||||||
static_cast<uint64_t>(src.height),
|
|
||||||
requiredSize) ||
|
|
||||||
requiredSize > src.data_size)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
const auto *srcBase = static_cast<const uint8_t *>(src.data);
|
|
||||||
const int srcStride = src.row_stride_bytes;
|
|
||||||
const int bytesPerPixel = convert_format_bytes_per_pixel(dst.desc.pixel_format);
|
|
||||||
if (bytesPerPixel <= 0)
|
|
||||||
return GVFG_ENOTSUP;
|
|
||||||
|
|
||||||
for (int y = 0; y < src.height; ++y)
|
|
||||||
{
|
|
||||||
const auto *srcRow = reinterpret_cast<const uint16_t *>(srcBase + static_cast<size_t>(y) * static_cast<size_t>(srcStride));
|
|
||||||
uint8_t *dstRow = dst.buffer.data() + static_cast<size_t>(y) * static_cast<size_t>(dst.desc.row_bytes);
|
|
||||||
|
|
||||||
for (int x = 0; x < src.width; x += 2)
|
|
||||||
{
|
|
||||||
const int sx = x * 2;
|
|
||||||
// Standard Y210 is Y0, Cb(U), Y1, Cr(V). Normalize the
|
|
||||||
// current FPGA DMA order Y0, Cr(V), Y1, Cb(U) before RGB
|
|
||||||
// conversion so snapshots match the preview path.
|
|
||||||
const uint16_t y0 = y210_word_to_10bit(srcRow[sx + 0]);
|
|
||||||
const uint16_t v = y210_word_to_10bit(srcRow[sx + 1]);
|
|
||||||
const uint16_t y1 = (x + 1 < src.width) ? y210_word_to_10bit(srcRow[sx + 2]) : y0;
|
|
||||||
const uint16_t u = (x + 1 < src.width) ? y210_word_to_10bit(srcRow[sx + 3]) : v;
|
|
||||||
|
|
||||||
double r = 0.0, g = 0.0, b = 0.0;
|
|
||||||
yuv709_limited_to_rgb01(static_cast<double>(y0) / 1023.0,
|
|
||||||
static_cast<double>(u) / 1023.0,
|
|
||||||
static_cast<double>(v) / 1023.0,
|
|
||||||
r,
|
|
||||||
g,
|
|
||||||
b);
|
|
||||||
store_converted_pixel(dstRow + static_cast<size_t>(x) * static_cast<size_t>(bytesPerPixel),
|
|
||||||
dst.desc.pixel_format,
|
|
||||||
r,
|
|
||||||
g,
|
|
||||||
b);
|
|
||||||
|
|
||||||
if (x + 1 < src.width)
|
|
||||||
{
|
|
||||||
yuv709_limited_to_rgb01(static_cast<double>(y1) / 1023.0,
|
|
||||||
static_cast<double>(u) / 1023.0,
|
|
||||||
static_cast<double>(v) / 1023.0,
|
|
||||||
r,
|
|
||||||
g,
|
|
||||||
b);
|
|
||||||
store_converted_pixel(dstRow + static_cast<size_t>(x + 1) * static_cast<size_t>(bytesPerPixel),
|
|
||||||
dst.desc.pixel_format,
|
|
||||||
r,
|
|
||||||
g,
|
|
||||||
b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return GVFG_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
gvfg_status_t gvfg_convert_create_frame(const gvfg_convert_frame_desc_t *desc,
|
|
||||||
gvfg_convert_frame *out_frame)
|
|
||||||
{
|
|
||||||
if (!desc || !out_frame)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
*out_frame = nullptr;
|
|
||||||
|
|
||||||
if (convert_format_bytes_per_pixel(desc->pixel_format) <= 0)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
if (desc->width < 0 || desc->height < 0 || desc->row_bytes < 0)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
auto frame = std::make_unique<gvfg_convert_frame_t>();
|
|
||||||
frame->request = {};
|
|
||||||
frame->request.width = desc->width;
|
|
||||||
frame->request.height = desc->height;
|
|
||||||
frame->request.pixel_format = desc->pixel_format;
|
|
||||||
frame->request.row_bytes = desc->row_bytes;
|
|
||||||
frame->desc = frame->request;
|
|
||||||
|
|
||||||
if (desc->width > 0 || desc->height > 0 || desc->row_bytes > 0)
|
|
||||||
{
|
|
||||||
if (desc->width <= 0 || desc->height <= 0)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
const gvfg_status_t st = frame->configure(desc->width,
|
|
||||||
desc->height,
|
|
||||||
desc->pixel_format,
|
|
||||||
desc->row_bytes);
|
|
||||||
if (st != GVFG_OK)
|
|
||||||
return st;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_frame = frame.release();
|
|
||||||
return GVFG_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
gvfg_status_t gvfg_convert_destroy_frame(gvfg_convert_frame frame)
|
|
||||||
{
|
|
||||||
delete frame;
|
|
||||||
return GVFG_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
gvfg_status_t gvfg_convert_frame_from_capture(const gvfg_frame_t *src,
|
|
||||||
gvfg_convert_frame dst_frame)
|
|
||||||
{
|
|
||||||
if (!src || !dst_frame)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
|
|
||||||
const gvfg_status_t cfg = create_or_reconfigure_frame(*src, *dst_frame);
|
|
||||||
if (cfg != GVFG_OK)
|
|
||||||
return cfg;
|
|
||||||
|
|
||||||
switch (src->pixel_format)
|
|
||||||
{
|
|
||||||
case GVFG_PIXFMT_YUY2:
|
|
||||||
return convert_yuy2_to_frame(*src, *dst_frame);
|
|
||||||
case GVFG_PIXFMT_Y210:
|
|
||||||
return convert_y210_to_frame(*src, *dst_frame);
|
|
||||||
default:
|
|
||||||
return GVFG_ENOTSUP;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gvfg_status_t gvfg_convert_get_frame_desc(gvfg_convert_frame frame,
|
|
||||||
gvfg_convert_frame_desc_t *out_desc)
|
|
||||||
{
|
|
||||||
if (!frame || !out_desc)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
*out_desc = frame->desc;
|
|
||||||
return GVFG_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
gvfg_status_t gvfg_convert_get_buffer(gvfg_convert_frame frame,
|
|
||||||
const void **out_data,
|
|
||||||
uint64_t *out_size)
|
|
||||||
{
|
|
||||||
if (!frame || !out_data || !out_size)
|
|
||||||
return GVFG_EINVAL;
|
|
||||||
*out_data = frame->buffer.empty() ? nullptr : frame->buffer.data();
|
|
||||||
*out_size = static_cast<uint64_t>(frame->buffer.size());
|
|
||||||
return frame->buffer.empty() ? GVFG_ESTATE : GVFG_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *gvfg_convert_strerror(gvfg_status_t status)
|
|
||||||
{
|
|
||||||
switch (status)
|
|
||||||
{
|
|
||||||
case GVFG_OK:
|
|
||||||
return "ok";
|
|
||||||
case GVFG_EINVAL:
|
|
||||||
return "invalid argument";
|
|
||||||
case GVFG_ENODEV:
|
|
||||||
return "device not found";
|
|
||||||
case GVFG_ESTATE:
|
|
||||||
return "invalid state";
|
|
||||||
case GVFG_EIO:
|
|
||||||
return "i/o error";
|
|
||||||
case GVFG_ENOTSUP:
|
|
||||||
return "not supported";
|
|
||||||
case GVFG_ETIMEOUT:
|
|
||||||
return "timeout";
|
|
||||||
default:
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,8 +2,8 @@ project(gvfg_preview LANGUAGES CXX)
|
|||||||
|
|
||||||
add_library(gvfg_preview SHARED
|
add_library(gvfg_preview SHARED
|
||||||
include/gvfg_preview.h
|
include/gvfg_preview.h
|
||||||
src/d3d_preview_pipeline.cpp
|
../../sdk/gvfg/src/gpu/d3d_conversion_pipeline.cpp
|
||||||
src/d3d_preview_pipeline.h
|
../../sdk/gvfg/src/gpu/d3d_conversion_pipeline.h
|
||||||
src/gvfg_preview.cpp
|
src/gvfg_preview.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,6 +18,7 @@ target_include_directories(gvfg_preview
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../sdk/gvfg/src/gpu
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(gvfg_preview PRIVATE
|
target_compile_definitions(gvfg_preview PRIVATE
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ typedef struct gvfg_preview_handle_t *gvfg_preview_handle;
|
|||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
GVFG_PREVIEW_PIXFMT_YUY2 = 1,
|
GVFG_PREVIEW_PIXFMT_Y210 = 2,
|
||||||
GVFG_PREVIEW_PIXFMT_Y210 = 2
|
GVFG_PREVIEW_PIXFMT_YVYU = 3
|
||||||
} gvfg_preview_pixel_format_t;
|
} gvfg_preview_pixel_format_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "gvfg_preview.h"
|
#include "gvfg_preview.h"
|
||||||
|
|
||||||
#include "d3d_preview_pipeline.h"
|
#include "d3d_conversion_pipeline.h"
|
||||||
|
|
||||||
#include <d3d11_4.h>
|
#include <d3d11_4.h>
|
||||||
#include <dxgi1_2.h>
|
#include <dxgi1_2.h>
|
||||||
@@ -61,15 +61,15 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
gvfg::internal::gvfg_render_pixfmt_t renderFmt = gvfg::internal::GVFG_RENDER_FMT_YUY2;
|
gvfg::internal::gvfg_render_pixfmt_t renderFmt = gvfg::internal::GVFG_RENDER_FMT_YVYU;
|
||||||
const uint8_t *base = static_cast<const uint8_t *>(frame.data);
|
const uint8_t *base = static_cast<const uint8_t *>(frame.data);
|
||||||
const int stride = frame.row_bytes;
|
const int stride = frame.row_bytes;
|
||||||
bool uploaded = false;
|
bool uploaded = false;
|
||||||
|
|
||||||
switch (frame.pixel_format)
|
switch (frame.pixel_format)
|
||||||
{
|
{
|
||||||
case GVFG_PREVIEW_PIXFMT_YUY2:
|
case GVFG_PREVIEW_PIXFMT_YVYU:
|
||||||
renderFmt = gvfg::internal::GVFG_RENDER_FMT_YUY2;
|
renderFmt = gvfg::internal::GVFG_RENDER_FMT_YVYU;
|
||||||
break;
|
break;
|
||||||
case GVFG_PREVIEW_PIXFMT_Y210:
|
case GVFG_PREVIEW_PIXFMT_Y210:
|
||||||
renderFmt = gvfg::internal::GVFG_RENDER_FMT_Y210;
|
renderFmt = gvfg::internal::GVFG_RENDER_FMT_Y210;
|
||||||
@@ -80,8 +80,8 @@ public:
|
|||||||
|
|
||||||
switch (frame.pixel_format)
|
switch (frame.pixel_format)
|
||||||
{
|
{
|
||||||
case GVFG_PREVIEW_PIXFMT_YUY2:
|
case GVFG_PREVIEW_PIXFMT_YVYU:
|
||||||
uploaded = pipeline_->upload_yuy2_frame(base, stride, frame.width, frame.height);
|
uploaded = pipeline_->upload_packed_422_frame(base, stride, frame.width, frame.height);
|
||||||
break;
|
break;
|
||||||
case GVFG_PREVIEW_PIXFMT_Y210:
|
case GVFG_PREVIEW_PIXFMT_Y210:
|
||||||
uploaded = pipeline_->upload_y210_frame(base, stride, frame.width, frame.height);
|
uploaded = pipeline_->upload_y210_frame(base, stride, frame.width, frame.height);
|
||||||
@@ -438,7 +438,7 @@ extern "C"
|
|||||||
uint64_t minimumRowBytes = 0;
|
uint64_t minimumRowBytes = 0;
|
||||||
switch (frame->pixel_format)
|
switch (frame->pixel_format)
|
||||||
{
|
{
|
||||||
case GVFG_PREVIEW_PIXFMT_YUY2:
|
case GVFG_PREVIEW_PIXFMT_YVYU:
|
||||||
minimumRowBytes = static_cast<uint64_t>(frame->width) * 2u;
|
minimumRowBytes = static_cast<uint64_t>(frame->width) * 2u;
|
||||||
break;
|
break;
|
||||||
case GVFG_PREVIEW_PIXFMT_Y210:
|
case GVFG_PREVIEW_PIXFMT_Y210:
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal
|
||||||
|
|
||||||
|
set "PROJECT_DIR=%~dp0"
|
||||||
|
set "BUILD_DIR=%PROJECT_DIR%build_diagnostic"
|
||||||
|
set "VSDEVCMD=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat"
|
||||||
|
set "CMAKE=C:\Qt\Tools\CMake_64\bin\cmake.exe"
|
||||||
|
set "QT_DIR=C:\Qt\6.10.2\msvc2022_64"
|
||||||
|
|
||||||
|
call "%VSDEVCMD%" -arch=x64
|
||||||
|
if errorlevel 1 goto :failed
|
||||||
|
|
||||||
|
"%CMAKE%" -S "%PROJECT_DIR%" -B "%BUILD_DIR%" ^
|
||||||
|
-DBUILD_GVFG_SAMPLES=ON ^
|
||||||
|
-DCMAKE_PREFIX_PATH="%QT_DIR%"
|
||||||
|
if errorlevel 1 goto :failed
|
||||||
|
|
||||||
|
"%CMAKE%" --build "%BUILD_DIR%" --target gvfg_qt_preview --config Debug
|
||||||
|
if errorlevel 1 goto :failed
|
||||||
|
|
||||||
|
start "GVFG Diagnostic" "%BUILD_DIR%\bin\Debug\gvfg_qt_preview.exe"
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:failed
|
||||||
|
echo.
|
||||||
|
echo GVFG diagnostic build failed.
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
@@ -18,48 +18,36 @@ set(GVFG_QT_PREVIEW_SOURCES
|
|||||||
previewwindow.ui
|
previewwindow.ui
|
||||||
)
|
)
|
||||||
|
|
||||||
function(add_gvfg_qt_preview_target target_name internal_diagnostics)
|
if (QT_VERSION_MAJOR GREATER_EQUAL 6)
|
||||||
if (QT_VERSION_MAJOR GREATER_EQUAL 6)
|
qt_add_executable(gvfg_qt_preview ${GVFG_QT_PREVIEW_SOURCES})
|
||||||
qt_add_executable(${target_name} ${GVFG_QT_PREVIEW_SOURCES})
|
else()
|
||||||
else()
|
add_executable(gvfg_qt_preview ${GVFG_QT_PREVIEW_SOURCES})
|
||||||
add_executable(${target_name} ${GVFG_QT_PREVIEW_SOURCES})
|
endif()
|
||||||
endif()
|
|
||||||
|
|
||||||
target_link_libraries(${target_name} PRIVATE
|
target_link_libraries(gvfg_qt_preview PRIVATE
|
||||||
Qt${QT_VERSION_MAJOR}::Widgets
|
Qt${QT_VERSION_MAJOR}::Widgets
|
||||||
gvfg
|
gvfg
|
||||||
gvfg_preview
|
gvfg_preview
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(${target_name} PRIVATE
|
target_compile_definitions(gvfg_qt_preview PRIVATE
|
||||||
GVFG_INTERNAL_DIAGNOSTICS=${internal_diagnostics}
|
GVFG_INTERNAL_DIAGNOSTICS=$<IF:$<CONFIG:Debug>,1,0>
|
||||||
)
|
)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_compile_options(${target_name} PRIVATE /utf-8)
|
target_compile_options(gvfg_qt_preview PRIVATE /utf-8)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_custom_command(TARGET ${target_name} POST_BUILD
|
add_custom_command(TARGET gvfg_qt_preview POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
$<TARGET_FILE:gvfg>
|
$<TARGET_FILE:gvfg>
|
||||||
$<TARGET_FILE_DIR:${target_name}>
|
$<TARGET_FILE_DIR:gvfg_qt_preview>
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(${target_name} PROPERTIES
|
set_target_properties(gvfg_qt_preview PROPERTIES
|
||||||
WIN32_EXECUTABLE TRUE
|
WIN32_EXECUTABLE TRUE
|
||||||
)
|
)
|
||||||
endfunction()
|
|
||||||
|
|
||||||
if (BUILD_GVFG_SAMPLES)
|
install(TARGETS gvfg_qt_preview
|
||||||
add_gvfg_qt_preview_target(gvfg_qt_preview 0)
|
|
||||||
install(TARGETS gvfg_qt_preview
|
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
)
|
)
|
||||||
endif()
|
|
||||||
|
|
||||||
if (BUILD_GVFG_INTERNAL_TOOLS)
|
|
||||||
add_gvfg_qt_preview_target(gvfg_qt_diagnostic 1)
|
|
||||||
install(TARGETS gvfg_qt_diagnostic
|
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace
|
|||||||
QString logFilePrefix()
|
QString logFilePrefix()
|
||||||
{
|
{
|
||||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
return QStringLiteral("gvfg_qt_diagnostic");
|
return QStringLiteral("gvfg_qt_preview_debug");
|
||||||
#else
|
#else
|
||||||
return QStringLiteral("gvfg_qt_preview");
|
return QStringLiteral("gvfg_qt_preview");
|
||||||
#endif
|
#endif
|
||||||
@@ -332,6 +332,7 @@ void MainWindow::closeDevice()
|
|||||||
|
|
||||||
ui_->statusLabel->setText(QStringLiteral("Idle"));
|
ui_->statusLabel->setText(QStringLiteral("Idle"));
|
||||||
lastSignalStatusText_.clear();
|
lastSignalStatusText_.clear();
|
||||||
|
lastLoggedInputStatus_.clear();
|
||||||
updateUiState();
|
updateUiState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,6 +444,18 @@ void MainWindow::updateSignalStatus()
|
|||||||
if (gvfg_get_signal_status(handle_, &signal) != GVFG_OK)
|
if (gvfg_get_signal_status(handle_, &signal) != GVFG_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const QString inputStatus = signal.connected
|
||||||
|
? QStringLiteral("CH%1 Connected | %2")
|
||||||
|
.arg(signal.channel)
|
||||||
|
.arg(signalFrameText(signal))
|
||||||
|
: QStringLiteral("CH%1 No signal")
|
||||||
|
.arg(signal.channel);
|
||||||
|
if (inputStatus != lastLoggedInputStatus_)
|
||||||
|
{
|
||||||
|
appendLog(QStringLiteral("Input status | %1").arg(inputStatus));
|
||||||
|
lastLoggedInputStatus_ = inputStatus;
|
||||||
|
}
|
||||||
|
|
||||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
gvfg_debug_backend_stats_t backendStats{};
|
gvfg_debug_backend_stats_t backendStats{};
|
||||||
const bool haveBackendStats = gvfg_debug_get_backend_stats(handle_, &backendStats) == GVFG_OK;
|
const bool haveBackendStats = gvfg_debug_get_backend_stats(handle_, &backendStats) == GVFG_OK;
|
||||||
@@ -756,8 +769,8 @@ void MainWindow::captureReadLoop()
|
|||||||
|
|
||||||
switch (frame.pixel_format)
|
switch (frame.pixel_format)
|
||||||
{
|
{
|
||||||
case GVFG_PIXFMT_YUY2:
|
case GVFG_PIXFMT_YVYU:
|
||||||
previewFrame.pixel_format = GVFG_PREVIEW_PIXFMT_YUY2;
|
previewFrame.pixel_format = GVFG_PREVIEW_PIXFMT_YVYU;
|
||||||
break;
|
break;
|
||||||
case GVFG_PIXFMT_Y210:
|
case GVFG_PIXFMT_Y210:
|
||||||
previewFrame.pixel_format = GVFG_PREVIEW_PIXFMT_Y210;
|
previewFrame.pixel_format = GVFG_PREVIEW_PIXFMT_Y210;
|
||||||
@@ -827,19 +840,32 @@ void MainWindow::captureReadLoop()
|
|||||||
if (st == GVFG_ETIMEOUT)
|
if (st == GVFG_ETIMEOUT)
|
||||||
{
|
{
|
||||||
++consecutiveTimeouts;
|
++consecutiveTimeouts;
|
||||||
if (!captureStalledLogged &&
|
const bool firstReport = !captureStalledLogged && consecutiveTimeouts >= 10;
|
||||||
consecutiveTimeouts >= 10 &&
|
const bool periodicReport = captureStalledLogged && (consecutiveTimeouts % 50) == 0;
|
||||||
(consecutiveTimeouts % 5) == 0)
|
if (firstReport || periodicReport)
|
||||||
{
|
{
|
||||||
gvfg_signal_status_t signal{};
|
gvfg_signal_status_t signal{};
|
||||||
if (gvfg_get_signal_status(handle_, &signal) == GVFG_OK && signal.connected)
|
const gvfg_status_t signalStatus = gvfg_get_signal_status(handle_, &signal);
|
||||||
{
|
const QString detail = signalStatus != GVFG_OK
|
||||||
|
? QStringLiteral("signal query failed: %1")
|
||||||
|
.arg(QString::fromUtf8(gvfg_strerror(signalStatus)))
|
||||||
|
: signal.connected
|
||||||
|
? signalFrameText(signal)
|
||||||
|
: QStringLiteral("No signal");
|
||||||
captureStalledLogged = true;
|
captureStalledLogged = true;
|
||||||
QMetaObject::invokeMethod(this, [this]()
|
const uint32_t elapsedMs = consecutiveTimeouts * 200u;
|
||||||
{ appendLog(QStringLiteral("ERROR capture stalled: no frame for at least 2 seconds")); },
|
QMetaObject::invokeMethod(this, [this, elapsedMs, detail]()
|
||||||
|
{
|
||||||
|
appendLog(QStringLiteral("ERROR no capture frame for %1 ms | %2")
|
||||||
|
.arg(elapsedMs)
|
||||||
|
.arg(detail));
|
||||||
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
|
updateSignalStatus();
|
||||||
|
writeDiagnosticSnapshot(lastSignalStatusText_);
|
||||||
|
#endif
|
||||||
|
},
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (captureStop_.load(std::memory_order_acquire) || st == GVFG_ESTATE)
|
if (captureStop_.load(std::memory_order_acquire) || st == GVFG_ESTATE)
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ private:
|
|||||||
uint64_t previewFailureCount_ = 0;
|
uint64_t previewFailureCount_ = 0;
|
||||||
QTimer *signalStatusTimer_ = nullptr;
|
QTimer *signalStatusTimer_ = nullptr;
|
||||||
QString lastSignalStatusText_;
|
QString lastSignalStatusText_;
|
||||||
|
QString lastLoggedInputStatus_;
|
||||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
QString lastLoggedBackendError_;
|
QString lastLoggedBackendError_;
|
||||||
uint64_t lastDebugDmaErrors_ = 0;
|
uint64_t lastDebugDmaErrors_ = 0;
|
||||||
|
|||||||
+11
-7
@@ -2,8 +2,6 @@ if (NOT DEFINED GVFG_SDK_VERSION)
|
|||||||
set(GVFG_SDK_VERSION "0.1.0" CACHE STRING "GVFG SDK version")
|
set(GVFG_SDK_VERSION "0.1.0" CACHE STRING "GVFG SDK version")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(GVFG_PCIES2MM_DEBUG_LOG "Write verbose PCIES2MM backend trace logs" OFF)
|
|
||||||
|
|
||||||
project(gvfg VERSION ${GVFG_SDK_VERSION} LANGUAGES CXX)
|
project(gvfg VERSION ${GVFG_SDK_VERSION} LANGUAGES CXX)
|
||||||
|
|
||||||
add_library(gvfg SHARED
|
add_library(gvfg SHARED
|
||||||
@@ -18,6 +16,9 @@ add_library(gvfg SHARED
|
|||||||
src/backend/pcies2mm/pcies2mm_reg.h
|
src/backend/pcies2mm/pcies2mm_reg.h
|
||||||
src/backend/pcies2mm/pcies2mm_video_format.cpp
|
src/backend/pcies2mm/pcies2mm_video_format.cpp
|
||||||
src/backend/pcies2mm/pcies2mm_video_format.h
|
src/backend/pcies2mm/pcies2mm_video_format.h
|
||||||
|
src/gpu/d3d_conversion_pipeline.cpp
|
||||||
|
src/gpu/d3d_conversion_pipeline.h
|
||||||
|
src/gpu/gvfg_gpu_convert.cpp
|
||||||
src/gvfg_capture.cpp
|
src/gvfg_capture.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ target_include_directories(gvfg
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/backend/pcies2mm
|
${CMAKE_CURRENT_SOURCE_DIR}/src/backend/pcies2mm
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/gpu
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(gvfg PRIVATE
|
target_compile_definitions(gvfg PRIVATE
|
||||||
@@ -39,14 +41,16 @@ target_compile_definitions(gvfg PRIVATE
|
|||||||
GVFG_SDK_VERSION="${GVFG_SDK_VERSION}"
|
GVFG_SDK_VERSION="${GVFG_SDK_VERSION}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if (GVFG_PCIES2MM_DEBUG_LOG)
|
target_compile_definitions(gvfg PRIVATE
|
||||||
target_compile_definitions(gvfg PRIVATE GVFG_PCIES2MM_DEBUG_LOG=1)
|
GVFG_INTERNAL_DIAGNOSTICS=$<IF:$<CONFIG:Debug>,1,0>
|
||||||
else()
|
)
|
||||||
target_compile_definitions(gvfg PRIVATE GVFG_PCIES2MM_DEBUG_LOG=0)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_link_libraries(gvfg PRIVATE
|
target_link_libraries(gvfg PRIVATE
|
||||||
setupapi
|
setupapi
|
||||||
|
user32
|
||||||
|
dxgi
|
||||||
|
d3d11
|
||||||
|
D3DCompiler
|
||||||
)
|
)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
|
|||||||
@@ -99,8 +99,8 @@ extern "C"
|
|||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
GVFG_PIXFMT_UNKNOWN = 0,
|
GVFG_PIXFMT_UNKNOWN = 0,
|
||||||
GVFG_PIXFMT_YUY2 = 1,
|
GVFG_PIXFMT_Y210 = 2,
|
||||||
GVFG_PIXFMT_Y210 = 2
|
GVFG_PIXFMT_YVYU = 3
|
||||||
} gvfg_pixel_format_t;
|
} gvfg_pixel_format_t;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
@@ -143,6 +143,23 @@ extern "C"
|
|||||||
uint64_t frame_id; /* Monotonic identifier within the current gvfg_start()/stop() run. */
|
uint64_t frame_id; /* Monotonic identifier within the current gvfg_start()/stop() run. */
|
||||||
} gvfg_frame_t;
|
} gvfg_frame_t;
|
||||||
|
|
||||||
|
/* Packed RGB formats produced by gvfg_gpu_convert_to_buffer(). */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
/* DXGI-compatible B8G8R8A8_UNORM byte layout, alpha is 255. */
|
||||||
|
GVFG_GPU_OUTPUT_BGRA8 = 1,
|
||||||
|
/* DXGI-compatible R10G10B10A2_UNORM packed uint32 layout, alpha is 3. */
|
||||||
|
GVFG_GPU_OUTPUT_RGB10A2 = 2
|
||||||
|
} gvfg_gpu_output_format_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
void *data; /* Caller-owned destination memory. */
|
||||||
|
uint64_t data_size; /* Bytes available from data. */
|
||||||
|
int row_bytes; /* Destination stride; must be at least width * 4. */
|
||||||
|
int pixel_format; /* gvfg_gpu_output_format_t. */
|
||||||
|
} gvfg_gpu_output_buffer_t;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
GVFG_EVENT_UNKNOWN = 0,
|
GVFG_EVENT_UNKNOWN = 0,
|
||||||
@@ -288,6 +305,22 @@ extern "C"
|
|||||||
_In_ gvfg_handle handle,
|
_In_ gvfg_handle handle,
|
||||||
_In_ const gvfg_frame_t *frame);
|
_In_ const gvfg_frame_t *frame);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a captured YVYU or Y210 frame with the GPU and copy the packed
|
||||||
|
* RGB result into caller-owned memory.
|
||||||
|
*
|
||||||
|
* This call is synchronous. The source frame and destination buffer must
|
||||||
|
* remain valid until it returns; the SDK retains neither pointer. A frame
|
||||||
|
* returned by gvfg_read_frame() must therefore be converted before
|
||||||
|
* gvfg_release_frame().
|
||||||
|
*
|
||||||
|
* BGRA8 and RGB10A2 both require at least width * 4 bytes per row and
|
||||||
|
* output->data_size of at least output->row_bytes * height bytes.
|
||||||
|
*/
|
||||||
|
GVFG_API gvfg_status_t gvfg_gpu_convert_to_buffer(
|
||||||
|
_In_ const gvfg_frame_t *source,
|
||||||
|
_In_ const gvfg_gpu_output_buffer_t *output);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Poll one capture event.
|
* Poll one capture event.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ typedef struct
|
|||||||
int width; /* Width of the most recent frame returned by gvfg_read_frame(). */
|
int width; /* Width of the most recent frame returned by gvfg_read_frame(). */
|
||||||
int height; /* Height of the most recent frame returned by gvfg_read_frame(). */
|
int height; /* Height of the most recent frame returned by gvfg_read_frame(). */
|
||||||
int bit_depth; /* Bits per color channel of the frame buffer. */
|
int bit_depth; /* Bits per color channel of the frame buffer. */
|
||||||
int pixel_format; /* gvfg_pixel_format_t value: YUY2 or Y210. */
|
int pixel_format; /* gvfg_pixel_format_t value: YVYU or Y210. */
|
||||||
int valid; /* Non-zero after a frame is returned during the current running session. */
|
int valid; /* Non-zero after a frame is returned during the current running session. */
|
||||||
} gvfg_debug_last_frame_info_t;
|
} gvfg_debug_last_frame_info_t;
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ typedef enum pcies2mm_status_t
|
|||||||
typedef enum pcies2mm_pixel_format_t
|
typedef enum pcies2mm_pixel_format_t
|
||||||
{
|
{
|
||||||
PCIES2MM_PIXFMT_UNKNOWN = 0,
|
PCIES2MM_PIXFMT_UNKNOWN = 0,
|
||||||
PCIES2MM_PIXFMT_YUY2 = 1,
|
PCIES2MM_PIXFMT_Y210 = 2,
|
||||||
PCIES2MM_PIXFMT_Y210 = 2
|
PCIES2MM_PIXFMT_YVYU = 3
|
||||||
} pcies2mm_pixel_format_t;
|
} pcies2mm_pixel_format_t;
|
||||||
|
|
||||||
typedef enum pcies2mm_stream_state_t
|
typedef enum pcies2mm_stream_state_t
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace
|
|||||||
|
|
||||||
static void trace_log(bool forceDebugOutput, const char *tag, const char *fmt, ...)
|
static void trace_log(bool forceDebugOutput, const char *tag, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
#if GVFG_PCIES2MM_DEBUG_LOG
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
(void)forceDebugOutput;
|
(void)forceDebugOutput;
|
||||||
#else
|
#else
|
||||||
if (!forceDebugOutput)
|
if (!forceDebugOutput)
|
||||||
@@ -126,7 +126,7 @@ namespace gvfg::internal
|
|||||||
stream_desc_.channel = 0;
|
stream_desc_.channel = 0;
|
||||||
stream_desc_.width = kDefaultWidth;
|
stream_desc_.width = kDefaultWidth;
|
||||||
stream_desc_.height = kDefaultHeight;
|
stream_desc_.height = kDefaultHeight;
|
||||||
stream_desc_.pixel_format = PCIES2MM_PIXFMT_YUY2;
|
stream_desc_.pixel_format = PCIES2MM_PIXFMT_YVYU;
|
||||||
stream_desc_.buffer_count = kDefaultRingBufferCount;
|
stream_desc_.buffer_count = kDefaultRingBufferCount;
|
||||||
stream_bit_depth_ = 8;
|
stream_bit_depth_ = 8;
|
||||||
reset_stats(stats_, PCIES2MM_STREAM_STOPPED);
|
reset_stats(stats_, PCIES2MM_STREAM_STOPPED);
|
||||||
@@ -268,10 +268,10 @@ namespace gvfg::internal
|
|||||||
if (desc.width == 0 || desc.height == 0)
|
if (desc.width == 0 || desc.height == 0)
|
||||||
return PCIES2MM_EINVAL;
|
return PCIES2MM_EINVAL;
|
||||||
|
|
||||||
pcies2mm_pixel_format_t fmt = desc.pixel_format == PCIES2MM_PIXFMT_UNKNOWN ? PCIES2MM_PIXFMT_YUY2 : desc.pixel_format;
|
pcies2mm_pixel_format_t fmt = desc.pixel_format == PCIES2MM_PIXFMT_UNKNOWN ? PCIES2MM_PIXFMT_YVYU : desc.pixel_format;
|
||||||
switch (fmt)
|
switch (fmt)
|
||||||
{
|
{
|
||||||
case PCIES2MM_PIXFMT_YUY2:
|
case PCIES2MM_PIXFMT_YVYU:
|
||||||
case PCIES2MM_PIXFMT_Y210:
|
case PCIES2MM_PIXFMT_Y210:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -347,6 +347,18 @@ namespace gvfg::internal
|
|||||||
close_event_handles();
|
close_event_handles();
|
||||||
return fail(PCIES2MM_EIO, "enable video capture", err);
|
return fail(PCIES2MM_EIO, "enable video capture", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t dmaEnableReadback = 0;
|
||||||
|
uint32_t videoEnableReadback = 0;
|
||||||
|
const bool dmaReadOk = read_reg(video_base() + VIDEO_DMA_EN_OFFSET, dmaEnableReadback);
|
||||||
|
const bool videoReadOk = read_reg(video_base() + VIDEO_EN_OFFSET, videoEnableReadback);
|
||||||
|
PCIES2MM_LOG("capture enable: dma_write=%d video_write=%d dma_read=%s0x%08X video_read=%s0x%08X",
|
||||||
|
dmaEnableOk ? 1 : 0,
|
||||||
|
videoEnableOk ? 1 : 0,
|
||||||
|
dmaReadOk ? "" : "FAILED/",
|
||||||
|
dmaEnableReadback,
|
||||||
|
videoReadOk ? "" : "FAILED/",
|
||||||
|
videoEnableReadback);
|
||||||
}
|
}
|
||||||
|
|
||||||
running_ = true;
|
running_ = true;
|
||||||
@@ -724,7 +736,15 @@ namespace gvfg::internal
|
|||||||
void PcieS2mmCaptureSession::capture_thread_proc()
|
void PcieS2mmCaptureSession::capture_thread_proc()
|
||||||
{
|
{
|
||||||
const uint32_t channel = active_channel();
|
const uint32_t channel = active_channel();
|
||||||
write_reg(INTERRUPT_BASE + IRQ_MASK_W1S_OFFSET, video_irq_mask_bit());
|
const uint32_t irqBit = video_irq_mask_bit();
|
||||||
|
const bool irqMaskWriteOk = write_reg(INTERRUPT_BASE + IRQ_MASK_W1S_OFFSET, irqBit);
|
||||||
|
uint32_t irqMaskReadback = 0;
|
||||||
|
const bool irqMaskReadOk = read_reg(INTERRUPT_BASE + IRQ_MASK_STATUS_OFFSET, irqMaskReadback);
|
||||||
|
PCIES2MM_LOG("capture wait start: irq_bit=0x%08X mask_write=%d mask_read=%s0x%08X",
|
||||||
|
irqBit,
|
||||||
|
irqMaskWriteOk ? 1 : 0,
|
||||||
|
irqMaskReadOk ? "" : "FAILED/",
|
||||||
|
irqMaskReadback);
|
||||||
HANDLE waitHandles[] = {
|
HANDLE waitHandles[] = {
|
||||||
dma_event_,
|
dma_event_,
|
||||||
format_change_event_,
|
format_change_event_,
|
||||||
@@ -732,6 +752,7 @@ namespace gvfg::internal
|
|||||||
plug_out_event_,
|
plug_out_event_,
|
||||||
};
|
};
|
||||||
constexpr DWORD waitHandleCount = 4;
|
constexpr DWORD waitHandleCount = 4;
|
||||||
|
uint64_t diagnosticTimeouts = 0;
|
||||||
|
|
||||||
while (running_)
|
while (running_)
|
||||||
{
|
{
|
||||||
@@ -743,6 +764,37 @@ namespace gvfg::internal
|
|||||||
break;
|
break;
|
||||||
if (waitResult == WAIT_TIMEOUT)
|
if (waitResult == WAIT_TIMEOUT)
|
||||||
{
|
{
|
||||||
|
++diagnosticTimeouts;
|
||||||
|
if (diagnosticTimeouts <= 5 || (diagnosticTimeouts % 10) == 0)
|
||||||
|
{
|
||||||
|
uint32_t videoEnable = 0;
|
||||||
|
uint32_t dmaEnable = 0;
|
||||||
|
uint32_t videoIrqStatus = 0;
|
||||||
|
uint32_t dmaIrqStatus = 0;
|
||||||
|
uint32_t irqPending = 0;
|
||||||
|
uint32_t irqMasked = 0;
|
||||||
|
uint32_t irqMask = 0;
|
||||||
|
const bool registersOk =
|
||||||
|
read_reg(video_base() + VIDEO_EN_OFFSET, videoEnable) &&
|
||||||
|
read_reg(video_base() + VIDEO_DMA_EN_OFFSET, dmaEnable) &&
|
||||||
|
read_reg(video_base() + VIDEO_IRQ_STATUS_OFFSET, videoIrqStatus) &&
|
||||||
|
read_reg(video_base() + VIDEO_DMA_IRQ_STATUS_OFFSET, dmaIrqStatus) &&
|
||||||
|
read_reg(INTERRUPT_BASE + IRQ_PENDING_STATUS_OFFSET, irqPending) &&
|
||||||
|
read_reg(INTERRUPT_BASE + IRQ_MASKED_STATUS_OFFSET, irqMasked) &&
|
||||||
|
read_reg(INTERRUPT_BASE + IRQ_MASK_STATUS_OFFSET, irqMask);
|
||||||
|
PCIES2MM_LOG("wait timeout #%llu: regs_ok=%d capture=%d probe=%d video_en=0x%08X dma_en=0x%08X video_irq=0x%08X dma_irq=0x%08X irq_pending=0x%08X irq_masked=0x%08X irq_mask=0x%08X",
|
||||||
|
static_cast<unsigned long long>(diagnosticTimeouts),
|
||||||
|
registersOk ? 1 : 0,
|
||||||
|
capture_active_.load(std::memory_order_acquire) ? 1 : 0,
|
||||||
|
signal_probe_active_.load(std::memory_order_acquire) ? 1 : 0,
|
||||||
|
videoEnable,
|
||||||
|
dmaEnable,
|
||||||
|
videoIrqStatus,
|
||||||
|
dmaIrqStatus,
|
||||||
|
irqPending,
|
||||||
|
irqMasked,
|
||||||
|
irqMask);
|
||||||
|
}
|
||||||
if (!signal_presence_known_.load(std::memory_order_acquire) &&
|
if (!signal_presence_known_.load(std::memory_order_acquire) &&
|
||||||
!capture_active_.load(std::memory_order_acquire) &&
|
!capture_active_.load(std::memory_order_acquire) &&
|
||||||
refresh_stream_from_registers(true))
|
refresh_stream_from_registers(true))
|
||||||
@@ -778,15 +830,19 @@ namespace gvfg::internal
|
|||||||
switch (waitResult - WAIT_OBJECT_0)
|
switch (waitResult - WAIT_OBJECT_0)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
PCIES2MM_LOG("event: DMA");
|
||||||
handle_dma_event(channel);
|
handle_dma_event(channel);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
PCIES2MM_LOG("event: FORMAT_CHANGE");
|
||||||
handle_format_change_event(channel);
|
handle_format_change_event(channel);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
PCIES2MM_LOG("event: PLUG_IN");
|
||||||
handle_plugin_event(channel);
|
handle_plugin_event(channel);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
PCIES2MM_LOG("event: PLUG_OUT");
|
||||||
handle_unplug_event(channel);
|
handle_unplug_event(channel);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -805,9 +861,13 @@ namespace gvfg::internal
|
|||||||
uint32_t doneIndex = 0;
|
uint32_t doneIndex = 0;
|
||||||
if (!get_video_done_index(channel, doneIndex))
|
if (!get_video_done_index(channel, doneIndex))
|
||||||
{
|
{
|
||||||
|
const DWORD err = GetLastError();
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
++stats_.dma_errors;
|
++stats_.dma_errors;
|
||||||
frame_cv_.notify_all();
|
frame_cv_.notify_all();
|
||||||
|
PCIES2MM_ERROR_LOG("get_video_done_index failed channel=%u win32=%lu",
|
||||||
|
channel,
|
||||||
|
static_cast<unsigned long>(err));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1006,6 +1066,38 @@ namespace gvfg::internal
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
const pcies2mm_pixel_format_t pixelFormat = decode_pixel_format(rawFormat);
|
const pcies2mm_pixel_format_t pixelFormat = decode_pixel_format(rawFormat);
|
||||||
|
const char fourccLe[5] = {
|
||||||
|
static_cast<char>(rawFormat & 0xffu),
|
||||||
|
static_cast<char>((rawFormat >> 8) & 0xffu),
|
||||||
|
static_cast<char>((rawFormat >> 16) & 0xffu),
|
||||||
|
static_cast<char>((rawFormat >> 24) & 0xffu),
|
||||||
|
'\0'};
|
||||||
|
const char *decodedFormat = "UNKNOWN";
|
||||||
|
switch (pixelFormat)
|
||||||
|
{
|
||||||
|
case PCIES2MM_PIXFMT_YVYU:
|
||||||
|
decodedFormat = "YVYU";
|
||||||
|
break;
|
||||||
|
case PCIES2MM_PIXFMT_Y210:
|
||||||
|
decodedFormat = "Y210";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PCIES2MM_LOG("stream registers: width=%u height=%u VIDEO_FORMAT=0x%08X register_text='%c%c%c%c' fourcc_le='%c%c%c%c' decoded=%s frame_bytes=%zu",
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
rawFormat,
|
||||||
|
static_cast<char>((rawFormat >> 24) & 0xffu),
|
||||||
|
static_cast<char>((rawFormat >> 16) & 0xffu),
|
||||||
|
static_cast<char>((rawFormat >> 8) & 0xffu),
|
||||||
|
static_cast<char>(rawFormat & 0xffu),
|
||||||
|
fourccLe[0],
|
||||||
|
fourccLe[1],
|
||||||
|
fourccLe[2],
|
||||||
|
fourccLe[3],
|
||||||
|
decodedFormat,
|
||||||
|
bytes_per_frame(width, height, pixelFormat));
|
||||||
if (pixelFormat == PCIES2MM_PIXFMT_UNKNOWN)
|
if (pixelFormat == PCIES2MM_PIXFMT_UNKNOWN)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,10 @@
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// This board revision can report v210 even though its DMA payload is Y210
|
// This board revision can report v210 even though its DMA payload is Y210
|
||||||
// (16-bit containers with 10 valid bits). Legacy register value 0 has the
|
// (16-bit containers with 10 valid bits).
|
||||||
// same Y210 payload.
|
constexpr uint32_t kRegisterDisplayYvyu = 0x59565955u;
|
||||||
constexpr uint32_t kLegacyY210Format = 0;
|
constexpr uint32_t kRegisterDisplayV210 = 0x76323130u;
|
||||||
constexpr uint32_t kFpgaFourccYuy2 = 0x59555932u;
|
constexpr uint32_t kRegisterDisplayY210 = 0x59323130u;
|
||||||
constexpr uint32_t kFpgaFourccV210 = 0x76323130u;
|
|
||||||
constexpr uint32_t kFpgaFourccY210 = 0x59323130u;
|
|
||||||
|
|
||||||
constexpr uint32_t fourcc(char a, char b, char c, char d)
|
constexpr uint32_t fourcc(char a, char b, char c, char d)
|
||||||
{
|
{
|
||||||
@@ -23,19 +21,18 @@ namespace gvfg::internal
|
|||||||
{
|
{
|
||||||
pcies2mm_pixel_format_t decode_pixel_format(uint32_t registerValue)
|
pcies2mm_pixel_format_t decode_pixel_format(uint32_t registerValue)
|
||||||
{
|
{
|
||||||
if (registerValue == kLegacyY210Format)
|
// Current firmware writes character codes in display order. Normalize
|
||||||
return PCIES2MM_PIXFMT_Y210;
|
// those values here so no register naming leaks into the SDK formats.
|
||||||
|
if (registerValue == kRegisterDisplayYvyu)
|
||||||
// CaptureDemo compares these display-order FPGA register values.
|
return PCIES2MM_PIXFMT_YVYU;
|
||||||
if (registerValue == kFpgaFourccYuy2)
|
if (registerValue == kRegisterDisplayV210 || registerValue == kRegisterDisplayY210)
|
||||||
return PCIES2MM_PIXFMT_YUY2;
|
|
||||||
if (registerValue == kFpgaFourccV210 || registerValue == kFpgaFourccY210)
|
|
||||||
return PCIES2MM_PIXFMT_Y210;
|
return PCIES2MM_PIXFMT_Y210;
|
||||||
|
|
||||||
|
// Also accept corrected Windows FOURCC values from future firmware.
|
||||||
switch (registerValue)
|
switch (registerValue)
|
||||||
{
|
{
|
||||||
case fourcc('Y', 'U', 'Y', '2'):
|
case fourcc('Y', 'V', 'Y', 'U'):
|
||||||
return PCIES2MM_PIXFMT_YUY2;
|
return PCIES2MM_PIXFMT_YVYU;
|
||||||
case fourcc('v', '2', '1', '0'):
|
case fourcc('v', '2', '1', '0'):
|
||||||
case fourcc('Y', '2', '1', '0'):
|
case fourcc('Y', '2', '1', '0'):
|
||||||
return PCIES2MM_PIXFMT_Y210;
|
return PCIES2MM_PIXFMT_Y210;
|
||||||
@@ -46,7 +43,7 @@ namespace gvfg::internal
|
|||||||
|
|
||||||
uint32_t bit_depth_for_pixfmt(pcies2mm_pixel_format_t format)
|
uint32_t bit_depth_for_pixfmt(pcies2mm_pixel_format_t format)
|
||||||
{
|
{
|
||||||
if (format == PCIES2MM_PIXFMT_YUY2)
|
if (format == PCIES2MM_PIXFMT_YVYU)
|
||||||
return 8;
|
return 8;
|
||||||
if (format == PCIES2MM_PIXFMT_Y210)
|
if (format == PCIES2MM_PIXFMT_Y210)
|
||||||
return 10;
|
return 10;
|
||||||
@@ -56,7 +53,7 @@ namespace gvfg::internal
|
|||||||
size_t bytes_per_frame(uint32_t width, uint32_t height, pcies2mm_pixel_format_t format)
|
size_t bytes_per_frame(uint32_t width, uint32_t height, pcies2mm_pixel_format_t format)
|
||||||
{
|
{
|
||||||
const size_t pixels = static_cast<size_t>(width) * static_cast<size_t>(height);
|
const size_t pixels = static_cast<size_t>(width) * static_cast<size_t>(height);
|
||||||
if (format == PCIES2MM_PIXFMT_YUY2)
|
if (format == PCIES2MM_PIXFMT_YVYU)
|
||||||
return pixels * 2u;
|
return pixels * 2u;
|
||||||
if (format == PCIES2MM_PIXFMT_Y210)
|
if (format == PCIES2MM_PIXFMT_Y210)
|
||||||
return pixels * 4u;
|
return pixels * 4u;
|
||||||
|
|||||||
+136
-9
@@ -1,4 +1,4 @@
|
|||||||
#include "d3d_preview_pipeline.h"
|
#include "d3d_conversion_pipeline.h"
|
||||||
|
|
||||||
#ifndef NOMINMAX
|
#ifndef NOMINMAX
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
@@ -51,12 +51,12 @@ VSOut main(VSIn i){
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
// YUY2 4:2:2 packed input.
|
// YVYU 4:2:2 packed input.
|
||||||
// Each upload texture texel stores two pixels as R=Y0, G=U, B=Y1, A=V.
|
// Each upload texture texel stores two pixels as R=Y0, G=U, B=Y1, A=V.
|
||||||
// R=Y0, G=U, B=Y1, A=V
|
// R=Y0, G=U, B=Y1, A=V
|
||||||
// texture width = ceil(w/2)
|
// texture width = ceil(w/2)
|
||||||
static const char *g_ps_yuy2 = R"(
|
static const char *g_ps_yuy2 = R"(
|
||||||
// YUY2 (4:2:2 packed):
|
// YVYU (4:2:2 packed):
|
||||||
// Each texel packs 2 pixels: R=Y0, G=U, B=Y1, A=V
|
// Each texel packs 2 pixels: R=Y0, G=U, B=Y1, A=V
|
||||||
// texture width = ceil(w/2)
|
// texture width = ceil(w/2)
|
||||||
Texture2D<uint4> texP : register(t0);
|
Texture2D<uint4> texP : register(t0);
|
||||||
@@ -132,8 +132,8 @@ float2 loadUV01(int x, int y)
|
|||||||
x = clamp(x, 0, (int)width - 1);
|
x = clamp(x, 0, (int)width - 1);
|
||||||
y = clamp(y, 0, (int)height - 1);
|
y = clamp(y, 0, (int)height - 1);
|
||||||
uint4 p = texP.Load(int3(x >> 1, y, 0));
|
uint4 p = texP.Load(int3(x >> 1, y, 0));
|
||||||
float u = (float)p.g / 255.0;
|
float u = (float)p.a / 255.0;
|
||||||
float v = (float)p.a / 255.0;
|
float v = (float)p.g / 255.0;
|
||||||
return float2(u, v);
|
return float2(u, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,7 +469,8 @@ bool D3DPreviewPipeline::ensure_rt_and_pipeline(int w, int h)
|
|||||||
{
|
{
|
||||||
const bool hasAllTargets = rt_fp16_ && rtv_fp16_ && srv_fp16_ &&
|
const bool hasAllTargets = rt_fp16_ && rtv_fp16_ && srv_fp16_ &&
|
||||||
rt_scene_fp16_ && rtv_scene_fp16_ && srv_scene_fp16_ &&
|
rt_scene_fp16_ && rtv_scene_fp16_ && srv_scene_fp16_ &&
|
||||||
rt_rgba_ && rtv_rgba_ && srv_rgba_;
|
rt_rgba_ && rtv_rgba_ && srv_rgba_ &&
|
||||||
|
rt_rgb10_ && rtv_rgb10_;
|
||||||
|
|
||||||
if (hasAllTargets && rt_w_ == w && rt_h_ == h)
|
if (hasAllTargets && rt_w_ == w && rt_h_ == h)
|
||||||
return true;
|
return true;
|
||||||
@@ -483,6 +484,10 @@ bool D3DPreviewPipeline::ensure_rt_and_pipeline(int w, int h)
|
|||||||
rt_rgba_.Reset();
|
rt_rgba_.Reset();
|
||||||
rtv_rgba_.Reset();
|
rtv_rgba_.Reset();
|
||||||
srv_rgba_.Reset();
|
srv_rgba_.Reset();
|
||||||
|
rt_rgb10_.Reset();
|
||||||
|
rtv_rgb10_.Reset();
|
||||||
|
readback_bgra8_.Reset();
|
||||||
|
readback_rgb10_.Reset();
|
||||||
|
|
||||||
// 1) High precision intermediate target
|
// 1) High precision intermediate target
|
||||||
D3D11_TEXTURE2D_DESC td{};
|
D3D11_TEXTURE2D_DESC td{};
|
||||||
@@ -524,6 +529,14 @@ bool D3DPreviewPipeline::ensure_rt_and_pipeline(int w, int h)
|
|||||||
if (FAILED(d3d_->CreateShaderResourceView(rt_rgba_.Get(), nullptr, &srv_rgba_)))
|
if (FAILED(d3d_->CreateShaderResourceView(rt_rgba_.Get(), nullptr, &srv_rgba_)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// 4) Packed 10:10:10:2 RGB target used by the public 10-bit buffer API.
|
||||||
|
td.Format = DXGI_FORMAT_R10G10B10A2_UNORM;
|
||||||
|
td.BindFlags = D3D11_BIND_RENDER_TARGET;
|
||||||
|
if (FAILED(d3d_->CreateTexture2D(&td, nullptr, &rt_rgb10_)))
|
||||||
|
return false;
|
||||||
|
if (FAILED(d3d_->CreateRenderTargetView(rt_rgb10_.Get(), nullptr, &rtv_rgb10_)))
|
||||||
|
return false;
|
||||||
|
|
||||||
const bool ok = create_shaders_and_states();
|
const bool ok = create_shaders_and_states();
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
@@ -576,7 +589,120 @@ bool D3DPreviewPipeline::blit_fp16_to_rgba8(int frame_w, int frame_h)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool D3DPreviewPipeline::upload_yuy2_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h)
|
bool D3DPreviewPipeline::blit_fp16_to_rgb10a2(int frame_w, int frame_h)
|
||||||
|
{
|
||||||
|
if (!rtv_rgb10_ || !srv_scene_fp16_ || !vs_ || !ps_fp16_to_rgba8_ || !ctx_)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
UINT stride = sizeof(float) * 4, offset = 0;
|
||||||
|
ID3D11Buffer *pVB = vb_.Get();
|
||||||
|
ctx_->IASetVertexBuffers(0, 1, &pVB, &stride, &offset);
|
||||||
|
ctx_->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||||
|
ctx_->IASetInputLayout(il_.Get());
|
||||||
|
|
||||||
|
ID3D11RenderTargetView *rtv = rtv_rgb10_.Get();
|
||||||
|
ctx_->OMSetRenderTargets(1, &rtv, nullptr);
|
||||||
|
|
||||||
|
D3D11_VIEWPORT vp{};
|
||||||
|
vp.Width = static_cast<FLOAT>(frame_w);
|
||||||
|
vp.Height = static_cast<FLOAT>(frame_h);
|
||||||
|
vp.MinDepth = 0.0f;
|
||||||
|
vp.MaxDepth = 1.0f;
|
||||||
|
ctx_->RSSetViewports(1, &vp);
|
||||||
|
|
||||||
|
const float clear[4] = {0, 0, 0, 1};
|
||||||
|
ctx_->ClearRenderTargetView(rtv_rgb10_.Get(), clear);
|
||||||
|
ctx_->VSSetShader(vs_.Get(), nullptr, 0);
|
||||||
|
ctx_->PSSetShader(ps_fp16_to_rgba8_.Get(), nullptr, 0);
|
||||||
|
|
||||||
|
ID3D11ShaderResourceView *srvs[1] = {srv_scene_fp16_.Get()};
|
||||||
|
ctx_->PSSetShaderResources(0, 1, srvs);
|
||||||
|
ID3D11SamplerState *ss = samp_.Get();
|
||||||
|
ctx_->PSSetSamplers(0, 1, &ss);
|
||||||
|
ctx_->Draw(6, 0);
|
||||||
|
|
||||||
|
ID3D11ShaderResourceView *nullSrv[1] = {nullptr};
|
||||||
|
ctx_->PSSetShaderResources(0, 1, nullSrv);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool D3DPreviewPipeline::readback_to_buffer(void *destination,
|
||||||
|
uint64_t destination_size,
|
||||||
|
int destination_row_bytes,
|
||||||
|
DXGI_FORMAT destination_format,
|
||||||
|
int frame_w,
|
||||||
|
int frame_h)
|
||||||
|
{
|
||||||
|
if (!d3d_ || !ctx_ || !destination || frame_w <= 0 || frame_h <= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ID3D11Texture2D *source = nullptr;
|
||||||
|
ComPtr<ID3D11Texture2D> *staging = nullptr;
|
||||||
|
if (destination_format == DXGI_FORMAT_B8G8R8A8_UNORM)
|
||||||
|
{
|
||||||
|
source = rt_rgba_.Get();
|
||||||
|
staging = &readback_bgra8_;
|
||||||
|
}
|
||||||
|
else if (destination_format == DXGI_FORMAT_R10G10B10A2_UNORM)
|
||||||
|
{
|
||||||
|
source = rt_rgb10_.Get();
|
||||||
|
staging = &readback_rgb10_;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint64_t minimumRowBytes = static_cast<uint64_t>(frame_w) * 4u;
|
||||||
|
if (!source || destination_row_bytes < minimumRowBytes ||
|
||||||
|
destination_size < static_cast<uint64_t>(destination_row_bytes) * static_cast<uint64_t>(frame_h))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool recreate = !*staging;
|
||||||
|
if (*staging)
|
||||||
|
{
|
||||||
|
D3D11_TEXTURE2D_DESC existing{};
|
||||||
|
(*staging)->GetDesc(&existing);
|
||||||
|
recreate = existing.Width != static_cast<UINT>(frame_w) ||
|
||||||
|
existing.Height != static_cast<UINT>(frame_h) ||
|
||||||
|
existing.Format != destination_format;
|
||||||
|
}
|
||||||
|
if (recreate)
|
||||||
|
{
|
||||||
|
staging->Reset();
|
||||||
|
D3D11_TEXTURE2D_DESC desc{};
|
||||||
|
desc.Width = static_cast<UINT>(frame_w);
|
||||||
|
desc.Height = static_cast<UINT>(frame_h);
|
||||||
|
desc.MipLevels = 1;
|
||||||
|
desc.ArraySize = 1;
|
||||||
|
desc.Format = destination_format;
|
||||||
|
desc.SampleDesc.Count = 1;
|
||||||
|
desc.Usage = D3D11_USAGE_STAGING;
|
||||||
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||||
|
if (FAILED(d3d_->CreateTexture2D(&desc, nullptr, staging->ReleaseAndGetAddressOf())))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx_->CopyResource(staging->Get(), source);
|
||||||
|
D3D11_MAPPED_SUBRESOURCE mapped{};
|
||||||
|
if (FAILED(ctx_->Map(staging->Get(), 0, D3D11_MAP_READ, 0, &mapped)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto *dst = static_cast<uint8_t *>(destination);
|
||||||
|
const size_t copyBytes = static_cast<size_t>(minimumRowBytes);
|
||||||
|
for (int row = 0; row < frame_h; ++row)
|
||||||
|
{
|
||||||
|
const auto *srcRow = static_cast<const uint8_t *>(mapped.pData) +
|
||||||
|
static_cast<size_t>(row) * mapped.RowPitch;
|
||||||
|
std::memcpy(dst + static_cast<size_t>(row) * static_cast<size_t>(destination_row_bytes),
|
||||||
|
srcRow,
|
||||||
|
copyBytes);
|
||||||
|
}
|
||||||
|
ctx_->Unmap(staging->Get(), 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool D3DPreviewPipeline::upload_packed_422_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h)
|
||||||
{
|
{
|
||||||
if (!d3d_ || !ctx_ || !data || frame_w <= 0 || frame_h <= 0 || src_stride <= 0)
|
if (!d3d_ || !ctx_ || !data || frame_w <= 0 || frame_h <= 0 || src_stride <= 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -604,7 +730,7 @@ bool D3DPreviewPipeline::upload_yuy2_frame(const uint8_t *data, int src_stride,
|
|||||||
if ((int)td.Width != w2 || (int)td.Height != frame_h || td.Format != DXGI_FORMAT_R8G8B8A8_UINT)
|
if ((int)td.Width != w2 || (int)td.Height != frame_h || td.Format != DXGI_FORMAT_R8G8B8A8_UINT)
|
||||||
{
|
{
|
||||||
upload_yuy2_packed_.Reset();
|
upload_yuy2_packed_.Reset();
|
||||||
return upload_yuy2_frame(data, src_stride, frame_w, frame_h);
|
return upload_packed_422_frame(data, src_stride, frame_w, frame_h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,7 +813,7 @@ bool D3DPreviewPipeline::render_uploaded_yuv_to_fp16(gvfg_render_pixfmt_t fmt, i
|
|||||||
|
|
||||||
ID3D11PixelShader *ps = nullptr;
|
ID3D11PixelShader *ps = nullptr;
|
||||||
ComPtr<ID3D11ShaderResourceView> srv0;
|
ComPtr<ID3D11ShaderResourceView> srv0;
|
||||||
if (fmt == GVFG_RENDER_FMT_YUY2)
|
if (fmt == GVFG_RENDER_FMT_YVYU)
|
||||||
{
|
{
|
||||||
if (!upload_yuy2_packed_)
|
if (!upload_yuy2_packed_)
|
||||||
return false;
|
return false;
|
||||||
@@ -745,6 +871,7 @@ bool D3DPreviewPipeline::render_uploaded_yuv_to_fp16(gvfg_render_pixfmt_t fmt, i
|
|||||||
cb.hueSin = 0.0f;
|
cb.hueSin = 0.0f;
|
||||||
cb.hueCos = 1.0f;
|
cb.hueCos = 1.0f;
|
||||||
cb.sharpAmount = 0.0f;
|
cb.sharpAmount = 0.0f;
|
||||||
|
cb.pad0 = 0.0f;
|
||||||
|
|
||||||
if (cs_params_)
|
if (cs_params_)
|
||||||
{
|
{
|
||||||
+14
-3
@@ -10,8 +10,8 @@ namespace gvfg::internal
|
|||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
GVFG_RENDER_FMT_YUY2,
|
GVFG_RENDER_FMT_Y210,
|
||||||
GVFG_RENDER_FMT_Y210
|
GVFG_RENDER_FMT_YVYU
|
||||||
} gvfg_render_pixfmt_t;
|
} gvfg_render_pixfmt_t;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
@@ -57,10 +57,17 @@ public:
|
|||||||
DXGI_FORMAT scene_texture_format() const;
|
DXGI_FORMAT scene_texture_format() const;
|
||||||
DXGI_FORMAT linear_fp16_texture_format() const;
|
DXGI_FORMAT linear_fp16_texture_format() const;
|
||||||
bool blit_fp16_to_rgba8(int frame_w, int frame_h);
|
bool blit_fp16_to_rgba8(int frame_w, int frame_h);
|
||||||
bool upload_yuy2_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h);
|
bool blit_fp16_to_rgb10a2(int frame_w, int frame_h);
|
||||||
|
bool upload_packed_422_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h);
|
||||||
bool upload_y210_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h);
|
bool upload_y210_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h);
|
||||||
bool render_uploaded_yuv_to_fp16(gvfg_render_pixfmt_t fmt, int frame_w, int frame_h);
|
bool render_uploaded_yuv_to_fp16(gvfg_render_pixfmt_t fmt, int frame_w, int frame_h);
|
||||||
bool copy_fp16_to_scene();
|
bool copy_fp16_to_scene();
|
||||||
|
bool readback_to_buffer(void *destination,
|
||||||
|
uint64_t destination_size,
|
||||||
|
int destination_row_bytes,
|
||||||
|
DXGI_FORMAT destination_format,
|
||||||
|
int frame_w,
|
||||||
|
int frame_h);
|
||||||
|
|
||||||
ID3D11Device *d3d_ = nullptr;
|
ID3D11Device *d3d_ = nullptr;
|
||||||
ID3D11DeviceContext *ctx_ = nullptr;
|
ID3D11DeviceContext *ctx_ = nullptr;
|
||||||
@@ -77,6 +84,10 @@ public:
|
|||||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_rgba8_to_preview_;
|
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_rgba8_to_preview_;
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_rgba_;
|
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_rgba_;
|
||||||
|
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_rgb10_;
|
||||||
|
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv_rgb10_;
|
||||||
|
Microsoft::WRL::ComPtr<ID3D11Texture2D> readback_bgra8_;
|
||||||
|
Microsoft::WRL::ComPtr<ID3D11Texture2D> readback_rgb10_;
|
||||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> upload_yuy2_packed_;
|
Microsoft::WRL::ComPtr<ID3D11Texture2D> upload_yuy2_packed_;
|
||||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> upload_y210_packed_;
|
Microsoft::WRL::ComPtr<ID3D11Texture2D> upload_y210_packed_;
|
||||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv_rgba_;
|
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv_rgba_;
|
||||||
@@ -0,0 +1,214 @@
|
|||||||
|
#include "gvfg_capture.h"
|
||||||
|
|
||||||
|
#include "d3d_conversion_pipeline.h"
|
||||||
|
|
||||||
|
#include <d3d11_4.h>
|
||||||
|
#include <dxgi.h>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <iterator>
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
#include <wrl/client.h>
|
||||||
|
|
||||||
|
using Microsoft::WRL::ComPtr;
|
||||||
|
|
||||||
|
#if INTPTR_MAX == INT64_MAX
|
||||||
|
static_assert(sizeof(gvfg_gpu_output_buffer_t) == 24,
|
||||||
|
"gvfg_gpu_output_buffer_t x64 ABI must remain frozen");
|
||||||
|
static_assert(offsetof(gvfg_gpu_output_buffer_t, data) == 0);
|
||||||
|
static_assert(offsetof(gvfg_gpu_output_buffer_t, data_size) == 8);
|
||||||
|
static_assert(offsetof(gvfg_gpu_output_buffer_t, row_bytes) == 16);
|
||||||
|
static_assert(offsetof(gvfg_gpu_output_buffer_t, pixel_format) == 20);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class GpuBufferConverter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
gvfg_status_t convert(const gvfg_frame_t &source,
|
||||||
|
const gvfg_gpu_output_buffer_t &output)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
if (!ensureDevice())
|
||||||
|
return GVFG_EIO;
|
||||||
|
|
||||||
|
if (!pipeline_)
|
||||||
|
pipeline_ = std::make_unique<gvfg::internal::D3DPreviewPipeline>();
|
||||||
|
if (!pipeline_->initialize(device_.Get(), context_.Get()) ||
|
||||||
|
!pipeline_->ensure_rt_and_pipeline(source.width, source.height))
|
||||||
|
return GVFG_EIO;
|
||||||
|
|
||||||
|
gvfg::internal::gvfg_render_pixfmt_t renderFormat{};
|
||||||
|
bool uploaded = false;
|
||||||
|
const auto *data = static_cast<const uint8_t *>(source.data);
|
||||||
|
switch (source.pixel_format)
|
||||||
|
{
|
||||||
|
case GVFG_PIXFMT_YVYU:
|
||||||
|
renderFormat = gvfg::internal::GVFG_RENDER_FMT_YVYU;
|
||||||
|
uploaded = pipeline_->upload_packed_422_frame(data,
|
||||||
|
source.row_stride_bytes,
|
||||||
|
source.width,
|
||||||
|
source.height);
|
||||||
|
break;
|
||||||
|
case GVFG_PIXFMT_Y210:
|
||||||
|
renderFormat = gvfg::internal::GVFG_RENDER_FMT_Y210;
|
||||||
|
uploaded = pipeline_->upload_y210_frame(data,
|
||||||
|
source.row_stride_bytes,
|
||||||
|
source.width,
|
||||||
|
source.height);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return GVFG_ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!uploaded ||
|
||||||
|
!pipeline_->render_uploaded_yuv_to_fp16(renderFormat, source.width, source.height) ||
|
||||||
|
!pipeline_->copy_fp16_to_scene())
|
||||||
|
return GVFG_EIO;
|
||||||
|
|
||||||
|
DXGI_FORMAT outputFormat = DXGI_FORMAT_UNKNOWN;
|
||||||
|
bool rendered = false;
|
||||||
|
switch (output.pixel_format)
|
||||||
|
{
|
||||||
|
case GVFG_GPU_OUTPUT_BGRA8:
|
||||||
|
outputFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||||
|
rendered = pipeline_->blit_fp16_to_rgba8(source.width, source.height);
|
||||||
|
break;
|
||||||
|
case GVFG_GPU_OUTPUT_RGB10A2:
|
||||||
|
outputFormat = DXGI_FORMAT_R10G10B10A2_UNORM;
|
||||||
|
rendered = pipeline_->blit_fp16_to_rgb10a2(source.width, source.height);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return GVFG_ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rendered ||
|
||||||
|
!pipeline_->readback_to_buffer(output.data,
|
||||||
|
output.data_size,
|
||||||
|
output.row_bytes,
|
||||||
|
outputFormat,
|
||||||
|
source.width,
|
||||||
|
source.height))
|
||||||
|
return GVFG_EIO;
|
||||||
|
return GVFG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool ensureDevice()
|
||||||
|
{
|
||||||
|
if (device_ && context_)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
|
||||||
|
#ifdef _DEBUG
|
||||||
|
flags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||||
|
#endif
|
||||||
|
const D3D_FEATURE_LEVEL levels[] = {
|
||||||
|
D3D_FEATURE_LEVEL_11_1,
|
||||||
|
D3D_FEATURE_LEVEL_11_0,
|
||||||
|
};
|
||||||
|
D3D_FEATURE_LEVEL actual{};
|
||||||
|
HRESULT hr = D3D11CreateDevice(nullptr,
|
||||||
|
D3D_DRIVER_TYPE_HARDWARE,
|
||||||
|
nullptr,
|
||||||
|
flags,
|
||||||
|
levels,
|
||||||
|
static_cast<UINT>(std::size(levels)),
|
||||||
|
D3D11_SDK_VERSION,
|
||||||
|
&device_,
|
||||||
|
&actual,
|
||||||
|
&context_);
|
||||||
|
#ifdef _DEBUG
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
flags &= ~D3D11_CREATE_DEVICE_DEBUG;
|
||||||
|
hr = D3D11CreateDevice(nullptr,
|
||||||
|
D3D_DRIVER_TYPE_HARDWARE,
|
||||||
|
nullptr,
|
||||||
|
flags,
|
||||||
|
levels,
|
||||||
|
static_cast<UINT>(std::size(levels)),
|
||||||
|
D3D11_SDK_VERSION,
|
||||||
|
&device_,
|
||||||
|
&actual,
|
||||||
|
&context_);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (FAILED(hr) || !device_ || !context_)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ComPtr<ID3D11Multithread> multithread;
|
||||||
|
if (SUCCEEDED(device_.As(&multithread)) && multithread)
|
||||||
|
multithread->SetMultithreadProtected(TRUE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::mutex mutex_;
|
||||||
|
ComPtr<ID3D11Device> device_;
|
||||||
|
ComPtr<ID3D11DeviceContext> context_;
|
||||||
|
std::unique_ptr<gvfg::internal::D3DPreviewPipeline> pipeline_;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool checkedFrameLayout(const gvfg_frame_t &source)
|
||||||
|
{
|
||||||
|
if (!source.data || source.width <= 0 || source.height <= 0 ||
|
||||||
|
source.row_stride_bytes <= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
uint64_t minimumRowBytes = 0;
|
||||||
|
switch (source.pixel_format)
|
||||||
|
{
|
||||||
|
case GVFG_PIXFMT_YVYU:
|
||||||
|
minimumRowBytes = static_cast<uint64_t>(source.width) * 2u;
|
||||||
|
break;
|
||||||
|
case GVFG_PIXFMT_Y210:
|
||||||
|
minimumRowBytes = static_cast<uint64_t>(source.width) * 4u;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (static_cast<uint64_t>(source.row_stride_bytes) < minimumRowBytes)
|
||||||
|
return false;
|
||||||
|
const uint64_t rowOffset = static_cast<uint64_t>(source.row_stride_bytes) *
|
||||||
|
static_cast<uint64_t>(source.height - 1);
|
||||||
|
return rowOffset <= UINT64_MAX - minimumRowBytes &&
|
||||||
|
source.data_size >= rowOffset + minimumRowBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
GpuBufferConverter &sharedConverter()
|
||||||
|
{
|
||||||
|
static GpuBufferConverter converter;
|
||||||
|
return converter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" GVFG_API gvfg_status_t gvfg_gpu_convert_to_buffer(
|
||||||
|
const gvfg_frame_t *source,
|
||||||
|
const gvfg_gpu_output_buffer_t *output)
|
||||||
|
{
|
||||||
|
if (!source || !output || !output->data ||
|
||||||
|
source->width <= 0 || source->height <= 0 ||
|
||||||
|
output->row_bytes <= 0)
|
||||||
|
return GVFG_EINVAL;
|
||||||
|
|
||||||
|
if (source->pixel_format != GVFG_PIXFMT_YVYU &&
|
||||||
|
source->pixel_format != GVFG_PIXFMT_Y210)
|
||||||
|
return GVFG_ENOTSUP;
|
||||||
|
if (output->pixel_format != GVFG_GPU_OUTPUT_BGRA8 &&
|
||||||
|
output->pixel_format != GVFG_GPU_OUTPUT_RGB10A2)
|
||||||
|
return GVFG_ENOTSUP;
|
||||||
|
if (!checkedFrameLayout(*source))
|
||||||
|
return GVFG_EINVAL;
|
||||||
|
|
||||||
|
const uint64_t minimumRowBytes = static_cast<uint64_t>(source->width) * 4u;
|
||||||
|
if (static_cast<uint64_t>(output->row_bytes) < minimumRowBytes)
|
||||||
|
return GVFG_EINVAL;
|
||||||
|
const uint64_t requiredSize = static_cast<uint64_t>(output->row_bytes) *
|
||||||
|
static_cast<uint64_t>(source->height);
|
||||||
|
if (output->data_size < requiredSize)
|
||||||
|
return GVFG_EINVAL;
|
||||||
|
|
||||||
|
return sharedConverter().convert(*source, *output);
|
||||||
|
}
|
||||||
@@ -135,8 +135,8 @@ namespace
|
|||||||
{
|
{
|
||||||
switch (fmt)
|
switch (fmt)
|
||||||
{
|
{
|
||||||
case PCIES2MM_PIXFMT_YUY2:
|
case PCIES2MM_PIXFMT_YVYU:
|
||||||
return GVFG_PIXFMT_YUY2;
|
return GVFG_PIXFMT_YVYU;
|
||||||
case PCIES2MM_PIXFMT_Y210:
|
case PCIES2MM_PIXFMT_Y210:
|
||||||
return GVFG_PIXFMT_Y210;
|
return GVFG_PIXFMT_Y210;
|
||||||
default:
|
default:
|
||||||
@@ -148,8 +148,8 @@ namespace
|
|||||||
{
|
{
|
||||||
switch (fmt)
|
switch (fmt)
|
||||||
{
|
{
|
||||||
case GVFG_PIXFMT_YUY2:
|
case GVFG_PIXFMT_YVYU:
|
||||||
return "YUY2";
|
return "YVYU";
|
||||||
case GVFG_PIXFMT_Y210:
|
case GVFG_PIXFMT_Y210:
|
||||||
return "Y210";
|
return "Y210";
|
||||||
default:
|
default:
|
||||||
@@ -170,7 +170,7 @@ namespace
|
|||||||
int &outStride)
|
int &outStride)
|
||||||
{
|
{
|
||||||
uint64_t bytesPerPixel = 0;
|
uint64_t bytesPerPixel = 0;
|
||||||
if (pixelFormat == PCIES2MM_PIXFMT_YUY2)
|
if (pixelFormat == PCIES2MM_PIXFMT_YVYU)
|
||||||
bytesPerPixel = 2;
|
bytesPerPixel = 2;
|
||||||
else if (pixelFormat == PCIES2MM_PIXFMT_Y210)
|
else if (pixelFormat == PCIES2MM_PIXFMT_Y210)
|
||||||
bytesPerPixel = 4;
|
bytesPerPixel = 4;
|
||||||
@@ -368,7 +368,7 @@ struct gvfg_handle_t
|
|||||||
const uint32_t configureWidth = waitingForSignal ? 2 : width;
|
const uint32_t configureWidth = waitingForSignal ? 2 : width;
|
||||||
const uint32_t configureHeight = waitingForSignal ? 1 : height;
|
const uint32_t configureHeight = waitingForSignal ? 1 : height;
|
||||||
const pcies2mm_pixel_format_t configureFormat =
|
const pcies2mm_pixel_format_t configureFormat =
|
||||||
waitingForSignal || pixelFormat == PCIES2MM_PIXFMT_UNKNOWN ? PCIES2MM_PIXFMT_YUY2 : pixelFormat;
|
waitingForSignal || pixelFormat == PCIES2MM_PIXFMT_UNKNOWN ? PCIES2MM_PIXFMT_YVYU : pixelFormat;
|
||||||
|
|
||||||
pcies2mm_stream_desc_t desc{};
|
pcies2mm_stream_desc_t desc{};
|
||||||
desc.channel = selectedChannel;
|
desc.channel = selectedChannel;
|
||||||
|
|||||||
Reference in New Issue
Block a user