Rise
The Vieneo Province
Loading...
Searching...
No Matches
AdDiagnostics11.h
Go to the documentation of this file.
1#pragma once
2#include "ClientRenderer11.h"
4#include "../AdViewability.h"
5#include <DirectXMath.h>
6#include <deque>
7#include <thread>
8#include <mutex>
9#include <condition_variable>
10#include <atomic>
11
12namespace Rendering
13{
14 // Opt-in local prototype. RegisterDraw is inventory-neutral; the current
15 // adapters register vehicles and city signs. Query pools bound all GPU work.
17 {
18 public:
19 static constexpr unsigned MaximumCandidates = 16, RingSize = 3;
20 static constexpr unsigned MaximumReplayDraws = 256;
21 static constexpr unsigned MaximumCreatives = 64, MaximumCreativePixels = 1024*1024;
23 // One asynchronous texture copy, then bounded CPU analysis; nullptr means pending/unsupported.
24 const CreativeMetadata* PrepareCreative(RenderDevice& device, ID3D11ShaderResourceView* view);
25 struct Vertex { DirectX::XMFLOAT3 position, normal; DirectX::XMFLOAT2 uv, logo; };
26 AdDiagnostics11() = default;
28 void SetEnabled(bool value);
29 bool Enabled() const { return enabled; }
30 void SetOverlayVisible(bool value) { overlayVisible=value; }
31 bool OverlayVisible() const { return overlayVisible; }
32 bool Collecting() const { return collecting; }
33 void ResetResources();
34 void SyncPlacement(unsigned slot, uint64_t entity, const std::string& creative);
35 void BeginFrame(RenderDevice& device, double now, bool eligible, const char* blocker = nullptr);
36 void RegisterDraw(RenderDevice& device, const AdViewability::Placement& placement, unsigned slot,
37 Geometry11& geometry, unsigned first, unsigned count, unsigned material,
38 const DirectX::XMFLOAT4X4& world, const DirectX::XMFLOAT4X4& view,
39 const DirectX::XMFLOAT4X4& projection, float distanceKm);
40 // Retain actual dry-glass/HUD draws for a bounded opacity replay.
41 void RegisterSignDraw(RenderDevice& device, const AdViewability::Placement& placement,
42 const CreativeMetadata* metadata, const std::weak_ptr<void>& lifetime,
43 unsigned animationFrame, unsigned animationFrames, const AnimatedAdMetadata::Summary& average,
44 Geometry11& geometry, unsigned first, unsigned count, unsigned material,
45 const DirectX::XMFLOAT4X4& world, const DirectX::XMFLOAT4X4& view,
46 const DirectX::XMFLOAT4X4& projection, float distanceKm);
47 void SetAnimatedInventory(bool value) { animatedInventory=value; }
48 void RegisterOverlayDraw(RenderDevice& device, Geometry11& geometry, unsigned first, unsigned count, unsigned material);
49 // Capture the opaque scene BEFORE clouds alter its depth.
51 ID3D11RenderTargetView* CloudOpacityTarget() const { return collecting && sceneCaptured ? opacityTarget.Get() : nullptr; }
52 // Rain writes a conservative refraction mask in its existing geometry draw.
53 ID3D11RenderTargetView* WetGlassExclusionTarget() const { return collecting && sceneCaptured ? glassTarget.Get() : nullptr; }
54 void WetGlassResult(HRESULT result);
55 void FinishScene(RenderDevice& device, bool weatherMeasured, const std::vector<DirectX::XMFLOAT4>& uiRects, const char* uiBlocker = nullptr);
56 // Append the measured, clipped text bounds when preparing UI masks.
57 void DrawOverlay(RenderFont* font, RenderSprite* sprite, unsigned width, unsigned height,
58 std::vector<RECT>* drawnBounds = nullptr);
59 const AdViewability::Tracker& Results() const { return tracker; }
60 const std::string& Status() const { return status; }
61 const std::string& LogPath() const { return logPath; }
62 const std::string& Blocker() const { return frameBlocker; }
63 uint64_t Dropped() const { return dropped; }
64 private:
65 using Query = Microsoft::WRL::ComPtr<ID3D11Query>;
66 struct Facet
67 {
68 DirectX::XMFLOAT3 origin{}, u{}, v{}, normal{}, center{};
69 unsigned first = 0, count = 0, boundsFirst = 0, boundsCount = 0;
70 };
71 struct Patch
72 {
74 std::vector<Vertex> vertices, bounds;
75 DirectX::XMFLOAT3 origin{}, u{}, v{}, normal{};
76 std::vector<Facet> facets;
77 };
79 {
80 Geometry11* source = nullptr;
81 Microsoft::WRL::ComPtr<ID3D11Buffer> sourceBuffer;
82 uint64_t revision = 0;
83 unsigned first = 0, count = 0;
84 unsigned frontConvention = 0;
85 DirectX::XMFLOAT4 bounds{};
86 std::vector<std::shared_ptr<Patch>> patches;
87 };
88 struct Candidate
89 {
92 std::shared_ptr<Patch> patch;
94 unsigned material = 0, slot = 0;
95 uint64_t generation = 0;
96 std::weak_ptr<void> creativeLifetime;
97 double estimatedPixels = 0;
98 DirectX::XMFLOAT4 referenceTransform{1,0,0,0};
99 float referenceScale = 1;
100 std::vector<unsigned> frontFacets, angleFacets;
101 };
102 struct Frame
103 {
104 std::array<std::array<Query, 6>, MaximumCandidates> queries;
105 std::vector<Candidate> candidates;
106 double seconds = 0;
107 unsigned samples = 1;
108 uint64_t sequence = 0, eligibility = 0;
109 bool pending = false;
110 };
112 {
113 Microsoft::WRL::ComPtr<ID3D11Buffer> buffer;
114 Microsoft::WRL::ComPtr<ID3D11RasterizerState> raster;
116 D3D11_VIEWPORT viewport{};
117 std::vector<D3D11_RECT> scissors;
118 unsigned first = 0, count = 0, material = 0;
119 };
120 struct VehicleIdentity { uint64_t entity = 0, generation = 0; std::string creative; };
122 void Poll(RenderDevice& device, double now);
123 void RegisterPreparedDraw(RenderDevice& device, const AdViewability::Placement& placement,
124 unsigned slot, const CreativeMetadata* metadata, const std::weak_ptr<void>& lifetime,
125 unsigned animationFrame, unsigned animationFrames, const AnimatedAdMetadata::Summary& average,
126 Geometry11& geometry, unsigned first, unsigned count, unsigned program,
127 const DirectX::XMFLOAT4X4& world, const DirectX::XMFLOAT4X4& view,
128 const DirectX::XMFLOAT4X4& projection, float distanceKm);
129 std::vector<std::shared_ptr<Patch>>& Mesh(RenderDevice& device, Geometry11& geometry, unsigned first, unsigned count, const DirectX::XMFLOAT4& bounds, unsigned frontConvention=0);
131 {
132 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> view;
133 Microsoft::WRL::ComPtr<ID3D11Texture2D> staging;
135 unsigned row = 0, minX = UINT_MAX, minY = UINT_MAX, maxX = 0, maxY = 0;
136 double red = 0, green = 0, blue = 0, luminance = 0;
137 bool ready = false, failed = false, bgra = false, opaque = false, srgb = false;
138 };
139 std::deque<CachedCreative> creatives;
140 Microsoft::WRL::ComPtr<ID3D11Device> metadataDevice;
141 unsigned metadataBudget = 65536;
142 double metadataFrame = -1;
143 void Checkpoint(double now, bool force = false);
144 void LogWorker();
145 void StopLog();
146 struct Snapshot { std::string placements, creatives; };
147 bool enabled = false, collecting = false, eligible = false, overlayVisible = true, uiBlocked = false;
149 uint64_t sequence = 0, dropped = 0, eligibilityGeneration = 0;
150 unsigned nextFrame = 0;
151 std::vector<VehicleIdentity> vehicles;
152 std::array<Frame, RingSize> ring;
153 std::vector<Candidate> candidates;
154 std::vector<OverlayDraw> overlays;
155 std::string overlayFailure;
156 std::deque<CachedMesh> meshes;
158 Microsoft::WRL::ComPtr<ID3D11Device> native;
159 Microsoft::WRL::ComPtr<ID3DDeviceContextState> passState;
160 std::array<std::array<Program11, 4>, 4> programs;
161 std::array<Program11, 3> overlayPrograms;
162 Microsoft::WRL::ComPtr<ID3D11DepthStencilState> referenceDepth, visibleDepth;
163 Microsoft::WRL::ComPtr<ID3D11RasterizerState> raster;
164 Microsoft::WRL::ComPtr<ID3D11BlendState> noColor, opacityBlend;
166 Microsoft::WRL::ComPtr<ID3D11Texture2D> opacityTexture;
167 Microsoft::WRL::ComPtr<ID3D11RenderTargetView> opacityTarget;
168 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> opacityView;
169 Microsoft::WRL::ComPtr<ID3D11Texture2D> glassTexture;
170 Microsoft::WRL::ComPtr<ID3D11RenderTargetView> glassTarget;
171 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> glassView;
172 Microsoft::WRL::ComPtr<ID3D11RenderTargetView> sceneTarget;
173 D3D11_VIEWPORT viewport{};
174 bool sceneCaptured = false, wetGlassExcluded = false;
176 bool animatedInventory = false;
177 uint32_t samplingState = 0x51a7d123;
178 std::string status = "off", logPath, frameBlocker;
179 std::string overlayText;
184 std::thread writer;
185 std::mutex logMutex;
186 std::condition_variable logReady;
187 std::deque<Snapshot> snapshots;
188 bool logStop = false;
189 std::atomic<bool> logFailed{ false };
190 };
191}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
void RegisterSignDraw(RenderDevice &device, const AdViewability::Placement &placement, const CreativeMetadata *metadata, const std::weak_ptr< void > &lifetime, unsigned animationFrame, unsigned animationFrames, const AnimatedAdMetadata::Summary &average, Geometry11 &geometry, unsigned first, unsigned count, unsigned material, const DirectX::XMFLOAT4X4 &world, const DirectX::XMFLOAT4X4 &view, const DirectX::XMFLOAT4X4 &projection, float distanceKm)
AdViewability::Tracker tracker
const AdViewability::Tracker & Results() const
void SetAnimatedInventory(bool value)
static constexpr unsigned MaximumCreativePixels
std::vector< Candidate > candidates
Microsoft::WRL::ComPtr< ID3D11Device > metadataDevice
std::deque< Snapshot > snapshots
std::vector< VehicleIdentity > vehicles
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > opacityView
void DrawOverlay(RenderFont *font, RenderSprite *sprite, unsigned width, unsigned height, std::vector< RECT > *drawnBounds=nullptr)
void SyncPlacement(unsigned slot, uint64_t entity, const std::string &creative)
Microsoft::WRL::ComPtr< ID3D11Device > native
static constexpr unsigned MaximumReplayDraws
Microsoft::WRL::ComPtr< ID3D11BlendState > opacityBlend
Microsoft::WRL::ComPtr< ID3D11Texture2D > opacityTexture
Microsoft::WRL::ComPtr< ID3D11DepthStencilState > visibleDepth
Microsoft::WRL::ComPtr< ID3D11RenderTargetView > sceneTarget
void RegisterDraw(RenderDevice &device, const AdViewability::Placement &placement, unsigned slot, Geometry11 &geometry, unsigned first, unsigned count, unsigned material, const DirectX::XMFLOAT4X4 &world, const DirectX::XMFLOAT4X4 &view, const DirectX::XMFLOAT4X4 &projection, float distanceKm)
void WetGlassResult(HRESULT result)
std::vector< std::shared_ptr< Patch > > & Mesh(RenderDevice &device, Geometry11 &geometry, unsigned first, unsigned count, const DirectX::XMFLOAT4 &bounds, unsigned frontConvention=0)
const std::string & Blocker() const
std::deque< CachedCreative > creatives
HRESULT Initialize(RenderDevice &device)
void BeginFrame(RenderDevice &device, double now, bool eligible, const char *blocker=nullptr)
const std::string & Status() const
void RegisterOverlayDraw(RenderDevice &device, Geometry11 &geometry, unsigned first, unsigned count, unsigned material)
void Checkpoint(double now, bool force=false)
Microsoft::WRL::ComPtr< ID3D11RasterizerState > raster
Microsoft::WRL::ComPtr< ID3D11DepthStencilState > referenceDepth
void SetOverlayVisible(bool value)
std::condition_variable logReady
Microsoft::WRL::ComPtr< ID3D11RenderTargetView > glassTarget
ID3D11RenderTargetView * CloudOpacityTarget() const
std::array< std::array< Program11, 4 >, 4 > programs
static constexpr unsigned RingSize
AdCreativeMetadata CreativeMetadata
ID3D11RenderTargetView * WetGlassExclusionTarget() const
std::array< Frame, RingSize > ring
void RegisterPreparedDraw(RenderDevice &device, const AdViewability::Placement &placement, unsigned slot, const CreativeMetadata *metadata, const std::weak_ptr< void > &lifetime, unsigned animationFrame, unsigned animationFrames, const AnimatedAdMetadata::Summary &average, Geometry11 &geometry, unsigned first, unsigned count, unsigned program, const DirectX::XMFLOAT4X4 &world, const DirectX::XMFLOAT4X4 &view, const DirectX::XMFLOAT4X4 &projection, float distanceKm)
static constexpr unsigned MaximumCandidates
Microsoft::WRL::ComPtr< ID3D11Texture2D > glassTexture
const std::string & LogPath() const
std::deque< CachedMesh > meshes
std::array< Program11, 3 > overlayPrograms
void Poll(RenderDevice &device, double now)
void FinishScene(RenderDevice &device, bool weatherMeasured, const std::vector< DirectX::XMFLOAT4 > &uiRects, const char *uiBlocker=nullptr)
const CreativeMetadata * PrepareCreative(RenderDevice &device, ID3D11ShaderResourceView *view)
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > glassView
std::atomic< bool > logFailed
HRESULT CaptureScene(RenderDevice &device)
Microsoft::WRL::ComPtr< ID3D11BlendState > noColor
std::vector< OverlayDraw > overlays
static constexpr unsigned MaximumCreatives
Microsoft::WRL::ComPtr< ID3D11RenderTargetView > opacityTarget
Microsoft::WRL::ComPtr< ID3D11Query > Query
Microsoft::WRL::ComPtr< ID3DDeviceContextState > passState
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > view
Microsoft::WRL::ComPtr< ID3D11Texture2D > staging
std::vector< std::shared_ptr< Patch > > patches
Microsoft::WRL::ComPtr< ID3D11Buffer > sourceBuffer
AdViewability::Observation observation
std::vector< Candidate > candidates
std::array< std::array< Query, 6 >, MaximumCandidates > queries
Microsoft::WRL::ComPtr< ID3D11Buffer > buffer
Microsoft::WRL::ComPtr< ID3D11RasterizerState > raster