Remove gcapture dependency from GVFG standalone
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "gvfg_capture.h"
|
||||
|
||||
#include "gcapture.h"
|
||||
#include "pipeline/shared_scene_pipeline.h"
|
||||
#include "gvfg_render_types.h"
|
||||
#include "shared_scene_pipeline.h"
|
||||
#include "xdma_capture_session.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <wrl/client.h>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
using namespace gvfg::internal;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -364,7 +365,7 @@ struct gvfg_handle_t
|
||||
previewDesc = desc;
|
||||
previewHwnd = desc.enable_preview ? desc.hwnd : nullptr;
|
||||
if (pipeline)
|
||||
pipeline->configurePreview(toGcapPreviewDesc());
|
||||
pipeline->configurePreview(toRenderPreviewDesc());
|
||||
if (previewHwnd && width > 0 && height > 0)
|
||||
createRenderPipeline();
|
||||
return GVFG_OK;
|
||||
@@ -598,23 +599,23 @@ struct gvfg_handle_t
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gcap_preview_desc_t toGcapPreviewDesc() const
|
||||
gvfg_render_preview_desc_t toRenderPreviewDesc() const
|
||||
{
|
||||
gcap_preview_desc_t desc{};
|
||||
gvfg_render_preview_desc_t desc{};
|
||||
desc.hwnd = previewHwnd;
|
||||
desc.enable_preview = previewHwnd ? 1 : 0;
|
||||
desc.use_fp16_pipeline = 1;
|
||||
switch (previewDesc.swapchain_bitdepth)
|
||||
{
|
||||
case GVFG_PREVIEW_BITDEPTH_8BIT:
|
||||
desc.swapchain_10bit = GCAP_PREVIEW_BITDEPTH_8BIT;
|
||||
desc.swapchain_10bit = GVFG_RENDER_PREVIEW_BITDEPTH_8BIT;
|
||||
break;
|
||||
case GVFG_PREVIEW_BITDEPTH_10BIT:
|
||||
desc.swapchain_10bit = GCAP_PREVIEW_BITDEPTH_10BIT;
|
||||
desc.swapchain_10bit = GVFG_RENDER_PREVIEW_BITDEPTH_10BIT;
|
||||
break;
|
||||
case GVFG_PREVIEW_BITDEPTH_AUTO:
|
||||
default:
|
||||
desc.swapchain_10bit = GCAP_PREVIEW_BITDEPTH_AUTO;
|
||||
desc.swapchain_10bit = GVFG_RENDER_PREVIEW_BITDEPTH_AUTO;
|
||||
break;
|
||||
}
|
||||
return desc;
|
||||
@@ -674,7 +675,7 @@ struct gvfg_handle_t
|
||||
if (!pipeline->initialize(d3d.Get(), ctx.Get(), d2dCtx.Get(), dwrite.Get(), d2dWhite.Get(), d2dBlack.Get()))
|
||||
return false;
|
||||
|
||||
pipeline->configurePreview(toGcapPreviewDesc());
|
||||
pipeline->configurePreview(toRenderPreviewDesc());
|
||||
pipeline->set_source_bit_depth(static_cast<int>(bitDepth ? bitDepth : 8));
|
||||
return pipeline->ensure_rt_and_pipeline(static_cast<int>(width), static_cast<int>(height)) &&
|
||||
pipeline->ensure_preview_swapchain(static_cast<int>(width), static_cast<int>(height));
|
||||
@@ -743,7 +744,7 @@ struct gvfg_handle_t
|
||||
pipeline->set_source_bit_depth(static_cast<int>(frame.bit_depth ? frame.bit_depth : fallbackBitDepth));
|
||||
|
||||
const auto *base = static_cast<const uint8_t *>(frame.data);
|
||||
gcap_pixfmt_t renderFmt = GCAP_FMT_YUY2;
|
||||
gvfg_render_pixfmt_t renderFmt = GVFG_RENDER_FMT_YUY2;
|
||||
bool uploaded = false;
|
||||
|
||||
switch (frame.pixel_format)
|
||||
@@ -753,7 +754,7 @@ struct gvfg_handle_t
|
||||
const int stride = frame.plane_stride_bytes[0] ? static_cast<int>(frame.plane_stride_bytes[0]) : w * 2;
|
||||
if (stride < w * 2)
|
||||
return false;
|
||||
renderFmt = GCAP_FMT_YUY2;
|
||||
renderFmt = GVFG_RENDER_FMT_YUY2;
|
||||
uploaded = pipeline->upload_yuy2_frame(base + frame.plane_offset_bytes[0], stride, w, h);
|
||||
break;
|
||||
}
|
||||
@@ -762,7 +763,7 @@ struct gvfg_handle_t
|
||||
const int stride = frame.plane_stride_bytes[0] ? static_cast<int>(frame.plane_stride_bytes[0]) : w * 4;
|
||||
if (stride < w * 4)
|
||||
return false;
|
||||
renderFmt = GCAP_FMT_Y210;
|
||||
renderFmt = GVFG_RENDER_FMT_Y210;
|
||||
uploaded = pipeline->upload_y210_frame(base + frame.plane_offset_bytes[0], stride, w, h);
|
||||
break;
|
||||
}
|
||||
@@ -772,7 +773,7 @@ struct gvfg_handle_t
|
||||
return false;
|
||||
const int strideY = frame.plane_stride_bytes[0] ? static_cast<int>(frame.plane_stride_bytes[0]) : w;
|
||||
const int strideUV = frame.plane_stride_bytes[1] ? static_cast<int>(frame.plane_stride_bytes[1]) : strideY;
|
||||
renderFmt = GCAP_FMT_NV12;
|
||||
renderFmt = GVFG_RENDER_FMT_NV12;
|
||||
uploaded = pipeline->upload_nv12_frame(base + frame.plane_offset_bytes[0], strideY,
|
||||
base + frame.plane_offset_bytes[1], strideUV, w, h);
|
||||
break;
|
||||
@@ -783,7 +784,7 @@ struct gvfg_handle_t
|
||||
return false;
|
||||
const int strideY = frame.plane_stride_bytes[0] ? static_cast<int>(frame.plane_stride_bytes[0]) : w * 2;
|
||||
const int strideUV = frame.plane_stride_bytes[1] ? static_cast<int>(frame.plane_stride_bytes[1]) : strideY;
|
||||
renderFmt = GCAP_FMT_P010;
|
||||
renderFmt = GVFG_RENDER_FMT_P010;
|
||||
uploaded = pipeline->upload_p010_frame(base + frame.plane_offset_bytes[0], strideY,
|
||||
base + frame.plane_offset_bytes[1], strideUV, w, h);
|
||||
break;
|
||||
@@ -817,7 +818,7 @@ struct gvfg_handle_t
|
||||
if (!pipeline->blit_fp16_to_rgba8(w, h))
|
||||
return;
|
||||
|
||||
gcap_frame_t readback{};
|
||||
gvfg_render_frame_t readback{};
|
||||
if (pipeline->readback_to_frame(w, h, frame.timestamp_ns ? frame.timestamp_ns : now_ns(), frame.frame_id, &readback))
|
||||
{
|
||||
gvfg_frame_t out{};
|
||||
@@ -1143,3 +1144,6 @@ extern "C"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "gcapture.h"
|
||||
#include "gvfg_logging.h"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
@@ -9,9 +9,9 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace gcap
|
||||
namespace gvfg::internal
|
||||
{
|
||||
void log_message(gcap_log_level_t, const char *message_utf8)
|
||||
void log_message(gvfg_log_level_t, const char *message_utf8)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const char *msg = message_utf8 ? message_utf8 : "";
|
||||
@@ -24,7 +24,7 @@ namespace gcap
|
||||
#endif
|
||||
}
|
||||
|
||||
void log_message_w(gcap_log_level_t level, const wchar_t *message_wide)
|
||||
void log_message_w(gvfg_log_level_t level, const wchar_t *message_wide)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!message_wide)
|
||||
@@ -44,7 +44,7 @@ namespace gcap
|
||||
#endif
|
||||
}
|
||||
|
||||
void log_printf(gcap_log_level_t level, const char *fmt, ...)
|
||||
void log_printf(gvfg_log_level_t level, const char *fmt, ...)
|
||||
{
|
||||
if (!fmt)
|
||||
{
|
||||
@@ -60,3 +60,4 @@ namespace gcap
|
||||
log_message(level, buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdarg>
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
typedef enum
|
||||
{
|
||||
GVFG_LOG_TRACE = 0,
|
||||
GVFG_LOG_DEBUG = 1,
|
||||
GVFG_LOG_INFO = 2,
|
||||
GVFG_LOG_WARN = 3,
|
||||
GVFG_LOG_ERROR = 4
|
||||
} gvfg_log_level_t;
|
||||
|
||||
void log_message(gvfg_log_level_t level, const char *message_utf8);
|
||||
void log_message_w(gvfg_log_level_t level, const wchar_t *message_wide);
|
||||
void log_printf(gvfg_log_level_t level, const char *fmt, ...);
|
||||
}
|
||||
|
||||
inline void gvfg_log_trace(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_TRACE, message_utf8); }
|
||||
inline void gvfg_log_debug(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_DEBUG, message_utf8); }
|
||||
inline void gvfg_log_info(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_INFO, message_utf8); }
|
||||
inline void gvfg_log_warn(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_WARN, message_utf8); }
|
||||
inline void gvfg_log_error(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_ERROR, message_utf8); }
|
||||
inline void gvfg_log_debug_w(const wchar_t *message_wide) { gvfg::internal::log_message_w(gvfg::internal::GVFG_LOG_DEBUG, message_wide); }
|
||||
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
typedef enum
|
||||
{
|
||||
GVFG_RENDER_FMT_NV12,
|
||||
GVFG_RENDER_FMT_YUY2,
|
||||
GVFG_RENDER_FMT_ARGB,
|
||||
GVFG_RENDER_FMT_P010,
|
||||
GVFG_RENDER_FMT_Y210,
|
||||
GVFG_RENDER_FMT_V210,
|
||||
GVFG_RENDER_FMT_R210
|
||||
} gvfg_render_pixfmt_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const void *data[3];
|
||||
int stride[3];
|
||||
int plane_count;
|
||||
int width;
|
||||
int height;
|
||||
gvfg_render_pixfmt_t format;
|
||||
uint64_t pts_ns;
|
||||
uint64_t frame_id;
|
||||
} gvfg_render_frame_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_RENDER_PREVIEW_BITDEPTH_8BIT = 0,
|
||||
GVFG_RENDER_PREVIEW_BITDEPTH_10BIT = 1,
|
||||
GVFG_RENDER_PREVIEW_BITDEPTH_AUTO = 2
|
||||
} gvfg_render_preview_bitdepth_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *hwnd;
|
||||
int enable_preview;
|
||||
int use_fp16_pipeline;
|
||||
int swapchain_10bit;
|
||||
} gvfg_render_preview_desc_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_RENDER_EXPORT_RAW_NATIVE = 1 << 0,
|
||||
GVFG_RENDER_EXPORT_RAW_RGB10_U16 = 1 << 1,
|
||||
GVFG_RENDER_EXPORT_RAW_RGBA16 = 1 << 2,
|
||||
GVFG_RENDER_EXPORT_TIFF = 1 << 3,
|
||||
GVFG_RENDER_EXPORT_STATS = 1 << 4,
|
||||
GVFG_RENDER_EXPORT_PNG = 1 << 5,
|
||||
GVFG_RENDER_EXPORT_RAW_GIGABYTE_HEADER = 1 << 6,
|
||||
GVFG_RENDER_EXPORT_RAW_RGBA8 = 1 << 7,
|
||||
GVFG_RENDER_EXPORT_RAW_ALL = GVFG_RENDER_EXPORT_RAW_NATIVE | GVFG_RENDER_EXPORT_RAW_RGB10_U16 | GVFG_RENDER_EXPORT_RAW_RGBA16
|
||||
} gvfg_render_export_flags_t;
|
||||
|
||||
enum { GVFG_RENDER_GIGABYTE_RAW_HEADER_SIZE = 128 };
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,136 @@
|
||||
#pragma once
|
||||
|
||||
#include "../internal/gvfg_render_types.h"
|
||||
|
||||
#include <d3d11_1.h>
|
||||
#include <d2d1_1.h>
|
||||
#include <dwrite.h>
|
||||
#include <dxgi1_2.h>
|
||||
#include <wrl.h>
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
|
||||
class SharedScenePipeline
|
||||
{
|
||||
public:
|
||||
SharedScenePipeline() = default;
|
||||
~SharedScenePipeline() = default;
|
||||
|
||||
bool initialize(ID3D11Device *d3d,
|
||||
ID3D11DeviceContext *ctx,
|
||||
ID2D1DeviceContext *d2d_ctx,
|
||||
IDWriteFactory *dwrite = nullptr,
|
||||
ID2D1SolidColorBrush *white = nullptr,
|
||||
ID2D1SolidColorBrush *black = nullptr);
|
||||
void shutdown();
|
||||
|
||||
bool configurePreview(const gvfg_render_preview_desc_t &desc);
|
||||
void set_source_bit_depth(int bits);
|
||||
int source_bit_depth() const { return preview_source_bit_depth_; }
|
||||
void release_preview_swapchain();
|
||||
|
||||
bool create_shaders_and_states();
|
||||
bool ensure_rt_and_pipeline(int w, int h);
|
||||
uint64_t last_ensure_rt_ns() const { return lastEnsureRtNs_; }
|
||||
uint64_t total_ensure_rt_ns() const { return totalEnsureRtNs_; }
|
||||
uint64_t ensure_rt_calls() const { return ensureRtCalls_; }
|
||||
bool last_ensure_rt_rebuilt() const { return lastEnsureRtRebuilt_; }
|
||||
const char *last_ensure_rt_rebuild_reason() const { return lastEnsureRtReason_; }
|
||||
bool ensure_preview_swapchain(int w, int h);
|
||||
bool preview_swapchain_10bit() const { return preview_swapchain_10bit_; }
|
||||
int preview_swapchain_mode() const { return preview_swapchain_mode_; }
|
||||
bool present_preview(int src_w, int src_h);
|
||||
DXGI_FORMAT preview_backbuffer_format() const;
|
||||
DXGI_FORMAT scene_texture_format() const;
|
||||
DXGI_FORMAT linear_fp16_texture_format() const;
|
||||
bool gpu_overlay_text(const wchar_t *text, int frame_w, int frame_h);
|
||||
bool composite_overlay_to_scene_fp16(int frame_w, int frame_h);
|
||||
bool blit_fp16_to_rgba8(int frame_w, int frame_h);
|
||||
bool upload_argb_frame(const void *data, int frame_w, int frame_h, int src_stride);
|
||||
bool render_uploaded_argb_to_fp16(int frame_w, int frame_h);
|
||||
bool upload_nv12_frame(const uint8_t *y, int stride_y, const uint8_t *uv, int stride_uv, int frame_w, int frame_h);
|
||||
bool upload_p010_frame(const uint8_t *y, int stride_y, const uint8_t *uv, int stride_uv, int frame_w, int frame_h);
|
||||
bool upload_yuy2_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_v210_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 copy_fp16_to_scene();
|
||||
bool readback_to_frame(int frame_w, int frame_h, uint64_t pts_ns, uint64_t frame_id,
|
||||
gvfg_render_frame_t *out);
|
||||
bool export_scene_rgb10(const wchar_t *base_path, int raw_flags, bool export_tiff, bool export_stats, bool export_gigabyte_raw);
|
||||
|
||||
ID3D11Device *d3d_ = nullptr;
|
||||
ID3D11DeviceContext *ctx_ = nullptr;
|
||||
ID2D1DeviceContext *d2d_ctx_ = nullptr;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv_fp16_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_scene_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv_scene_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv_scene_fp16_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv_rgba_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_rgba8_to_preview_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_rgba_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> upload_nv12_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> upload_yuy2_packed_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> upload_y210_packed_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> rtv_rgba_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_stage_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> rt_scene_stage_fp16_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Buffer> cs_params_;
|
||||
Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> rt_uav_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11VertexShader> vs_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_nv12_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_p010_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_yuy2_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_y210_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_fp16_to_rgba8_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_fp16_to_preview_;
|
||||
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps_composite_overlay_fp16_;
|
||||
Microsoft::WRL::ComPtr<ID3D11InputLayout> il_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Buffer> vb_;
|
||||
Microsoft::WRL::ComPtr<ID3D11SamplerState> samp_;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID2D1Bitmap1> d2d_bitmap_rt_;
|
||||
|
||||
Microsoft::WRL::ComPtr<IDWriteFactory> dwrite_;
|
||||
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> d2d_white_;
|
||||
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> d2d_black_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> overlay_rgba_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> overlay_rtv_;
|
||||
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> overlay_srv_;
|
||||
|
||||
void *preview_hwnd_ = nullptr;
|
||||
bool preview_enabled_ = false;
|
||||
bool preview_use_fp16_ = false;
|
||||
int preview_swapchain_mode_ = GVFG_RENDER_PREVIEW_BITDEPTH_10BIT;
|
||||
int preview_source_bit_depth_ = 0;
|
||||
bool preview_swapchain_10bit_ = false;
|
||||
DXGI_FORMAT preview_swapchain_format_ = DXGI_FORMAT_UNKNOWN;
|
||||
int preview_w_ = 0;
|
||||
int preview_h_ = 0;
|
||||
|
||||
|
||||
int rt_w_ = 0;
|
||||
int rt_h_ = 0;
|
||||
uint64_t lastEnsureRtNs_ = 0;
|
||||
uint64_t totalEnsureRtNs_ = 0;
|
||||
uint64_t ensureRtCalls_ = 0;
|
||||
bool lastEnsureRtRebuilt_ = false;
|
||||
const char *lastEnsureRtReason_ = "never";
|
||||
|
||||
Microsoft::WRL::ComPtr<IDXGISwapChain1> preview_swapchain_;
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> preview_backbuf_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> preview_rtv_;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user