Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion QuickView/CompositionEngine.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "pch.h"
#include "CompositionEngine.h"
#include "QuickViewETW.h"
#include "DebugMetrics.h"
#include <dxgi1_6.h>
#include "TileManager.h"
#include "TileTypes.h"
Expand Down Expand Up @@ -537,7 +539,7 @@ bool CompositionEngine::RefreshDisplayColorState(bool forceHdrSimulation) {
m_surfaceFormat = m_isAdvancedColor ? DXGI_FORMAT_R16G16B16A16_FLOAT : DXGI_FORMAT_B8G8R8A8_UNORM;

if (m_isAdvancedColor) {
OutputDebugStringW(L"[HDR] Advanced color active on current monitor. Using FP16 scRGB composition surfaces.\n");
QV_LOG("CompositionEngine_Log", TraceLoggingWideString(L"[HDR] Advanced color active on current monitor. Using FP16 scRGB composition surfaces.", "Message"));
}

return changed;
Expand Down
8 changes: 5 additions & 3 deletions QuickView/ComputeEngine.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "pch.h"
#include "QuickViewETW.h"
#include "DebugMetrics.h"
#include "ComputeEngine.h"
#include <d3dcompiler.h>
#include <algorithm>
Expand Down Expand Up @@ -653,19 +655,19 @@ HRESULT ComputeEngine::ComposeGainMap(
ID3D11Texture2D** outTexture)
{
if (!m_valid || !sdrPixels || !gainPixels || !outTexture) {
OutputDebugStringW(L"[ComputeEngine] ComposeGainMap: Invalid arguments or engine state.\n");
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(L"[ComputeEngine] ComposeGainMap: Invalid arguments or engine state.", "Message"));
return E_INVALIDARG;
}
if (sdrW <= 0 || sdrH <= 0 || gainW <= 0 || gainH <= 0) {
OutputDebugStringW(L"[ComputeEngine] ComposeGainMap: Invalid dimensions.\n");
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(L"[ComputeEngine] ComposeGainMap: Invalid dimensions.", "Message"));
return E_INVALIDARG;
}

// [Diagnostic] Log composition start
wchar_t logBuf[256];
swprintf_s(logBuf, L"[ComputeEngine] Compose: SDR %dx%d, Gain %dx%d, Headroom %.2f, MaxGain %.2f\n",
sdrW, sdrH, gainW, gainH, payload.targetHeadroom, payload.gainMapMax[0]);
OutputDebugStringW(logBuf);
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(logBuf, "Message"));

// 1. Upload SDR base layer (Can be BGRA8 or R32G32B32A32_FLOAT)
D3D11_TEXTURE2D_DESC sdrDesc = {};
Expand Down
132 changes: 67 additions & 65 deletions QuickView/HeavyLanePool.cpp

Large diffs are not rendered by default.

80 changes: 44 additions & 36 deletions QuickView/ImageEngine.cpp

Large diffs are not rendered by default.

118 changes: 60 additions & 58 deletions QuickView/ImageLoader.cpp

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions QuickView/QuickViewETW.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "pch.h"
#include "QuickViewETW.h"

// Define the "QuickView" ETW provider
// {YOUR-GUID-HERE-OR-AUTO-GENERATED-BY-MACRO}
// The macro automatically hashes the name "QuickView" to generate the GUID.
TRACELOGGING_DEFINE_PROVIDER(
g_hQuickViewProvider,
"QuickView",
(0xa3a9c9e8, 0x1d3a, 0x4d5b, 0xa1, 0x5d, 0x24, 0x98, 0xb7, 0x3d, 0x6e, 0x5a) // Explicit GUID generated via uuidgen or powershell [guid]::NewGuid()
);

namespace QuickView {
namespace Logging {
void Initialize() {
TraceLoggingRegister(g_hQuickViewProvider);
}

void Shutdown() {
TraceLoggingUnregister(g_hQuickViewProvider);
}
}
}
32 changes: 32 additions & 0 deletions QuickView/QuickViewETW.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <windows.h>
#include <TraceLoggingProvider.h>
#include "EditState.h" // For AppConfig g_config

