diff --git a/sdk/gvfg/CMakeLists.txt b/sdk/gvfg/CMakeLists.txt index b4c7570..ab34985 100644 --- a/sdk/gvfg/CMakeLists.txt +++ b/sdk/gvfg/CMakeLists.txt @@ -44,8 +44,8 @@ endif() target_link_libraries(gvfg PRIVATE setupapi - ole32 user32 windowscodecs - dxgi d3d11 d2d1 dwrite D3DCompiler + user32 + dxgi d3d11 D3DCompiler ) if (MSVC) diff --git a/sdk/gvfg/src/backend/xdma/xdma_backend_types.h b/sdk/gvfg/src/backend/xdma/xdma_backend_types.h index 752be22..a47c688 100644 --- a/sdk/gvfg/src/backend/xdma/xdma_backend_types.h +++ b/sdk/gvfg/src/backend/xdma/xdma_backend_types.h @@ -16,16 +16,6 @@ typedef enum xdma_status_t XDMA_EABI } xdma_status_t; -typedef struct xdma_device_info_t -{ - char friendly_name[GDRIVER_MAX_FRIENDLY_NAME]; - char serial_number[GDRIVER_MAX_SERIAL_NUMBER]; - char firmware_version[GDRIVER_MAX_FIRMWARE_VERSION]; - char driver_version[GDRIVER_MAX_DRIVER_VERSION]; - uint32_t supported_inputs_mask; - uint32_t supported_pixel_formats_mask; -} xdma_device_info_t; - typedef struct xdma_stream_desc_t { gdriver_input_t input; diff --git a/sdk/gvfg/src/backend/xdma/xdma_capture_session.cpp b/sdk/gvfg/src/backend/xdma/xdma_capture_session.cpp index 9d5e482..4500056 100644 --- a/sdk/gvfg/src/backend/xdma/xdma_capture_session.cpp +++ b/sdk/gvfg/src/backend/xdma/xdma_capture_session.cpp @@ -256,18 +256,6 @@ namespace return oss.str(); } - static void copy_string(const std::string &src, char *dst, size_t dstSize) - { - if (!dst || dstSize == 0) - return; - dst[0] = '\0'; - if (src.empty()) - return; - const size_t n = (std::min)(src.size(), dstSize - 1); - std::memcpy(dst, src.data(), n); - dst[n] = '\0'; - } - static void reset_stats(xdma_stream_stats_t &stats, gdriver_stream_state_t state) { std::memset(&stats, 0, sizeof(stats)); @@ -370,15 +358,6 @@ namespace gvfg::internal close(); } - xdma_status_t XdmaCaptureSession::open_default() - { - const auto devices = enumerate_xdma_devices(); - XDMA_LOG("open_default: device_count=%zu", devices.size()); - if (devices.empty()) - return fail(XDMA_ENODEV, "enumerate_xdma_devices", ERROR_NOT_FOUND); - return open_device(devices.front()); - } - xdma_status_t XdmaCaptureSession::open_device_index(size_t deviceIndex) { const auto devices = enumerate_xdma_devices(); @@ -507,23 +486,6 @@ namespace gvfg::internal return XDMA_OK; } - xdma_status_t XdmaCaptureSession::get_device_info(xdma_device_info_t &out) const - { - if (!opened_) - return XDMA_ESTATE; - std::memset(&out, 0, sizeof(out)); - copy_string(wide_to_utf8(friendly_name_), out.friendly_name, sizeof(out.friendly_name)); - copy_string("XDMA", out.driver_version, sizeof(out.driver_version)); - out.supported_inputs_mask = (1u << GDRIVER_INPUT_SDI) | (1u << GDRIVER_INPUT_HDMI); - out.supported_pixel_formats_mask = (1u << GDRIVER_PIXFMT_YUY2) | - (1u << GDRIVER_PIXFMT_Y210) | - (1u << GDRIVER_PIXFMT_RGB24) | - (1u << GDRIVER_PIXFMT_NV12) | - (1u << GDRIVER_PIXFMT_P010) | - (1u << GDRIVER_PIXFMT_YUV444); - return XDMA_OK; - } - xdma_status_t XdmaCaptureSession::get_signal_status(xdma_signal_status_t &out) const { if (!opened_) @@ -591,14 +553,6 @@ namespace gvfg::internal return XDMA_OK; } - xdma_status_t XdmaCaptureSession::get_stream_stats(xdma_stream_stats_t &out) const - { - std::lock_guard lock(mutex_); - out = stats_; - out.state = running_ ? GDRIVER_STREAM_RUNNING : (configured_ ? GDRIVER_STREAM_CONFIGURED : GDRIVER_STREAM_STOPPED); - return XDMA_OK; - } - xdma_status_t XdmaCaptureSession::set_event_callback(xdma_event_callback_t callback, void *user, uint32_t eventMask) { std::lock_guard lock(event_callback_mutex_); diff --git a/sdk/gvfg/src/backend/xdma/xdma_capture_session.h b/sdk/gvfg/src/backend/xdma/xdma_capture_session.h index 52c4d1a..6441725 100644 --- a/sdk/gvfg/src/backend/xdma/xdma_capture_session.h +++ b/sdk/gvfg/src/backend/xdma/xdma_capture_session.h @@ -31,14 +31,11 @@ namespace gvfg::internal XdmaCaptureSession &operator=(const XdmaCaptureSession &) = delete; ~XdmaCaptureSession(); - xdma_status_t open_default(); xdma_status_t open_device_index(size_t deviceIndex); xdma_status_t close(); xdma_status_t set_input(gdriver_input_t input); - xdma_status_t get_device_info(xdma_device_info_t &out) const; xdma_status_t get_signal_status(xdma_signal_status_t &out) const; - xdma_status_t get_stream_stats(xdma_stream_stats_t &out) const; xdma_status_t set_event_callback(xdma_event_callback_t callback, void *user, uint32_t eventMask); xdma_status_t configure_stream(const xdma_stream_desc_t &desc); diff --git a/sdk/gvfg/src/gvfg_capture.cpp b/sdk/gvfg/src/gvfg_capture.cpp index 39ce125..83e85d9 100644 --- a/sdk/gvfg/src/gvfg_capture.cpp +++ b/sdk/gvfg/src/gvfg_capture.cpp @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -656,23 +655,9 @@ struct gvfg_handle_t if (SUCCEEDED(d3d.As(&mt)) && mt) mt->SetMultithreadProtected(TRUE); - if (FAILED(D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, d2dFactory.ReleaseAndGetAddressOf())) || !d2dFactory) - return false; - - ComPtr dxgiDev; - if (FAILED(d3d.As(&dxgiDev)) || !dxgiDev) - return false; - if (FAILED(d2dFactory->CreateDevice(dxgiDev.Get(), &d2dDevice)) || !d2dDevice) - return false; - if (FAILED(d2dDevice->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &d2dCtx)) || !d2dCtx) - return false; - if (FAILED(DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &dwrite)) || !dwrite) - return false; - d2dCtx->CreateSolidColorBrush(D2D1::ColorF(1, 1, 1, 1), &d2dWhite); - d2dCtx->CreateSolidColorBrush(D2D1::ColorF(0, 0, 0, 0.55f), &d2dBlack); } - if (!pipeline->initialize(d3d.Get(), ctx.Get(), d2dCtx.Get(), dwrite.Get(), d2dWhite.Get(), d2dBlack.Get())) + if (!pipeline->initialize(d3d.Get(), ctx.Get())) return false; pipeline->configurePreview(toRenderPreviewDesc()); @@ -688,12 +673,6 @@ struct gvfg_handle_t pipeline->release_preview_swapchain(); pipeline.reset(); } - d2dBlack.Reset(); - d2dWhite.Reset(); - dwrite.Reset(); - d2dCtx.Reset(); - d2dDevice.Reset(); - d2dFactory.Reset(); ctx.Reset(); d3d.Reset(); } @@ -988,12 +967,6 @@ struct gvfg_handle_t ComPtr d3d; ComPtr ctx; - ComPtr d2dFactory; - ComPtr d2dDevice; - ComPtr d2dCtx; - ComPtr dwrite; - ComPtr d2dWhite; - ComPtr d2dBlack; std::unique_ptr pipeline; }; diff --git a/sdk/gvfg/src/internal/gvfg_render_types.h b/sdk/gvfg/src/internal/gvfg_render_types.h index aea904d..4fee2a9 100644 --- a/sdk/gvfg/src/internal/gvfg_render_types.h +++ b/sdk/gvfg/src/internal/gvfg_render_types.h @@ -10,9 +10,7 @@ namespace gvfg::internal 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_FMT_Y210 } gvfg_render_pixfmt_t; typedef struct @@ -42,18 +40,4 @@ namespace gvfg::internal 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 }; } diff --git a/sdk/gvfg/src/render/shared_scene_pipeline.cpp b/sdk/gvfg/src/render/shared_scene_pipeline.cpp index c74bf4b..1c32f65 100644 --- a/sdk/gvfg/src/render/shared_scene_pipeline.cpp +++ b/sdk/gvfg/src/render/shared_scene_pipeline.cpp @@ -1,4 +1,3 @@ -#include #include "../internal/gvfg_logging.h" #ifndef NOMINMAX @@ -11,25 +10,7 @@ using namespace gvfg::internal; #include #include #include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static void SSP_DBG(const char *stage, HRESULT hr) -{ - char buf[256] = {}; - std::snprintf(buf, sizeof(buf), "[SharedScene] %s : hr=0x%lx\n", - stage ? stage : "(null)", (unsigned long)hr); - gvfg_log_debug(buf); -} using Microsoft::WRL::ComPtr; @@ -40,11 +21,6 @@ static inline uint16_t normalize_y210_word_for_upload(uint16_t v) return static_cast((v >> 6) & 0x03FFu); } -static inline uint16_t v210_component_for_upload(uint32_t word, int shift) -{ - return static_cast((word >> shift) & 0x03FFu); -} - static const char *ss_dxgi_format_name(DXGI_FORMAT fmt) { switch (fmt) @@ -621,27 +597,6 @@ float4 main(PSIn i) : SV_Target } )"; -static const char *g_ps_composite_overlay_fp16 = R"( -Texture2D texBase : register(t0); -Texture2D texOverlay : register(t1); -SamplerState samL : register(s0); - -struct PSIn -{ - float4 pos : SV_Position; - float2 uv : TEXCOORD0; -}; - -float4 main(PSIn i) : SV_Target -{ - float4 base = texBase.Sample(samL, i.uv); - float4 ov = texOverlay.Sample(samL, i.uv); - float a = saturate(ov.a); - float3 rgb = ov.rgb + base.rgb * (1.0 - a); - return float4(rgb, 1.0); -} -)"; - static const char *g_ps_rgba8_to_preview = R"( Texture2D tex0 : register(t0); SamplerState samL : register(s0); @@ -661,59 +616,11 @@ float4 main(PSIn i) : SV_Target )"; bool SharedScenePipeline::initialize(ID3D11Device *d3d, - ID3D11DeviceContext *ctx, - ID2D1DeviceContext *d2d_ctx, - IDWriteFactory *dwrite, - ID2D1SolidColorBrush *white, - ID2D1SolidColorBrush *black) + ID3D11DeviceContext *ctx) { d3d_ = d3d; ctx_ = ctx; - d2d_ctx_ = d2d_ctx; - dwrite_ = dwrite; - d2d_white_ = white; - d2d_black_ = black; - return d3d_ && ctx_ && d2d_ctx_; -} - -void SharedScenePipeline::shutdown() -{ - release_preview_swapchain(); - d2d_bitmap_rt_.Reset(); - d2d_white_.Reset(); - d2d_black_.Reset(); - dwrite_.Reset(); - overlay_srv_.Reset(); - overlay_rtv_.Reset(); - overlay_rgba_.Reset(); - srv_scene_fp16_.Reset(); - rtv_scene_fp16_.Reset(); - rt_scene_fp16_.Reset(); - srv_fp16_.Reset(); - rtv_fp16_.Reset(); - rt_fp16_.Reset(); - srv_rgba_.Reset(); - rtv_rgba_.Reset(); - rt_rgba_.Reset(); - rt_stage_.Reset(); - rt_scene_stage_fp16_.Reset(); - samp_.Reset(); - vb_.Reset(); - il_.Reset(); - vs_.Reset(); - ps_nv12_.Reset(); - ps_p010_.Reset(); - ps_yuy2_.Reset(); - ps_y210_.Reset(); - ps_fp16_to_rgba8_.Reset(); - ps_fp16_to_preview_.Reset(); - ps_rgba8_to_preview_.Reset(); - ps_composite_overlay_fp16_.Reset(); - cs_params_.Reset(); - rt_uav_.Reset(); - d3d_ = nullptr; - ctx_ = nullptr; - d2d_ctx_ = nullptr; + return d3d_ && ctx_; } bool SharedScenePipeline::configurePreview(const gvfg_render_preview_desc_t &desc) @@ -761,7 +668,7 @@ void SharedScenePipeline::set_source_bit_depth(int bits) bool SharedScenePipeline::create_shaders_and_states() { // Compile shaders - ComPtr vsb, psb1, psb2, psb3, psb4, psb5, psb6, psb7, err; + ComPtr vsb, psb1, psb2, psb3, psb4, psb5, psb6, err; if (FAILED(D3DCompile(g_vs_src, strlen(g_vs_src), nullptr, nullptr, nullptr, "main", "vs_5_0", 0, 0, &vsb, &err))) return false; @@ -820,16 +727,6 @@ bool SharedScenePipeline::create_shaders_and_states() nullptr, &ps_rgba8_to_preview_))) return false; - if (FAILED(D3DCompile(g_ps_composite_overlay_fp16, strlen(g_ps_composite_overlay_fp16), - nullptr, nullptr, nullptr, - "main", "ps_5_0", 0, 0, &psb7, &err))) - return false; - if (FAILED(d3d_->CreatePixelShader(psb7->GetBufferPointer(), - psb7->GetBufferSize(), - nullptr, - &ps_composite_overlay_fp16_))) - return false; - // Fullscreen quad (two triangles) struct V { @@ -869,32 +766,13 @@ bool SharedScenePipeline::create_shaders_and_states() bool SharedScenePipeline::ensure_rt_and_pipeline(int w, int h) { - const auto t0 = std::chrono::steady_clock::now(); - lastEnsureRtRebuilt_ = false; - lastEnsureRtReason_ = "reuse"; - const bool hasAllTargets = rt_fp16_ && rtv_fp16_ && srv_fp16_ && rt_scene_fp16_ && rtv_scene_fp16_ && srv_scene_fp16_ && rt_rgba_ && rtv_rgba_ && srv_rgba_ && - overlay_rgba_ && overlay_rtv_ && overlay_srv_ && - rt_stage_ && rt_scene_stage_fp16_ && d2d_bitmap_rt_; + rt_stage_; if (hasAllTargets && rt_w_ == w && rt_h_ == h) - { - const auto t1 = std::chrono::steady_clock::now(); - lastEnsureRtNs_ = (uint64_t)std::chrono::duration_cast(t1 - t0).count(); - totalEnsureRtNs_ += lastEnsureRtNs_; - ++ensureRtCalls_; return true; - } - - lastEnsureRtRebuilt_ = true; - if (!hasAllTargets) - lastEnsureRtReason_ = "missing-targets"; - else if (rt_w_ != w || rt_h_ != h) - lastEnsureRtReason_ = "size-change"; - else - lastEnsureRtReason_ = "unknown"; rt_fp16_.Reset(); rtv_fp16_.Reset(); @@ -905,12 +783,7 @@ bool SharedScenePipeline::ensure_rt_and_pipeline(int w, int h) rt_rgba_.Reset(); rtv_rgba_.Reset(); srv_rgba_.Reset(); - overlay_rgba_.Reset(); - overlay_rtv_.Reset(); - overlay_srv_.Reset(); rt_stage_.Reset(); - rt_scene_stage_fp16_.Reset(); - d2d_bitmap_rt_.Reset(); // 1) High precision intermediate target D3D11_TEXTURE2D_DESC td{}; @@ -935,7 +808,7 @@ bool SharedScenePipeline::ensure_rt_and_pipeline(int w, int h) // rt ???/?????????compute path ??UAV ????????? rt_uav_.Reset(); - // 2) Composited FP16 scene target (base FP16 + overlay) + // 2) Scene FP16 target used by preview and readback paths td.Format = DXGI_FORMAT_R16G16B16A16_FLOAT; td.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; if (FAILED(d3d_->CreateTexture2D(&td, nullptr, &rt_scene_fp16_))) @@ -955,188 +828,22 @@ bool SharedScenePipeline::ensure_rt_and_pipeline(int w, int h) if (FAILED(d3d_->CreateShaderResourceView(rt_rgba_.Get(), nullptr, &srv_rgba_))) return false; - // 4) Overlay texture for D2D/DWrite (premultiplied BGRA8) - if (FAILED(d3d_->CreateTexture2D(&td, nullptr, &overlay_rgba_))) - return false; - if (FAILED(d3d_->CreateRenderTargetView(overlay_rgba_.Get(), nullptr, &overlay_rtv_))) - return false; - if (FAILED(d3d_->CreateShaderResourceView(overlay_rgba_.Get(), nullptr, &overlay_srv_))) - return false; - - // 5) staging for readback + // 4) staging for readback td.BindFlags = 0; td.CPUAccessFlags = D3D11_CPU_ACCESS_READ; td.Usage = D3D11_USAGE_STAGING; if (FAILED(d3d_->CreateTexture2D(&td, nullptr, &rt_stage_))) return false; - td.Format = DXGI_FORMAT_R16G16B16A16_FLOAT; - if (FAILED(d3d_->CreateTexture2D(&td, nullptr, &rt_scene_stage_fp16_))) - return false; - - // 6) D2D target now stays on dedicated overlay texture, not the final preview/readback surface - ComPtr surf; - if (FAILED(overlay_rgba_->QueryInterface(IID_PPV_ARGS(&surf))) || !surf) - return false; - D2D1_BITMAP_PROPERTIES1 bp = {}; - bp.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; - bp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED; - bp.dpiX = 96.f; - bp.dpiY = 96.f; - bp.bitmapOptions = (D2D1_BITMAP_OPTIONS)(D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW); - bp.colorContext = nullptr; - - if (FAILED(d2d_ctx_->CreateBitmapFromDxgiSurface(surf.Get(), &bp, &d2d_bitmap_rt_))) - { - SSP_DBG("D2D CreateBitmapFromDxgiSurface", E_FAIL); - return false; - } - - d2d_ctx_->SetTarget(d2d_bitmap_rt_.Get()); - const bool ok = create_shaders_and_states(); if (ok) { rt_w_ = w; rt_h_ = h; } - const auto t1 = std::chrono::steady_clock::now(); - lastEnsureRtNs_ = (uint64_t)std::chrono::duration_cast(t1 - t0).count(); - totalEnsureRtNs_ += lastEnsureRtNs_; - ++ensureRtCalls_; return ok; } -bool SharedScenePipeline::gpu_overlay_text(const wchar_t *text, int frame_w, int frame_h) -{ - if (!text || !*text || !d2d_ctx_ || !dwrite_) - return true; - - d2d_ctx_->BeginDraw(); - d2d_ctx_->SetTransform(D2D1::Matrix3x2F::Identity()); - d2d_ctx_->Clear(D2D1::ColorF(0, 0, 0, 0)); - - ComPtr fmt; - HRESULT hr = dwrite_->CreateTextFormat( - L"Segoe UI", - nullptr, - DWRITE_FONT_WEIGHT_SEMI_BOLD, - DWRITE_FONT_STYLE_NORMAL, - DWRITE_FONT_STRETCH_NORMAL, - 16.0f, - L"en-us", - &fmt); - if (FAILED(hr)) - { - d2d_ctx_->EndDraw(); - return false; - } - - fmt->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING); - fmt->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR); - - float layoutWidth = static_cast(frame_w) - 32.0f; - if (layoutWidth < 100.0f) - layoutWidth = 100.0f; - float layoutHeight = 100.0f; - - ComPtr layout; - hr = dwrite_->CreateTextLayout( - text, - (UINT32)wcslen(text), - fmt.Get(), - layoutWidth, - layoutHeight, - &layout); - if (FAILED(hr)) - { - d2d_ctx_->EndDraw(); - return false; - } - - DWRITE_TEXT_METRICS metrics{}; - hr = layout->GetMetrics(&metrics); - if (FAILED(hr)) - { - d2d_ctx_->EndDraw(); - return false; - } - - float textWidth = metrics.width; - float textHeight = metrics.height; - const float padX = 12.0f; - const float padY = 6.0f; - - D2D1_RECT_F bg = D2D1::RectF( - 8.0f, - 8.0f, - 8.0f + textWidth + padX * 2.0f, - 8.0f + textHeight + padY * 2.0f); - - if (d2d_black_) - d2d_ctx_->FillRectangle(bg, d2d_black_.Get()); - - D2D1_RECT_F rc = D2D1::RectF( - bg.left + padX, - bg.top + padY, - bg.right - padX, - bg.bottom - padY); - - if (d2d_white_) - d2d_ctx_->DrawText( - text, - (UINT32)wcslen(text), - fmt.Get(), - rc, - d2d_white_.Get()); - - hr = d2d_ctx_->EndDraw(); - return SUCCEEDED(hr); -} - -bool SharedScenePipeline::composite_overlay_to_scene_fp16(int frame_w, int frame_h) -{ - if (!rtv_scene_fp16_ || !srv_fp16_ || !overlay_srv_ || !vs_ || !ps_composite_overlay_fp16_ || !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_scene_fp16_.Get(); - ctx_->OMSetRenderTargets(1, &rtv, nullptr); - - D3D11_VIEWPORT vp{}; - vp.TopLeftX = 0.0f; - vp.TopLeftY = 0.0f; - vp.Width = static_cast(frame_w); - vp.Height = static_cast(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_scene_fp16_.Get(), clear); - - ctx_->VSSetShader(vs_.Get(), nullptr, 0); - ctx_->PSSetShader(ps_composite_overlay_fp16_.Get(), nullptr, 0); - - ID3D11ShaderResourceView *srvs[2] = {srv_fp16_.Get(), overlay_srv_.Get()}; - ctx_->PSSetShaderResources(0, 2, srvs); - - ID3D11SamplerState *ss = samp_.Get(); - ctx_->PSSetSamplers(0, 1, &ss); - - ctx_->Draw(6, 0); - - ID3D11ShaderResourceView *nullSrv[2] = {nullptr, nullptr}; - ctx_->PSSetShaderResources(0, 2, nullSrv); - - return true; -} - bool SharedScenePipeline::blit_fp16_to_rgba8(int frame_w, int frame_h) { if (!rtv_rgba_ || !srv_scene_fp16_ || !vs_ || !ps_fp16_to_rgba8_ || !ctx_) @@ -1180,62 +887,6 @@ bool SharedScenePipeline::blit_fp16_to_rgba8(int frame_w, int frame_h) return true; } -bool SharedScenePipeline::upload_argb_frame(const void *data, int frame_w, int frame_h, int src_stride) -{ - if (!data || !ctx_ || !rt_rgba_ || frame_w <= 0 || frame_h <= 0 || src_stride <= 0) - return false; - - D3D11_BOX box{}; - box.left = 0; - box.top = 0; - box.front = 0; - box.right = (UINT)frame_w; - box.bottom = (UINT)frame_h; - box.back = 1; - - ctx_->UpdateSubresource(rt_rgba_.Get(), 0, &box, data, (UINT)src_stride, 0); - return true; -} - -bool SharedScenePipeline::render_uploaded_argb_to_fp16(int frame_w, int frame_h) -{ - if (!ctx_ || !vs_ || !il_ || !vb_ || !rtv_fp16_ || !srv_rgba_ || !ps_rgba8_to_preview_ || frame_w <= 0 || frame_h <= 0) - 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()); - - ctx_->VSSetShader(vs_.Get(), nullptr, 0); - ctx_->PSSetShader(ps_rgba8_to_preview_.Get(), nullptr, 0); - - D3D11_VIEWPORT vp{}; - vp.TopLeftX = 0.0f; - vp.TopLeftY = 0.0f; - vp.Width = static_cast(frame_w); - vp.Height = static_cast(frame_h); - vp.MinDepth = 0.0f; - vp.MaxDepth = 1.0f; - ctx_->RSSetViewports(1, &vp); - - ID3D11RenderTargetView *rtv = rtv_fp16_.Get(); - ctx_->OMSetRenderTargets(1, &rtv, nullptr); - const float clear[4] = {0, 0, 0, 1}; - ctx_->ClearRenderTargetView(rtv_fp16_.Get(), clear); - - ID3D11ShaderResourceView *srv = srv_rgba_.Get(); - ctx_->PSSetShaderResources(0, 1, &srv); - ID3D11SamplerState *ss = samp_.Get(); - ctx_->PSSetSamplers(0, 1, &ss); - ctx_->Draw(6, 0); - - ID3D11ShaderResourceView *nullSrv = nullptr; - ctx_->PSSetShaderResources(0, 1, &nullSrv); - return true; -} - bool SharedScenePipeline::upload_nv12_frame(const uint8_t *y, int stride_y, const uint8_t *uv, int stride_uv, int frame_w, int frame_h) { if (!d3d_ || !ctx_ || !y || !uv || frame_w <= 0 || frame_h <= 0 || stride_y <= 0 || stride_uv <= 0) @@ -1448,99 +1099,6 @@ bool SharedScenePipeline::upload_y210_frame(const uint8_t *data, int src_stride, return true; } -bool SharedScenePipeline::upload_v210_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h) -{ - if (!ctx_ || !d3d_ || !data || frame_w <= 0 || frame_h <= 0) - return false; - - const int packedStride = ((frame_w + 5) / 6) * 16; - const int effectiveStride = (src_stride > 0) ? src_stride : packedStride; - if (effectiveStride < packedStride) - return false; - - const int w2 = (frame_w + 1) / 2; - if (upload_y210_packed_) - { - D3D11_TEXTURE2D_DESC desc{}; - upload_y210_packed_->GetDesc(&desc); - if ((int)desc.Width != w2 || (int)desc.Height != frame_h || desc.Format != DXGI_FORMAT_R16G16B16A16_UINT) - upload_y210_packed_.Reset(); - } - - if (!upload_y210_packed_) - { - D3D11_TEXTURE2D_DESC td{}; - td.Width = (UINT)w2; - td.Height = (UINT)frame_h; - td.MipLevels = 1; - td.ArraySize = 1; - td.SampleDesc.Count = 1; - td.Format = DXGI_FORMAT_R16G16B16A16_UINT; - td.Usage = D3D11_USAGE_DYNAMIC; - td.BindFlags = D3D11_BIND_SHADER_RESOURCE; - td.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - if (FAILED(d3d_->CreateTexture2D(&td, nullptr, &upload_y210_packed_))) - return false; - } - - D3D11_MAPPED_SUBRESOURCE m{}; - if (FAILED(ctx_->Map(upload_y210_packed_.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &m))) - return false; - - for (int row = 0; row < frame_h; ++row) - { - const uint8_t *srcRow = data + (size_t)row * (size_t)effectiveStride; - uint8_t *dstRow = static_cast(m.pData) + (size_t)row * (size_t)m.RowPitch; - uint16_t *dst16 = reinterpret_cast(dstRow); - - for (int x = 0; x < frame_w; x += 6) - { - uint32_t words[4] = {}; - std::memcpy(words, srcRow + (size_t)(x / 6) * 16u, sizeof(words)); - - const uint16_t u0 = v210_component_for_upload(words[0], 0); - const uint16_t y0 = v210_component_for_upload(words[0], 10); - const uint16_t v0 = v210_component_for_upload(words[0], 20); - const uint16_t y1 = v210_component_for_upload(words[1], 0); - const uint16_t u2 = v210_component_for_upload(words[1], 10); - const uint16_t y2 = v210_component_for_upload(words[1], 20); - const uint16_t v2 = v210_component_for_upload(words[2], 0); - const uint16_t y3 = v210_component_for_upload(words[2], 10); - const uint16_t u4 = v210_component_for_upload(words[2], 20); - const uint16_t y4 = v210_component_for_upload(words[3], 0); - const uint16_t v4 = v210_component_for_upload(words[3], 10); - const uint16_t y5 = v210_component_for_upload(words[3], 20); - - uint16_t *d0 = dst16 + (size_t)(x / 2) * 4u; - d0[0] = y0; - d0[1] = u0; - d0[2] = (x + 1 < frame_w) ? y1 : y0; - d0[3] = v0; - - if (x + 2 < frame_w) - { - uint16_t *d1 = dst16 + (size_t)((x + 2) / 2) * 4u; - d1[0] = y2; - d1[1] = u2; - d1[2] = (x + 3 < frame_w) ? y3 : y2; - d1[3] = v2; - } - - if (x + 4 < frame_w) - { - uint16_t *d2 = dst16 + (size_t)((x + 4) / 2) * 4u; - d2[0] = y4; - d2[1] = u4; - d2[2] = (x + 5 < frame_w) ? y5 : y4; - d2[3] = v4; - } - } - } - - ctx_->Unmap(upload_y210_packed_.Get(), 0); - return true; -} - bool SharedScenePipeline::render_uploaded_yuv_to_fp16(gvfg_render_pixfmt_t fmt, int frame_w, int frame_h) { if (!ctx_ || !vs_ || !il_ || !vb_ || !rtv_fp16_ || !rt_fp16_ || frame_w <= 0 || frame_h <= 0) @@ -1692,382 +1250,6 @@ bool SharedScenePipeline::render_uploaded_yuv_to_fp16(gvfg_render_pixfmt_t fmt, return true; } -namespace -{ - - static inline uint16_t ssp_float_to_10bit(float v) - { - if (v < 0.0f) - v = 0.0f; - if (v > 1.0f) - v = 1.0f; - return static_cast(std::lround(v * 1023.0f)); - } - - static inline uint16_t ssp_expand_10_to_16(uint16_t v10) - { - v10 = static_cast(std::min(v10, 1023u)); - return static_cast((v10 << 6) | (v10 >> 4)); - } - - static inline uint8_t ssp_float_to_8bit(float v) - { - if (v < 0.0f) - v = 0.0f; - if (v > 1.0f) - v = 1.0f; - return static_cast(std::lround(v * 255.0f)); - } - - static bool ssp_write_gigabyte_raw_file(const std::wstring &path, - int w, - int h, - const char *format, - int sourceBitDepth, - const void *payload, - size_t payloadBytes) - { - if (path.empty() || !format || !*format || !payload || payloadBytes == 0) - return false; - - char header[GVFG_RENDER_GIGABYTE_RAW_HEADER_SIZE] = {}; - std::snprintf(header, sizeof(header), - "GIGABYTE_RAW\n" - "header_size=%d\n" - "Width=%d\n" - "Height=%d\n" - "Format=%s\n" - "SourceBitDepth=%d\n", - GVFG_RENDER_GIGABYTE_RAW_HEADER_SIZE, - w, - h, - format, - sourceBitDepth); - - std::ofstream ofs(std::filesystem::path(path), std::ios::binary); - if (!ofs) - return false; - ofs.write(header, static_cast(sizeof(header))); - ofs.write(reinterpret_cast(payload), static_cast(payloadBytes)); - return ofs.good(); - } - - static bool ssp_write_fp16_gigabyte_raw(const std::wstring &path, int w, int h, int sourceBitDepth, const std::vector &rgba16f) - { - if (w <= 0 || h <= 0 || rgba16f.size() < static_cast(w) * static_cast(h) * 4u) - return false; - const size_t payloadBytes = rgba16f.size() * sizeof(uint16_t); - return ssp_write_gigabyte_raw_file(path, w, h, "RGBA16F", sourceBitDepth, rgba16f.data(), payloadBytes); - } - - static bool ssp_write_rgb10_gigabyte_raw(const std::wstring &path, int w, int h, int sourceBitDepth, const std::vector &rgb10) - { - if (w <= 0 || h <= 0 || rgb10.size() < static_cast(w) * static_cast(h) * 3u) - return false; - const size_t payloadBytes = rgb10.size() * sizeof(uint16_t); - return ssp_write_gigabyte_raw_file(path, w, h, "RGB10_U16", sourceBitDepth, rgb10.data(), payloadBytes); - } - - static bool ssp_write_bgra8_gigabyte_raw(const std::wstring &path, int w, int h, int sourceBitDepth, const std::vector &bgra8) - { - if (w <= 0 || h <= 0 || bgra8.size() < static_cast(w) * static_cast(h) * 4u) - return false; - return ssp_write_gigabyte_raw_file(path, w, h, "BGRA8", sourceBitDepth, bgra8.data(), bgra8.size()); - } - - static bool ssp_write_abgr2101010_gigabyte_raw(const std::wstring &path, int w, int h, int sourceBitDepth, const std::vector &abgr2101010) - { - if (w <= 0 || h <= 0 || abgr2101010.size() < static_cast(w) * static_cast(h)) - return false; - const size_t payloadBytes = abgr2101010.size() * sizeof(uint32_t); - return ssp_write_gigabyte_raw_file(path, w, h, "ABGR2101010", sourceBitDepth, abgr2101010.data(), payloadBytes); - } - - static bool ssp_write_rgba16_expanded_gigabyte_raw(const std::wstring &path, int w, int h, int sourceBitDepth, const std::vector &rgb10) - { - if (w <= 0 || h <= 0 || rgb10.size() < static_cast(w) * static_cast(h) * 3u) - return false; - - std::vector rgba; - const size_t pixelCount = static_cast(w) * static_cast(h); - rgba.resize(pixelCount * 4u); - for (size_t i = 0; i < pixelCount; ++i) - { - rgba[i * 4u + 0u] = ssp_expand_10_to_16(rgb10[i * 3u + 0u]); - rgba[i * 4u + 1u] = ssp_expand_10_to_16(rgb10[i * 3u + 1u]); - rgba[i * 4u + 2u] = ssp_expand_10_to_16(rgb10[i * 3u + 2u]); - rgba[i * 4u + 3u] = 0xFFFFu; - } - - const size_t payloadBytes = rgba.size() * sizeof(uint16_t); - return ssp_write_gigabyte_raw_file(path, w, h, "RGBA16", sourceBitDepth, rgba.data(), payloadBytes); - } - - static bool ssp_write_fp16_raw(const std::wstring &path, int w, int h, const std::vector &rgba16f) - { - if (w <= 0 || h <= 0 || rgba16f.size() < static_cast(w) * static_cast(h) * 4u) - return false; - - // No header. Payload: R16F G16F B16F A16F, little-endian. - std::ofstream ofs(std::filesystem::path(path), std::ios::binary); - if (!ofs) - return false; - ofs.write(reinterpret_cast(rgba16f.data()), static_cast(rgba16f.size() * sizeof(uint16_t))); - return ofs.good(); - } - - static bool ssp_write_rgb10_raw_value(const std::wstring &path, int w, int h, const std::vector &rgb10) - { - if (w <= 0 || h <= 0 || rgb10.size() < static_cast(w) * static_cast(h) * 3u) - return false; - - // No header. Payload: R16 G16 B16, little-endian, valid value 0..1023. - std::ofstream ofs(std::filesystem::path(path), std::ios::binary); - if (!ofs) - return false; - ofs.write(reinterpret_cast(rgb10.data()), static_cast(rgb10.size() * sizeof(uint16_t))); - return ofs.good(); - } - - static bool ssp_write_bgra8_raw_value(const std::wstring &path, int w, int h, const std::vector &bgra8) - { - if (w <= 0 || h <= 0 || bgra8.size() < static_cast(w) * static_cast(h) * 4u) - return false; - - // No header. Payload: B8 G8 R8 A8, 4 bytes per pixel. - // This matches DXGI_FORMAT_B8G8R8A8_UNORM preview backbuffer layout. - std::ofstream ofs(std::filesystem::path(path), std::ios::binary); - if (!ofs) - return false; - ofs.write(reinterpret_cast(bgra8.data()), static_cast(bgra8.size())); - return ofs.good(); - } - - static bool ssp_write_rgba8_raw_value(const std::wstring &path, int w, int h, const std::vector &bgra8) - { - if (w <= 0 || h <= 0 || bgra8.size() < static_cast(w) * static_cast(h) * 4u) - return false; - - std::vector rgba8; - const size_t pixelCount = static_cast(w) * static_cast(h); - rgba8.resize(pixelCount * 4u); - for (size_t i = 0; i < pixelCount; ++i) - { - rgba8[i * 4u + 0u] = bgra8[i * 4u + 2u]; - rgba8[i * 4u + 1u] = bgra8[i * 4u + 1u]; - rgba8[i * 4u + 2u] = bgra8[i * 4u + 0u]; - rgba8[i * 4u + 3u] = bgra8[i * 4u + 3u]; - } - - std::ofstream ofs(std::filesystem::path(path), std::ios::binary); - if (!ofs) - return false; - ofs.write(reinterpret_cast(rgba8.data()), static_cast(rgba8.size())); - return ofs.good(); - } - - static bool ssp_write_abgr2101010_raw_value(const std::wstring &path, int w, int h, const std::vector &abgr2101010) - { - if (w <= 0 || h <= 0 || abgr2101010.size() < static_cast(w) * static_cast(h)) - return false; - - // No header. Payload: 4 bytes per pixel, little-endian packed 10-bit RGB. - // This matches the preview backbuffer DXGI_FORMAT_R10G10B10A2_UNORM bit layout: - // bits 0.. 9 = R, bits 10..19 = G, bits 20..29 = B, bits 30..31 = A. - // PixelViewer names the same low-to-high layout as ABGR_2101010 because - // reading the 32-bit word from high bits to low bits is A2 B10 G10 R10. - std::ofstream ofs(std::filesystem::path(path), std::ios::binary); - if (!ofs) - return false; - ofs.write(reinterpret_cast(abgr2101010.data()), static_cast(abgr2101010.size() * sizeof(uint32_t))); - return ofs.good(); - } - - static bool ssp_write_rgba16_expanded_raw(const std::wstring &path, int w, int h, const std::vector &rgb10) - { - if (w <= 0 || h <= 0 || rgb10.size() < static_cast(w) * static_cast(h) * 3u) - return false; - - // No header. Payload: R16 G16 B16 A16, little-endian. - // RGB is expanded from 10-bit 0..1023 to 16-bit 0..65535 for RAW viewers. - std::vector rgba; - const size_t pixelCount = static_cast(w) * static_cast(h); - rgba.resize(pixelCount * 4u); - for (size_t i = 0; i < pixelCount; ++i) - { - rgba[i * 4u + 0u] = ssp_expand_10_to_16(rgb10[i * 3u + 0u]); - rgba[i * 4u + 1u] = ssp_expand_10_to_16(rgb10[i * 3u + 1u]); - rgba[i * 4u + 2u] = ssp_expand_10_to_16(rgb10[i * 3u + 2u]); - rgba[i * 4u + 3u] = 0xFFFFu; - } - - std::ofstream ofs(std::filesystem::path(path), std::ios::binary); - if (!ofs) - return false; - ofs.write(reinterpret_cast(rgba.data()), static_cast(rgba.size() * sizeof(uint16_t))); - return ofs.good(); - } - - static bool ssp_write_rgb10_stats(const std::wstring &path, int w, int h, int sourceBitDepth, const std::vector &rgb10) - { - if (rgb10.empty()) - return false; - uint16_t minV[3] = {1023, 1023, 1023}; - uint16_t maxV[3] = {0, 0, 0}; - bool anyGt255 = false; - bool bins[3][1024] = {}; - for (size_t i = 0; i + 2 < rgb10.size(); i += 3) - { - for (int c = 0; c < 3; ++c) - { - uint16_t v = rgb10[i + c]; - minV[c] = (std::min)(minV[c], v); - maxV[c] = (std::max)(maxV[c], v); - if (v > 255) - anyGt255 = true; - bins[c][v] = true; - } - } - int unique[3] = {0, 0, 0}; - for (int c = 0; c < 3; ++c) - for (bool hit : bins[c]) - if (hit) - ++unique[c]; - std::ofstream ofs{std::filesystem::path(path)}; - if (!ofs) - return false; - ofs << "Width=" << w << "\n"; - ofs << "Height=" << h << "\n"; - ofs << "SourceBitDepth=" << sourceBitDepth << "\n"; - ofs << "Files=_abgr2101010.raw, _gigabyte_abgr2101010.raw, _rgb10.raw, .tiff, .png, .stats.txt\n"; - ofs << "NativeRAW=_abgr2101010.raw, DXGI R10G10B10A2 layout, little-endian uint32 per pixel\n"; - ofs << "GigabyteRAW=_gigabyte_abgr2101010.raw, 128-byte ASCII GIGABYTE_RAW header + same native payload\n"; - ofs << "HexRGB10=_rgb10.raw, little-endian uint16 R G B values per pixel, valid range 0..1023, no header\n"; - ofs << "R min=" << minV[0] << " max=" << maxV[0] << " unique=" << unique[0] << "\n"; - ofs << "G min=" << minV[1] << " max=" << maxV[1] << " unique=" << unique[1] << "\n"; - ofs << "B min=" << minV[2] << " max=" << maxV[2] << " unique=" << unique[2] << "\n"; - ofs << "Any value > 255=" << (anyGt255 ? "YES" : "NO") << "\n"; - ofs << "MatchesPreviewSwapchain=DXGI_FORMAT_R10G10B10A2_UNORM via _abgr2101010.raw\n"; - ofs << "ABGR2101010 raw is for PixelViewer: choose ABGR_2101010 + Little-Endian\n"; - ofs << "DXGI bit layout=bits 0-9 R, 10-19 G, 20-29 B, 30-31 A; alpha fixed to 3\n"; - return ofs.good(); - } - - static bool ssp_write_bgra8_stats(const std::wstring &path, int w, int h, int sourceBitDepth, const std::vector &bgra8) - { - if (bgra8.empty()) - return false; - uint8_t minV[3] = {255, 255, 255}; - uint8_t maxV[3] = {0, 0, 0}; - bool bins[3][256] = {}; - for (size_t i = 0; i + 3 < bgra8.size(); i += 4) - { - const uint8_t r = bgra8[i + 2u]; - const uint8_t g = bgra8[i + 1u]; - const uint8_t b = bgra8[i + 0u]; - const uint8_t v[3] = {r, g, b}; - for (int c = 0; c < 3; ++c) - { - minV[c] = (std::min)(minV[c], v[c]); - maxV[c] = (std::max)(maxV[c], v[c]); - bins[c][v[c]] = true; - } - } - int unique[3] = {0, 0, 0}; - for (int c = 0; c < 3; ++c) - for (bool hit : bins[c]) - if (hit) - ++unique[c]; - std::ofstream ofs{std::filesystem::path(path)}; - if (!ofs) - return false; - ofs << "Width=" << w << "\n"; - ofs << "Height=" << h << "\n"; - ofs << "SourceBitDepth=" << sourceBitDepth << "\n"; - ofs << "Files=_bgra8.raw, _gigabyte_bgra8.raw, _rgba8.raw, .tiff, .png, .stats.txt\n"; - ofs << "NativeRAW=_bgra8.raw, B8 G8 R8 A8 byte order, 4 bytes per pixel, no header\n"; - ofs << "GigabyteRAW=_gigabyte_bgra8.raw, 128-byte ASCII GIGABYTE_RAW header + same native payload\n"; - ofs << "HexRGBA=_rgba8.raw, R8 G8 B8 A8 byte order, 4 bytes per pixel, no header\n"; - ofs << "MatchesPreviewSwapchain=DXGI_FORMAT_B8G8R8A8_UNORM\n"; - ofs << "R min=" << static_cast(minV[0]) << " max=" << static_cast(maxV[0]) << " unique=" << unique[0] << "\n"; - ofs << "G min=" << static_cast(minV[1]) << " max=" << static_cast(maxV[1]) << " unique=" << unique[1] << "\n"; - ofs << "B min=" << static_cast(minV[2]) << " max=" << static_cast(maxV[2]) << " unique=" << unique[2] << "\n"; - ofs << "Any value > 255=NO\n"; - return ofs.good(); - } - - static bool ssp_write_rgb16_tiff(const std::wstring &path, int w, int h, const std::vector &rgb10) - { - HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); - const bool needUninit = SUCCEEDED(hr); - IWICImagingFactory *factory = nullptr; - IWICBitmapEncoder *encoder = nullptr; - IWICStream *stream = nullptr; - IWICBitmapFrameEncode *frame = nullptr; - IPropertyBag2 *bag = nullptr; - bool ok = false; - do - { - hr = CoCreateInstance(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&factory)); - if (FAILED(hr) || !factory) - break; - hr = factory->CreateStream(&stream); - if (FAILED(hr) || !stream) - break; - hr = stream->InitializeFromFilename(path.c_str(), GENERIC_WRITE); - if (FAILED(hr)) - break; - hr = factory->CreateEncoder(GUID_ContainerFormatTiff, nullptr, &encoder); - if (FAILED(hr) || !encoder) - break; - hr = encoder->Initialize(stream, WICBitmapEncoderNoCache); - if (FAILED(hr)) - break; - hr = encoder->CreateNewFrame(&frame, &bag); - if (FAILED(hr) || !frame) - break; - hr = frame->Initialize(bag); - if (FAILED(hr)) - break; - hr = frame->SetSize(static_cast(w), static_cast(h)); - if (FAILED(hr)) - break; - WICPixelFormatGUID pf = GUID_WICPixelFormat48bppRGB; - hr = frame->SetPixelFormat(&pf); - if (FAILED(hr) || !IsEqualGUID(pf, GUID_WICPixelFormat48bppRGB)) - break; - std::vector rgb16(rgb10.size()); - for (size_t i = 0; i < rgb10.size(); ++i) - rgb16[i] = static_cast((static_cast(rgb10[i]) * 65535u + 511u) / 1023u); - const UINT stride = static_cast(w * 3 * sizeof(uint16_t)); - const UINT imageSize = static_cast(rgb16.size() * sizeof(uint16_t)); - hr = frame->WritePixels(static_cast(h), stride, imageSize, reinterpret_cast(rgb16.data())); - if (FAILED(hr)) - break; - hr = frame->Commit(); - if (FAILED(hr)) - break; - hr = encoder->Commit(); - if (FAILED(hr)) - break; - ok = true; - } while (false); - if (bag) - bag->Release(); - if (frame) - frame->Release(); - if (encoder) - encoder->Release(); - if (stream) - stream->Release(); - if (factory) - factory->Release(); - if (needUninit) - CoUninitialize(); - return ok; - } -} - bool SharedScenePipeline::copy_fp16_to_scene() { if (!ctx_ || !rt_fp16_ || !rt_scene_fp16_) @@ -2099,125 +1281,6 @@ bool SharedScenePipeline::readback_to_frame(int frame_w, int frame_h, uint64_t p return true; } -bool SharedScenePipeline::export_scene_rgb10(const wchar_t *base_path, int raw_flags, bool export_tiff, bool export_stats, bool export_gigabyte_raw) -{ - if (!base_path || !*base_path || !ctx_ || !rt_scene_stage_fp16_ || !rt_scene_fp16_ || rt_w_ <= 0 || rt_h_ <= 0) - return false; - - ctx_->CopyResource(rt_scene_stage_fp16_.Get(), rt_scene_fp16_.Get()); - D3D11_MAPPED_SUBRESOURCE m{}; - if (FAILED(ctx_->Map(rt_scene_stage_fp16_.Get(), 0, D3D11_MAP_READ, 0, &m))) - return false; - - const size_t pixelCount = static_cast(rt_w_) * static_cast(rt_h_); - std::vector rgba16f; - std::vector rgb10; - std::vector bgra8; - std::vector abgr2101010; - const bool sourceIs10Bit = (preview_source_bit_depth_ >= 10); - rgba16f.resize(pixelCount * 4u); - rgb10.resize(pixelCount * 3u); - bgra8.resize(pixelCount * 4u); - abgr2101010.resize(pixelCount); - for (int y = 0; y < rt_h_; ++y) - { - const uint8_t *srcRow = static_cast(m.pData) + static_cast(y) * static_cast(m.RowPitch); - const uint16_t *src = reinterpret_cast(srcRow); - for (int x = 0; x < rt_w_; ++x) - { - const size_t pixelIndex = static_cast(y) * static_cast(rt_w_) + static_cast(x); - const size_t si = static_cast(x) * 4u; - const size_t fpi = pixelIndex * 4u; - const size_t di = pixelIndex * 3u; - const size_t bi = pixelIndex * 4u; - - rgba16f[fpi + 0u] = src[si + 0u]; - rgba16f[fpi + 1u] = src[si + 1u]; - rgba16f[fpi + 2u] = src[si + 2u]; - rgba16f[fpi + 3u] = src[si + 3u]; - - const float r = DirectX::PackedVector::XMConvertHalfToFloat(src[si + 0u]); - const float g = DirectX::PackedVector::XMConvertHalfToFloat(src[si + 1u]); - const float b = DirectX::PackedVector::XMConvertHalfToFloat(src[si + 2u]); - const uint16_t r10 = ssp_float_to_10bit(r); - const uint16_t g10 = ssp_float_to_10bit(g); - const uint16_t b10 = ssp_float_to_10bit(b); - rgb10[di + 0u] = r10; - rgb10[di + 1u] = g10; - rgb10[di + 2u] = b10; - - bgra8[bi + 0u] = ssp_float_to_8bit(b); - bgra8[bi + 1u] = ssp_float_to_8bit(g); - bgra8[bi + 2u] = ssp_float_to_8bit(r); - bgra8[bi + 3u] = 255u; - - abgr2101010[pixelIndex] = - ((static_cast(r10) & 0x3FFu) << 0u) | - ((static_cast(g10) & 0x3FFu) << 10u) | - ((static_cast(b10) & 0x3FFu) << 20u) | - (3u << 30u); - } - } - ctx_->Unmap(rt_scene_stage_fp16_.Get(), 0); - - const bool exportNativeRaw = (raw_flags & GVFG_RENDER_EXPORT_RAW_NATIVE) != 0; - const bool exportRgb10Raw = (raw_flags & GVFG_RENDER_EXPORT_RAW_RGB10_U16) != 0; - const bool exportRgba16Raw = (raw_flags & GVFG_RENDER_EXPORT_RAW_RGBA16) != 0; - const bool exportRgba8Raw = (raw_flags & GVFG_RENDER_EXPORT_RAW_RGBA8) != 0; - const bool exportFp16Raw = sourceIs10Bit && (raw_flags & GVFG_RENDER_EXPORT_RAW_ALL) == GVFG_RENDER_EXPORT_RAW_ALL; - const std::wstring base(base_path); - bool ok = true; - if (raw_flags != 0) - { - if (sourceIs10Bit) - { - if (exportFp16Raw) - ok = ssp_write_fp16_raw(base + L"_fp16_rgba16f.raw", rt_w_, rt_h_, rgba16f) && ok; - if (exportRgb10Raw) - ok = ssp_write_rgb10_raw_value(base + L"_rgb10.raw", rt_w_, rt_h_, rgb10) && ok; - if (exportNativeRaw) - ok = ssp_write_abgr2101010_raw_value(base + L"_abgr2101010.raw", rt_w_, rt_h_, abgr2101010) && ok; - if (exportRgba16Raw) - ok = ssp_write_rgba16_expanded_raw(base + L"_rgba16_expanded.raw", rt_w_, rt_h_, rgb10) && ok; - } - else - { - if (exportNativeRaw) - ok = ssp_write_bgra8_raw_value(base + L"_bgra8.raw", rt_w_, rt_h_, bgra8) && ok; - if (exportRgba8Raw) - ok = ssp_write_rgba8_raw_value(base + L"_rgba8.raw", rt_w_, rt_h_, bgra8) && ok; - } - } - if (export_gigabyte_raw) - { - const int sourceBitDepth = preview_source_bit_depth_ > 0 ? preview_source_bit_depth_ : (sourceIs10Bit ? 10 : 8); - if (sourceIs10Bit) - { - ok = ssp_write_abgr2101010_gigabyte_raw(base + L"_gigabyte_abgr2101010.raw", rt_w_, rt_h_, sourceBitDepth, abgr2101010) && ok; - } - else - { - ok = ssp_write_bgra8_gigabyte_raw(base + L"_gigabyte_bgra8.raw", rt_w_, rt_h_, sourceBitDepth, bgra8) && ok; - } - } - if (export_tiff) - ok = ssp_write_rgb16_tiff(base + L".tiff", rt_w_, rt_h_, rgb10) && ok; - if (export_stats) - { - const int sourceBitDepth = preview_source_bit_depth_ > 0 ? preview_source_bit_depth_ : (sourceIs10Bit ? 10 : 8); - ok = sourceIs10Bit - ? (ssp_write_rgb10_stats(base + L".stats.txt", rt_w_, rt_h_, sourceBitDepth, rgb10) && ok) - : (ssp_write_bgra8_stats(base + L".stats.txt", rt_w_, rt_h_, sourceBitDepth, bgra8) && ok); - } - - char msg[512] = {}; - std::snprintf(msg, sizeof(msg), - "[SharedScene] export_scene_rgb10 base=%ls size=%dx%d sourceBitDepth=%d exportAs=%s rawFlags=0x%x gigabyteRaw=%d tiff=%d stats=%d ok=%d", - base_path, rt_w_, rt_h_, preview_source_bit_depth_, sourceIs10Bit ? "abgr2101010" : "bgra8", raw_flags, export_gigabyte_raw ? 1 : 0, export_tiff ? 1 : 0, export_stats ? 1 : 0, ok ? 1 : 0); - ssp_log_text(msg); - return ok; -} - void SharedScenePipeline::release_preview_swapchain() { preview_rtv_.Reset(); diff --git a/sdk/gvfg/src/render/shared_scene_pipeline.h b/sdk/gvfg/src/render/shared_scene_pipeline.h index 7a19153..4fe8185 100644 --- a/sdk/gvfg/src/render/shared_scene_pipeline.h +++ b/sdk/gvfg/src/render/shared_scene_pipeline.h @@ -3,8 +3,6 @@ #include "../internal/gvfg_render_types.h" #include -#include -#include #include #include @@ -18,51 +16,32 @@ public: ~SharedScenePipeline() = default; bool initialize(ID3D11Device *d3d, - ID3D11DeviceContext *ctx, - ID2D1DeviceContext *d2d_ctx, - IDWriteFactory *dwrite = nullptr, - ID2D1SolidColorBrush *white = nullptr, - ID2D1SolidColorBrush *black = nullptr); - void shutdown(); + ID3D11DeviceContext *ctx); 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 rt_fp16_; Microsoft::WRL::ComPtr rtv_fp16_; @@ -81,7 +60,6 @@ public: Microsoft::WRL::ComPtr upload_y210_packed_; Microsoft::WRL::ComPtr rtv_rgba_; Microsoft::WRL::ComPtr rt_stage_; - Microsoft::WRL::ComPtr rt_scene_stage_fp16_; Microsoft::WRL::ComPtr cs_params_; Microsoft::WRL::ComPtr rt_uav_; @@ -93,20 +71,10 @@ public: Microsoft::WRL::ComPtr ps_y210_; Microsoft::WRL::ComPtr ps_fp16_to_rgba8_; Microsoft::WRL::ComPtr ps_fp16_to_preview_; - Microsoft::WRL::ComPtr ps_composite_overlay_fp16_; Microsoft::WRL::ComPtr il_; Microsoft::WRL::ComPtr vb_; Microsoft::WRL::ComPtr samp_; - Microsoft::WRL::ComPtr d2d_bitmap_rt_; - - Microsoft::WRL::ComPtr dwrite_; - Microsoft::WRL::ComPtr d2d_white_; - Microsoft::WRL::ComPtr d2d_black_; - Microsoft::WRL::ComPtr overlay_rgba_; - Microsoft::WRL::ComPtr overlay_rtv_; - Microsoft::WRL::ComPtr overlay_srv_; - void *preview_hwnd_ = nullptr; bool preview_enabled_ = false; bool preview_use_fp16_ = false; @@ -117,14 +85,8 @@ public: 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 preview_swapchain_; Microsoft::WRL::ComPtr preview_backbuf_;