Integrate GPU conversion and update capture pipeline
This commit is contained in:
@@ -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">
|
||||
<mxGeometry height="58" width="280" x="450" y="50" as="geometry" />
|
||||
</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">
|
||||
<mxGeometry height="275" width="1180" x="50" y="515" as="geometry">
|
||||
<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">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</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">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
|
||||
+24
-82
@@ -3,9 +3,9 @@
|
||||
本文說明客戶端使用的 GVFG capture API,主要 public header 是
|
||||
`sdk/gvfg/include/gvfg_capture.h`。
|
||||
|
||||
Customer SDK 的 core API 只負責 capture。它不 expose SDK-managed preview、
|
||||
driver registers、DMA internals 或 FPGA debug controls。Preview rendering、
|
||||
snapshot conversion 這類功能放在 helper DLL,使用者需要時再另外 link。
|
||||
Customer SDK 的 core `gvfg.dll` 負責 capture 與 explicit GPU buffer conversion。
|
||||
它不 expose SDK-managed preview、driver registers、DMA internals 或 FPGA debug
|
||||
controls。Preview rendering 仍由 optional `gvfg_preview.dll` 提供。
|
||||
|
||||
Customer 交付內容只包含 public headers 與 public DLL functions。Customer
|
||||
sample 只記錄 signal events、API failures、capture stall/recovery 與
|
||||
@@ -152,48 +152,28 @@ typedef struct
|
||||
|
||||
板子只提供兩種 tightly packed native capture layout:
|
||||
|
||||
- `YUY2`:`row_stride_bytes = width * 2`。
|
||||
- `YVYU`:`row_stride_bytes = width * 2`。
|
||||
- `Y210`:`row_stride_bytes = width * 4`。
|
||||
|
||||
其他 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
|
||||
typedef struct gvfg_convert_frame_t *gvfg_convert_frame;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int pixel_format;
|
||||
int row_bytes;
|
||||
void *data;
|
||||
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
|
||||
frame,再明確把 source frame convert 進去。Core capture API 仍然回傳
|
||||
hardware/native buffer,不會在 `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_GPU_OUTPUT_BGRA8` 與 packed `GVFG_GPU_OUTPUT_RGB10A2`;兩者皆為
|
||||
每像素四 bytes。Core capture API 仍回傳 hardware/native buffer,不會在
|
||||
`gvfg_read_frame()` 裡自動轉換。
|
||||
|
||||
### `gvfg_event_type_t`
|
||||
|
||||
@@ -271,69 +251,31 @@ gvfg_status_t gvfg_read_frame(gvfg_handle handle,
|
||||
- `GVFG_ETIMEOUT`:timeout 前沒有 frame。
|
||||
- `GVFG_ESTATE`:capture 尚未 running,或上一個 frame 還沒 release。
|
||||
|
||||
### `gvfg_convert_create_frame` / `gvfg_convert_destroy_frame`
|
||||
### `gvfg_gpu_convert_to_buffer`
|
||||
|
||||
```c
|
||||
gvfg_status_t gvfg_convert_create_frame(const gvfg_convert_frame_desc_t *desc,
|
||||
gvfg_convert_frame *out_frame);
|
||||
gvfg_status_t gvfg_convert_destroy_frame(gvfg_convert_frame frame);
|
||||
gvfg_status_t gvfg_gpu_convert_to_buffer(const gvfg_frame_t *source,
|
||||
const gvfg_gpu_output_buffer_t *output);
|
||||
```
|
||||
|
||||
建立或銷毀 helper-owned destination frame。Caller 主要設定
|
||||
`desc.pixel_format`;`width`、`height`、`row_bytes` 可以是 0,讓
|
||||
`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 範例:
|
||||
用 D3D11 shader 同步轉換 captured YVYU/Y210 frame,並 readback 到 caller buffer。
|
||||
函式返回前 source 與 output memory 必須保持有效;SDK 不保留兩者的 pointer。
|
||||
|
||||
```c
|
||||
#include <gvfg_capture.h>
|
||||
#include <gvfg_convert.h>
|
||||
|
||||
gvfg_frame_t frame = {};
|
||||
if (gvfg_read_frame(h, &frame, 1000) == GVFG_OK) {
|
||||
gvfg_convert_frame_desc_t desc = {};
|
||||
desc.pixel_format = GVFG_CONVERT_FMT_RGB48;
|
||||
|
||||
gvfg_convert_frame image = NULL;
|
||||
if (gvfg_convert_create_frame(&desc, &image) == GVFG_OK &&
|
||||
gvfg_convert_frame_from_capture(&frame, image) == GVFG_OK) {
|
||||
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_gpu_output_buffer_t output = {};
|
||||
output.data = canvas_data;
|
||||
output.data_size = canvas_size;
|
||||
output.row_bytes = frame.width * 4;
|
||||
output.pixel_format = GVFG_GPU_OUTPUT_BGRA8;
|
||||
gvfg_gpu_convert_to_buffer(&frame, &output);
|
||||
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`
|
||||
|
||||
```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">
|
||||
<mxGeometry x="430" y="540" width="310" height="120" as="geometry"/>
|
||||
</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"/>
|
||||
</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">
|
||||
|
||||
+17
-47
@@ -10,19 +10,15 @@ GVFG 目前切成幾個清楚的模組:
|
||||
```text
|
||||
sdk/gvfg/
|
||||
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/
|
||||
gvfg_preview.dll
|
||||
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/
|
||||
gvfg_qt_preview: customer-facing, uses public APIs only
|
||||
gvfg_qt_diagnostic: internal build, additionally uses gvfg_debug.h
|
||||
gvfg_qt_preview: diagnostics are selected at configure time
|
||||
```
|
||||
|
||||
從 customer 角度看,core SDK 必須維持 driver-neutral。PCIES2MM、IRQ、DMA counters、
|
||||
@@ -48,11 +44,11 @@ pcies2mm_reg.h
|
||||
FPGA register offsets and bit masks
|
||||
|
||||
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,不可放進
|
||||
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。
|
||||
上述拆分只分離程式責任,不會增加 capture thread。
|
||||
|
||||
@@ -70,11 +66,6 @@ flowchart TD
|
||||
PreviewPipe["private D3D preview pipeline"]
|
||||
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"]
|
||||
CaptureApi["sdk/gvfg/include/gvfg_capture.h"]
|
||||
DebugApi["sdk/gvfg/include/gvfg_debug.h\ninternal only"]
|
||||
@@ -89,13 +80,11 @@ flowchart TD
|
||||
|
||||
CustomerApp --> CaptureApi
|
||||
CustomerApp -. optional display .-> PreviewApi
|
||||
CustomerApp -. optional snapshot .-> ConvertApi
|
||||
CustomerApp -. GPU buffer conversion .-> CaptureApi
|
||||
QtApp --> CaptureApi
|
||||
QtApp --> DebugApi
|
||||
QtApp --> PreviewApi
|
||||
PreviewApi --> PreviewPipe
|
||||
ConvertApi --> ConvertPipe
|
||||
ConvertApi --> CaptureApi
|
||||
CaptureApi --> Facade
|
||||
DebugApi --> Facade
|
||||
Facade --> PcieS2mm
|
||||
@@ -203,7 +192,7 @@ Released : ready=false, in_use=false
|
||||
- `frame.data` 在 `gvfg_release_frame()` 前有效。
|
||||
- `frame.row_stride_bytes` 是相鄰兩列起點之間的 byte 距離;consumer 不應自行
|
||||
由 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。
|
||||
- `gvfg_handle` 永遠 opaque;stable release 後 `gvfg_frame_t` 凍結,只有 major
|
||||
version 可以破壞既有 ABI。
|
||||
@@ -211,8 +200,8 @@ Released : ready=false, in_use=false
|
||||
`gvfg_get_frame_color_info()` 與 `gvfg_get_frame_timestamp_info()`。不要預先在每個
|
||||
struct 放大型 reserved array;等 metadata 類型真的很多再考慮 side data。
|
||||
- `gvfg_preview.dll` 直接使用 capture frame 的 `row_stride_bytes`。
|
||||
- `gvfg_convert.dll` 負責 explicit snapshot/export conversion。不要把 color
|
||||
conversion、image export、GPU conversion policy 搬進 `gvfg.dll`。
|
||||
- `gvfg.dll` 提供 explicit GPU buffer conversion;API 不負責 image export、
|
||||
thread、queue 或 frame ownership policy。
|
||||
- 同一個 handle 一次最多 hold 一個 frame。
|
||||
- Application 如果 release 後還要用 data,必須自己 copy frame。
|
||||
- `gvfg_preview_render_frame()` 是 synchronous,應該在 `gvfg_release_frame()` 前呼叫。
|
||||
@@ -277,7 +266,6 @@ Customer/demo 可見:
|
||||
```text
|
||||
include/gvfg_capture.h
|
||||
include/gvfg_preview.h when display helper is used
|
||||
include/gvfg_convert.h when snapshot/export conversion is used
|
||||
```
|
||||
|
||||
Internal debug only:
|
||||
@@ -301,13 +289,10 @@ Include:
|
||||
```text
|
||||
include/gvfg_capture.h
|
||||
include/gvfg_preview.h when the demo shows video
|
||||
include/gvfg_convert.h when the demo exports snapshots
|
||||
lib/gvfg.lib
|
||||
lib/gvfg_preview.lib when the demo shows video
|
||||
lib/gvfg_convert.lib when the demo exports snapshots
|
||||
bin/gvfg.dll
|
||||
bin/gvfg_preview.dll when the demo shows video
|
||||
bin/gvfg_convert.dll when the demo exports snapshots
|
||||
samples/customer-facing source
|
||||
docs/GVFG_CUSTOMER_API.md
|
||||
```
|
||||
@@ -332,22 +317,19 @@ Include:
|
||||
include/gvfg_capture.h
|
||||
include/gvfg_debug.h
|
||||
include/gvfg_preview.h
|
||||
include/gvfg_convert.h
|
||||
lib/gvfg.lib
|
||||
lib/gvfg_preview.lib
|
||||
lib/gvfg_convert.lib
|
||||
bin/gvfg.dll
|
||||
bin/gvfg_preview.dll
|
||||
bin/gvfg_convert.dll
|
||||
bin/gvfg_qt_diagnostic.exe
|
||||
bin/gvfg_qt_preview.exe
|
||||
PDB symbols
|
||||
internal debug notes
|
||||
```
|
||||
|
||||
### Full Release Package
|
||||
|
||||
Full application release 可以使用 `gvfg.dll`、`gvfg_preview.dll` 和
|
||||
`gvfg_convert.dll`,再加上 licensing 與 closed-source application integration。
|
||||
Full application release 可以使用 `gvfg.dll` 與 `gvfg_preview.dll`,再加上
|
||||
licensing 與 closed-source application integration。
|
||||
不要把 full release package 當成 daily driver/FPGA bring-up vehicle。
|
||||
|
||||
## Build
|
||||
@@ -356,40 +338,28 @@ Top-level CMake 會 build core SDK、helpers 和 optional sample:
|
||||
|
||||
```text
|
||||
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`
|
||||
不 export `gvfg_debug_get_backend_stats()` 或
|
||||
`gvfg_debug_get_last_error_detail()`,install tree 也不包含
|
||||
`gvfg_debug.h`。
|
||||
|
||||
Internal diagnostic build 使用:
|
||||
Internal diagnostic build 使用 Debug configuration:
|
||||
|
||||
```text
|
||||
BUILD_GVFG_SAMPLES=OFF
|
||||
GVFG_ENABLE_INTERNAL_DEBUG_API=ON
|
||||
BUILD_GVFG_INTERNAL_TOOLS=ON
|
||||
cmake --build build --target gvfg_qt_preview --config Debug
|
||||
```
|
||||
|
||||
只有這個 build 會產生 `gvfg_qt_diagnostic.exe` 並安裝
|
||||
`gvfg_debug.h`。
|
||||
這個 build 仍產生 `gvfg_qt_preview.exe`,但會把 internal diagnostics
|
||||
編譯進同一個執行檔。
|
||||
|
||||
輸出產物:
|
||||
|
||||
```text
|
||||
bin/gvfg.dll
|
||||
bin/gvfg_preview.dll
|
||||
bin/gvfg_convert.dll
|
||||
lib/gvfg.lib
|
||||
lib/gvfg_preview.lib
|
||||
lib/gvfg_convert.lib
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user