// Declare the ETW provider
TRACELOGGING_DECLARE_PROVIDER(g_hQuickViewProvider);

namespace QuickView {
namespace Logging {
void Initialize();
void Shutdown();
}
}

// RAII scope for managing ETW lifecycle in main
struct EtwScope {
EtwScope() { QuickView::Logging::Initialize(); }
~EtwScope() { QuickView::Logging::Shutdown(); }
};

// Zero-overhead logging macro.
// Short-circuits completely if EnableDebugFeatures is false or the provider isn't listening.
extern AppConfig g_config;

#define QV_LOG(EventName, ...) \
do { \
if (g_config.EnableDebugFeatures && TraceLoggingProviderEnabled(g_hQuickViewProvider, 0, 0)) { \
TraceLoggingWrite(g_hQuickViewProvider, EventName, __VA_ARGS__); \
} \
} while(0)
6 changes: 4 additions & 2 deletions QuickView/RenderEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <vector>
#include <algorithm>
#include "RenderEngine.h"
#include "QuickViewETW.h"
#include "DebugMetrics.h"
#include "EditState.h"
#include "ImageTypes.h" // [Direct D2D] RawImageFrame
#include "ImageLoaderSimd.h"
Expand Down Expand Up @@ -656,7 +658,7 @@ CRenderEngine::UploadRawFrameToGPU(const QuickView::RawImageFrame &frame,

wchar_t dbg[256];
swprintf_s(dbg, L"[RenderEngine] GPU Bake Triggered (UltraHDR). Target Headroom: %.2f stops.\n", payload.targetHeadroom);
OutputDebugStringW(dbg);
QV_LOG("RenderEngine_Log", TraceLoggingWideString(dbg, "Message"));

ComPtr<ID3D11Texture2D> pBaked;
HRESULT hrBake = m_computeEngine->ComposeGainMap(
Expand Down Expand Up @@ -703,7 +705,7 @@ CRenderEngine::UploadRawFrameToGPU(const QuickView::RawImageFrame &frame,
wchar_t dbgUpload[256];
swprintf_s(dbgUpload, L"[RenderEngine] Upload: %dx%d, Format=%d, BlendOp=%d, AdvColor=%d\n",
(int)frame.width, (int)frame.height, (int)frame.format, (int)frame.blendOp, (int)m_isAdvancedColor);
OutputDebugStringW(dbgUpload);
QV_LOG("RenderEngine_Log", TraceLoggingWideString(dbgUpload, "Message"));

switch (frame.format) {
case QuickView::PixelFormat::BGRA8888:
Expand Down
8 changes: 5 additions & 3 deletions QuickView/TileManager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "pch.h"
#include "QuickViewETW.h"
#include "DebugMetrics.h"
#include "TileManager.h"
#include "SystemInfo.h"
#include <algorithm>
Expand Down Expand Up @@ -34,7 +36,7 @@ namespace QuickView {

wchar_t log[128];
swprintf_s(log, L"[TileManager] Aggressive Caching Enabled. Budget: %llu MB (%d tiles)\n", budget / (1024*1024), m_maxTiles);
OutputDebugStringW(log);
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(log, "Message"));
}

TileManager::~TileManager() {
Expand Down Expand Up @@ -133,7 +135,7 @@ namespace QuickView {
swprintf_s(skipBuf,
L"[TileManager] Skip trigger: zoom=%.4f base=%.4f img=%dx%d\n",
zoom, basePreviewRatio, imageW, imageH);
OutputDebugStringW(skipBuf);
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(skipBuf, "Message"));
}
// Not in tile mode: clear viewport progress source so UI doesn't show stale progress.
m_viewportTilesActive = false;
Expand Down Expand Up @@ -196,7 +198,7 @@ namespace QuickView {
wchar_t buf[256];
swprintf_s(buf, L"[TileManager] Update: LOD=%d Viewport=[%d, %d, %d, %d] Grid=[%d,%d] to [%d,%d]\n",
lod, viewport.x, viewport.y, viewport.w, viewport.h, startX, startY, endX, endY);
OutputDebugStringW(buf);
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(buf, "Message"));
}

std::vector<TileKey> missing;
Expand Down
32 changes: 17 additions & 15 deletions QuickView/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "QuickViewETW.h"
#include "pch.h"
#include "CoroutineTypes.h"
#include "CompositionEngine.h"
Expand Down Expand Up @@ -5761,7 +5762,7 @@ static HRESULT SafeFullDecodeFromMemory(const uint8_t* data, size_t size, QuickV
return InternalFullDecodeWrapper(data, size, outFrame);
} __except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION
? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
OutputDebugStringW(L"[Phase4] SEH: ACCESS_VIOLATION in FullDecodeFromMemory (caught)\n");
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(L"[Phase4] SEH: ACCESS_VIOLATION in FullDecodeFromMemory (caught)", "Message"));
return E_OUTOFMEMORY;
}
}
Expand Down Expand Up @@ -5934,6 +5935,7 @@ static void ForceForegroundWindow(HWND hwnd) {
}

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int nCmdShow) {
EtwScope etwScope;
// === Priority 0: Tool subprocess dispatch (must be first) ===
int toolExitCode = 0;
if (TryRunToolProcessFromCommandLine(&toolExitCode)) {
Expand Down Expand Up @@ -6396,7 +6398,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
auto nextFrame = g_imageResource.animator->GetNextFrame();
if (!nextFrame || !nextFrame->pixels) {
// EOF: Loop back to frame 0
OutputDebugStringW(L"[Anim] EOF reached, looping to frame 0\n");
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(L"[Anim] EOF reached, looping to frame 0", "Message"));
nextFrame = g_imageResource.animator->SeekToFrame(0);
}

Expand All @@ -6419,10 +6421,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
RenderImageToDComp(hwnd, g_imageResource, true);
RequestRepaint(PaintLayer::Image | PaintLayer::Dynamic);
} else {
OutputDebugStringW(L"[Anim] UploadRawFrameToGPU FAILED\n");
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(L"[Anim] UploadRawFrameToGPU FAILED", "Message"));
}
} else {
OutputDebugStringW(L"[Anim] SeekToFrame(0) also returned null, stopping\n");
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(L"[Anim] SeekToFrame(0) also returned null, stopping", "Message"));
KillTimer(hwnd, IDT_ANIMATION);
}
return 0;
Expand Down Expand Up @@ -8262,13 +8264,13 @@ SKIP_EDGE_NAV:;
case '3': g_slowMotionMode = !g_slowMotionMode; handled = true; break;
case '4':
g_showTileGrid = !g_showTileGrid;
OutputDebugStringW(g_showTileGrid ? L"Tile Grid: ON\n" : L"Tile Grid: OFF\n");
QV_LOG("Main_Log", TraceLoggingWideString(g_showTileGrid ? L"Tile Grid: ON" : L"Tile Grid: OFF", "Message"));
if (g_uiRenderer) g_uiRenderer->SetTileGridVisible(g_showTileGrid);
handled = true;
break;
case '5':
g_runtime.ForceHdrSimulation = !g_runtime.ForceHdrSimulation;
OutputDebugStringW(g_runtime.ForceHdrSimulation ? L"Force HDR Sim: ON\n" : L"Force HDR Sim: OFF\n");
QV_LOG("Main_Log", TraceLoggingWideString(g_runtime.ForceHdrSimulation ? L"Force HDR Sim: ON" : L"Force HDR Sim: OFF", "Message"));
handled = true;
// Re-evaluate display color state to trigger FP16/8-bit UNORM surface swap in CompositionEngine
RefreshDisplayColorPipeline(hwnd, false);
Expand Down Expand Up @@ -10196,7 +10198,7 @@ void ProcessEngineEvents(HWND hwnd) {

wchar_t debugBuf[256];
swprintf_s(debugBuf, L"[Main] AuxLayerReady: Gain Map applied via Auto-Gate and GPU Bake triggered\n");
OutputDebugStringW(debugBuf);
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(debugBuf, "Message"));
}
}
break;
Expand All @@ -10208,7 +10210,7 @@ void ProcessEngineEvents(HWND hwnd) {
wchar_t debugBuf[256];
swprintf_s(debugBuf, L"[Main] TileReady: LOD=%d (%d,%d) ID=%llu\n",
evt.tileCoord->lod, evt.tileCoord->col, evt.tileCoord->row, evt.imageId);
OutputDebugStringW(debugBuf);
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(debugBuf, "Message"));

