- Render preview directly from the FP16 conversion target into the selected 8-bit or 10-bit swapchain, removing the full-frame scene copy and the intermediate BGRA8 preview pass without capture-frame decimation. - Simplify neutral YUY2/Y210 shaders to one packed texture load per pixel; preserve BT.709 conversion, 10-bit unpacking and odd-width chroma handling. - Cache shader resource views per upload slot and update constant-buffer contents only when source dimensions change. - Allocate only preview resources and skip export-only shader compilation for preview; retain the full BGRA8/RGB10A2/NV12 buffer conversion path. - Unbind render targets before swapchain resize/release and serialize preview configuration and resource changes with GPU rendering. - Bound startup Present retries and retry presentation without redrawing; retain actual skipped-frame counts when presentation remains busy. - Add preview delivery counters for presented, replaced, busy, failed, cancelled and pending frames, including busy source and affected frame ID. - Fix an uncounted pending-frame replacement and drain pending preview work at Stop and before a new run to keep per-run accounting separate. - Track application audio delivery, dropped duration, read/write stalls and frame-ID anomalies while retaining the original 10-block audio queue. - Stop the channel on audio write failure or two seconds of zero-write progress; distinguish cancelled data from runtime drops. - Keep the existing compact UI; aggregate delivery issue logs at most once per five seconds and emit a stop summary with accounting errors only. - Document diagnostic interpretation, GPU changes and validation boundaries. Validation: - User testing reported approximately 15% lower GPU utilization after the optimization. Baseline/final readings and relative versus percentage-point interpretation were not supplied; no independent benchmark was performed. - Static source checks and git diff --check passed. No application or shader build was performed by the agent; 10-bit startup resolution and long-run zero-loss behavior have not been confirmed. - Rebuild the preview DLL with its matching APP; the SDK GPU buffer converter also shares the modified shader source. Capture APIs and driver are unchanged.
164 lines
4.4 KiB
C
164 lines
4.4 KiB
C
#pragma once
|
|
|
|
/*
|
|
* Optional GVFG preview helper API.
|
|
*
|
|
* Standalone preview helper. Applications provide the frame buffer, pixel
|
|
* format, and row stride explicitly; gvfg_preview.dll does not depend on
|
|
* gvfg.dll.
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef _WIN32
|
|
#ifdef GVFG_PREVIEW_BUILD
|
|
#define GVFG_PREVIEW_API __declspec(dllexport)
|
|
#else
|
|
#define GVFG_PREVIEW_API __declspec(dllimport)
|
|
#endif
|
|
#else
|
|
#define GVFG_PREVIEW_API
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef enum
|
|
{
|
|
GVFG_PREVIEW_OK = 0,
|
|
GVFG_PREVIEW_EINVAL = -1,
|
|
GVFG_PREVIEW_ESTATE = -2,
|
|
GVFG_PREVIEW_ENOTSUP = -3,
|
|
GVFG_PREVIEW_ERENDER = -4
|
|
} gvfg_preview_status_t;
|
|
|
|
typedef struct gvfg_preview_handle_t *gvfg_preview_handle;
|
|
|
|
typedef enum
|
|
{
|
|
GVFG_PREVIEW_PIXFMT_Y210 = 2,
|
|
GVFG_PREVIEW_PIXFMT_YUY2 = 3
|
|
} gvfg_preview_pixel_format_t;
|
|
|
|
typedef struct
|
|
{
|
|
const void *data;
|
|
uint64_t data_size;
|
|
int width;
|
|
int height;
|
|
int pixel_format; /* gvfg_preview_pixel_format_t */
|
|
int bit_depth;
|
|
int row_bytes;
|
|
uint64_t frame_id;
|
|
} gvfg_preview_frame_t;
|
|
|
|
typedef struct
|
|
{
|
|
int active;
|
|
int width;
|
|
int height;
|
|
int bit_depth;
|
|
char pixel_format[32];
|
|
char adapter_name[160];
|
|
int adapter_index;
|
|
} gvfg_preview_info_t;
|
|
|
|
/*
|
|
* Preview presentation statistics.
|
|
*
|
|
* present_fps counts only frames accepted by DXGI Present. A frame skipped
|
|
* because the non-blocking swapchain is busy is excluded. The rate uses
|
|
* successful presents from the most recent five seconds.
|
|
*/
|
|
typedef struct
|
|
{
|
|
double present_fps;
|
|
uint64_t presented_frames;
|
|
uint64_t skipped_presents;
|
|
} gvfg_preview_stats_t;
|
|
|
|
/* Lifetime counters (until shutdown); configure/clear do not reset them.
|
|
* submitted = presented + replaced + busy + failed + cancelled + in_flight.
|
|
* Presented means DXGI accepted Present, not proof of physical scanout.
|
|
* Failed render API calls are counted by the caller, not in submitted.
|
|
*/
|
|
typedef struct
|
|
{
|
|
uint64_t submitted;
|
|
uint64_t presented;
|
|
uint64_t replaced;
|
|
uint64_t busy;
|
|
uint64_t failed;
|
|
uint64_t cancelled;
|
|
uint64_t in_flight;
|
|
uint64_t last_presented_id;
|
|
uint64_t present_busy;
|
|
uint64_t slots_busy;
|
|
uint64_t last_busy_id;
|
|
} gvfg_preview_delivery_stats_t;
|
|
|
|
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_get_delivery_stats(
|
|
gvfg_preview_handle handle, gvfg_preview_delivery_stats_t *out_stats);
|
|
|
|
/* Call after stopping submissions. Wait at most timeout_ms for queued work.
|
|
* Returns ESTATE if work remains; does not discard or reset counters. */
|
|
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_wait_idle(
|
|
gvfg_preview_handle handle, uint32_t timeout_ms);
|
|
|
|
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_create(
|
|
gvfg_preview_handle *out_handle);
|
|
|
|
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_destroy(
|
|
gvfg_preview_handle handle);
|
|
|
|
/*
|
|
* Attach a native window handle for preview output.
|
|
*
|
|
* On Windows, native_window_handle is an HWND.
|
|
*/
|
|
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_attach_window(
|
|
gvfg_preview_handle handle,
|
|
void *native_window_handle);
|
|
|
|
/* Pre-create GPU resources before the first captured frame is held. */
|
|
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_prepare(
|
|
gvfg_preview_handle handle,
|
|
int width,
|
|
int height,
|
|
int bit_depth);
|
|
|
|
/*
|
|
* Upload one frame to an internal GPU slot and queue it for preview.
|
|
*
|
|
* The frame memory remains owned by the caller and must remain valid until
|
|
* this function returns. GPU conversion and Present continue on the internal
|
|
* preview worker. If preview falls behind, an older queued preview frame may
|
|
* be replaced; capture ownership and capture-frame delivery are unaffected.
|
|
*/
|
|
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_render_frame(
|
|
gvfg_preview_handle handle,
|
|
const gvfg_preview_frame_t *frame);
|
|
|
|
/* Replace the last presented frame with a solid black frame. */
|
|
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_clear(
|
|
gvfg_preview_handle handle);
|
|
|
|
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_get_info(
|
|
gvfg_preview_handle handle,
|
|
gvfg_preview_info_t *out_info);
|
|
|
|
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_get_stats(
|
|
gvfg_preview_handle handle,
|
|
gvfg_preview_stats_t *out_stats);
|
|
|
|
GVFG_PREVIEW_API gvfg_preview_status_t gvfg_preview_shutdown(
|
|
gvfg_preview_handle handle);
|
|
|
|
GVFG_PREVIEW_API const char *gvfg_preview_strerror(
|
|
gvfg_preview_status_t status);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|