if (g_imageEngine) {
// [Infinity Engine] TileManager already updated by ImageEngine::PollState
Expand All @@ -10219,7 +10221,7 @@ void ProcessEngineEvents(HWND hwnd) {
wchar_t debugBuf[256];
swprintf_s(debugBuf, L"[Main] TileReady IGNORED: MatchID=%d HasCoord=%d HasFrame=%d\n",
(evt.imageId == g_currentImageId.load()), evt.tileCoord.has_value(), (bool)evt.rawFrame);
OutputDebugStringW(debugBuf);
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(debugBuf, "Message"));
}
break;

Expand Down Expand Up @@ -10494,7 +10496,7 @@ static void PrimePhase1Placeholder(HWND hwnd, const std::wstring& path, ImageID
{
bool isTitan = g_isNavigatingToTitan;
if (!isTitan) {
OutputDebugStringW(L"[Phase1] Non-Titan: Skip Phase 1 completely.\n");
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(L"[Phase1] Non-Titan: Skip Phase 1 completely.", "Message"));
// [Fix] Do not apply skeleton. Leave current image intact for visual continuity.
// Do not update metadata early to avoid DComp scaling artifacts on the old layer.
return; // No Shell/WIC extraction and NO skeleton for non-Titan images
Expand Down Expand Up @@ -10628,7 +10630,7 @@ static FireAndForget RunPhase2DispatchLoop() {
if (task.imageId != g_currentImageId.load() ||
task.navToken != g_currentNavToken.load() ||
g_imagePath != task.path) {
OutputDebugStringW(L"[Phase2] QueueDispatch skipped stale task.\n");
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(L"[Phase2] QueueDispatch skipped stale task.", "Message"));
g_isPhase2Debouncing.store(false, std::memory_order_release);
co_await ResumeBackground{};
continue;
Expand All @@ -10640,7 +10642,7 @@ static FireAndForget RunPhase2DispatchLoop() {
static_cast<unsigned long long>(task.imageId),
static_cast<unsigned long long>(GetTickCount64() - task.enqueueTick),
task.navigatorIndex);
OutputDebugStringW(dbg);
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(dbg, "Message"));

DispatchNavigationToEngine(
task.path,
Expand Down Expand Up @@ -10697,7 +10699,7 @@ static void EnqueuePhase2NavigationTask(
static_cast<unsigned long long>(droppedId),
static_cast<unsigned long long>(droppedSerial),
static_cast<unsigned long long>(g_phase2DroppedNavTasks.load()));
OutputDebugStringW(dropBuf);
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(dropBuf, "Message"));
}

wchar_t pushBuf[256];
Expand All @@ -10707,7 +10709,7 @@ static void EnqueuePhase2NavigationTask(
static_cast<unsigned long long>(g_phase2NavSerial.load()),
static_cast<unsigned long>(kPhase2DebounceWindowMs),
navigatorIndex);
OutputDebugStringW(pushBuf);
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(pushBuf, "Message"));

g_isPhase2Debouncing.store(true, std::memory_order_release);

Expand Down Expand Up @@ -11317,7 +11319,7 @@ void OnPaint(HWND hwnd) {
previewW,
baseRatio,
absoluteZoom);
OutputDebugStringW(tileDbg);
QV_LOG("QuickView_GlobalLog", TraceLoggingWideString(tileDbg, "Message"));
}
g_imageEngine->UpdateTileViewport(vp, absoluteZoom, titanMeta.Width, titanMeta.Height, baseRatio, 0.0f, 0.0f);
lastVP = vp;
Expand Down
Loading