1#include "NativeUiTest11.h"
2#include "../Rendering/AdDiagnostics11.h"
3#include "../Rendering/CloudRenderer11.h"
4#include "../Rendering/WindshieldRain11.h"
5#include <iostream>
6#include <limits>
7
10using Microsoft::WRL::ComPtr;
12{
13 struct WindshieldRain11TestAccess
14 {
16 };
17}
18namespace
19{
20 unsigned checks=0;
21 void Check(bool value,const char* message){++checks;if(!value)throw std::runtime_error(message);}
22 void Model()
23 {
28 auto piecewise=good;piecewise.
anglePixels=15000;piecewise.pitch=70;
30 piecewise.anglePixels=14999;piecewise.clearPixels=14999;
32 piecewise=good;piecewise.
backFacing=
true;piecewise.referencePixels=0;
39 value.projectionInvalid=
true;Check(
Evaluate(value)==
Reason::Clipped,
"near-plane projection remains unsupported");
43 Check(!tracker.
Records().at(p).qualified,
"five observations span only .8 seconds");
45 Check(tracker.
Records().at(p).qualified,
"one continuous second qualifies");
46 Check(std::abs(tracker.
Records().at(p).qualifiedSeconds-1)<1e-8,
"initial second counted once");
48 Check(std::abs(tracker.
Records().at(p).qualifiedSeconds-1.2)<1e-8,
"additional exposure duration");
50 Check(tracker.
Records().at(p).continuousSeconds==0,
"obstruction resets streak");
53 Check(tracker.
Records().at(p).continuousSeconds==0,
"gap cannot earn time");
54 good.
seconds=2;Check(!tracker.
Observe(p,good),
"out of order result ignored");
55 good.
seconds=std::numeric_limits<double>::quiet_NaN();Check(!tracker.
Observe(p,good),
"invalid clock ignored");
58 Check(!tracker.
Records().at(newCreative).qualified,
"creative replacement starts fresh");
61 for(
int i=0;i<=150;++i){distantObservation.
seconds=i*.2;exposure.
Observe(p,distantObservation);}
62 const auto& distant=exposure.
Records().at(p);
63 Check(distant.reason==
Reason::TooSmall && !distant.qualified,
"small branding remains below the standard threshold");
64 Check(std::abs(distant.screenPercentageSeconds-1.5)<1e-8,"0.05 percent for 30 seconds is 1.5 screen-percentage-seconds");
65 Check(std::abs(distant.visibleSeconds-30)<1e-8 && distant.aboveMinimumScreenPercentageSeconds==0,
66 "small exposure earns visible time without earning the 1.5 percent metric");
67 Check(std::abs(distant.readableScreenPercentageSeconds-1.5)<1e-8 && std::abs(distant.angleScreenPercentageSeconds-1.5)<1e-8,
68 "quality areas are accumulated independently of the standard size cutoff");
69 const double before=distant.screenPercentageSeconds;
71 Check(exposure.
Records().at(p).screenPercentageSeconds==before,
"non-sampled foreground interruption cannot bridge exposure");
74 Check(exposure.
Records().at(p).screenPercentageSeconds==before,
"missing GPU observation cannot earn inferred exposure");
75 distantObservation.
seconds=31.2;exposure.
Observe(p,distantObservation);
76 Check(exposure.
Records().at(p).screenPercentageSeconds==before,
"large observation gap cannot earn area-time");
78 Check(exposure.
Records().at(p).screenPercentageSeconds==before,
"CPU admission estimates cannot earn exposure");
81 const auto& qualified=standard.
Records().at(p);
82 Check(std::abs(qualified.screenPercentageSeconds-1.5)<1e-8 &&
83 std::abs(qualified.aboveMinimumScreenPercentageSeconds-1.5)<1e-8 &&
84 std::abs(qualified.qualifiedScreenPercentageSeconds-1.5)<1e-8,"qualification backfills exactly the initial second of area-time");
86 Check(std::abs(standard.
Records().at(p).qualifiedScreenPercentageSeconds-1.8)<1e-8,
"qualified area-time is not backfilled twice");
89 Check(std::abs(standard.
Records().at(p).qualifiedScreenPercentageSeconds-1.8)<1e-8 &&
90 std::abs(standard.
Records().at(p).qualifiedSeconds-1.2)<1e-8,
"a later short flash must earn its own continuous second");
91 Check(std::abs(standard.
Records().at(p).screenPercentageSeconds-2.1)<1e-8 &&
92 std::abs(standard.
Records().at(p).aboveMinimumScreenPercentageSeconds-2.1)<1e-8,
"short flashes still earn diagnostic and size-qualified exposure");
93 for(
int i=2;i<=5;++i){good.
seconds=2+i*.2;standard.
Observe(p,good);}
94 Check(std::abs(standard.
Records().at(p).qualifiedScreenPercentageSeconds-3.3)<1e-8 &&
95 std::abs(standard.
Records().at(p).qualifiedSeconds-2.2)<1e-8,
"a second full streak backfills its initial second exactly once");
97 Check(std::abs(standard.
Records().at(p).qualifiedScreenPercentageSeconds-3.6)<1e-8 &&
98 standard.
Summaries().begin()->second.qualifiedPlacements==1,
"continued second streak accrues without a duplicate qualified placement");
99 Tracker impaired;value=good;value.
seconds=0;value.clearPixels=value.anglePixels=0;impaired.
Observe(p,value);
100 value.seconds=.2;impaired.
Observe(p,value);
101 const auto& angled=impaired.
Records().at(p);
102 Check(angled.screenPercentageSeconds>0 && angled.aboveMinimumScreenPercentageSeconds>0 &&
103 angled.qualifiedScreenPercentageSeconds==0 && angled.readableScreenPercentageSeconds==0,
104 "1.5 percent size alone does not imply full threshold qualification or readable exposure");
105 Tracker clippedExposure;value=good;value.
seconds=0;value.referencePixels=100000;value.visiblePixels=value.clearPixels=value.anglePixels=1000;
106 clippedExposure.
Observe(p,value);value.seconds=.2;clippedExposure.
Observe(p,value);
108 std::abs(clippedExposure.
Records().at(p).screenPercentageSeconds-.02)<1e-8,
"less than half a creative visible still contributes its actual diagnostic area");
110 value.screenPixels*=4;value.referencePixels*=4;value.visiblePixels*=4;value.clearPixels*=4;value.anglePixels*=4;scaled.
Observe(p,value);
111 Check(std::abs(scaled.
Records().at(p).screenPercentageSeconds-.3)<1e-8,
"resolution changes do not create extra exposure credit");
113 value.visiblePixels=value.clearPixels=value.anglePixels=30000;changing.
Observe(p,value);
114 Check(std::abs(changing.
Records().at(p).screenPercentageSeconds-.45)<1e-8,
"varying screen size uses source-time trapezoidal area integration");
116 auto second=p;second.
entity=2;value.seconds=0;content.
Observe(second,value);value.seconds=.2;content.
Observe(second,value);
117 auto hiddenPlacement=p;hiddenPlacement.
entity=3;value.backFacing=
true;value.seconds=0;content.
Observe(hiddenPlacement,value);
119 Check(summaries.at(creative).observedPlacements==3 && summaries.at(creative).visiblePlacements==2 &&
120 std::abs(summaries.at(creative).screenPercentageSeconds-.6)<1e-8,"creative summary counts distinct observed and visible placements");
121 value.backFacing=
false;value.creativeHash=2;value.seconds=.4;content.
Observe(p,value);
122 Check(content.
Summaries().size()==2,
"filename reused with different artwork retains separate creative histories");
123 }
124 void AnimatedMetadata()
125 {
127 const std::vector<uint32_t> original={0xff000000,0x80ffffff},changed={0xffffffff,0xffffffff};
128 Check(stats.
Analyze(0,original,1,
true)==1 && !stats.
Frame(0),
"GIF metadata scanning obeys the pixel budget");
129 Check(stats.
Analyze(1,changed,1,
false)==1 && stats.
Frame(0) && !stats.
Frame(1),
"a frame transition cannot contaminate the pending canvas snapshot");
130 const auto first=*stats.
Frame(0);
131 Check(first.hash==42 && first.bounds.x==0 && first.bounds.z==1 && first.bounds.w==1,"animation uses stable content identity and a fixed full-canvas area");
132 Check(std::abs(first.alphaPixels-(1+128/255.))<1e-9 && !first.empty,"black opaque artwork retains its alpha coverage");
133 Check(std::abs(first.meanLuminance-(128/383.))<1e-9,"relative luminance excludes transparent contributions and weights partial alpha");
134 Check(stats.
Analyze(0,changed,100,
true)==0,
"cached GIF frames do not rescan pixels");
135 Check(std::abs(stats.
Average().
analyzedFraction-.1)<1e-9,
"partial animation summaries disclose analyzed duration");
136 stats.
Analyze(1,{0xff000000,0xff000000},100,
true);
138 "whole-animation luminance is weighted by frame duration, not frame count");
139 stats.
Analyze(2,{0x00ffffff,0x00000000},100,
true);
143 "zero-duration held frame and metadata reinitialization are supported");
145 Check(!stats.
Supported() && stats.
Analyze(0,{},65536,
true)==0,
"oversized metadata cannot allocate a canvas or earn inferred exposure");
146 }
147 void OverlayBounds()
148 {
149 NativeUiTest11 fixture(1920,400);auto& device=fixture.device;
150 ComPtr<RenderFont> font;ComPtr<RenderSprite> sprite;
151 NativeUiTest11::HR(
CreateFontW(&device,12,0,FW_NORMAL,1,FALSE,DEFAULT_CHARSET,
152 OUT_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,L"Arial",&font));
154 const float black[4]{};device.Context()->ClearRenderTargetView(fixture.host.Device().SceneTarget(),black);
156 diagnostic.
DrawOverlay(font.Get(),sprite.Get(),1920,400,&bounds);
157 Check(bounds.size()==1,"readout publishes its measured text bounds");
158 const auto rectangle=bounds.front();
159 Check(rectangle.right<960 && rectangle.bottom<200,"empty upper-right and lower readout space are not masked");
160 const auto pixels=fixture.Pixels();size_t painted=0;bool contained=true;
161 for(unsigned y=0;y<400;++y)for(unsigned x=0;x<1920;++x)if(pixels[y*1920+x]&0x00ffffff)
162 {
163 ++painted;contained=contained && x>=unsigned(rectangle.left) && x<unsigned(rectangle.right) &&
164 y>=unsigned(rectangle.top) && y<unsigned(rectangle.bottom);
165 }
166 Check(painted>100 && contained,"text UI mask contains all rendered readout pixels");
168 Check(bounds.empty(),"hidden ADVIEW2 readout adds no UI mask");
170 Check(bounds.size()==1 && bounds.front().right<=348 && bounds.front().bottom<=68,"readout bounds follow the actual text clipping rectangle");
171 diagnostic.
SetEnabled(
false);fixture.DebugClean();
172 }
174 {
175 const std::vector<DWORD> pixels(size_t(extent)*extent,rgba);
176 D3D11_TEXTURE2D_DESC desc{};desc.Width=desc.Height=extent;desc.MipLevels=desc.ArraySize=desc.SampleDesc.Count=1;
177 desc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;desc.BindFlags=D3D11_BIND_SHADER_RESOURCE;
178 D3D11_SUBRESOURCE_DATA data{pixels.data(),extent*4,extent*extent*4};ComPtr<ID3D11Texture2D> texture;ComPtr<ID3D11ShaderResourceView> view;
179 NativeUiTest11::HR(device.
Native()->CreateTexture2D(&desc,&data,&texture));
180 NativeUiTest11::HR(device.
Native()->CreateShaderResourceView(texture.Get(),
nullptr,&view));
return view;
181 }
182 ComPtr<ID3D11ShaderResourceView> SparseTexture(
RenderDevice& device)
183 {
184 const DWORD rgba[]={0xffffffff,0x00ffffff,0xffffffff,0x00ffffff};
185 D3D11_TEXTURE2D_DESC desc{};desc.Width=desc.Height=2;desc.MipLevels=desc.ArraySize=desc.SampleDesc.Count=1;
186 desc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;desc.BindFlags=D3D11_BIND_SHADER_RESOURCE;
187 D3D11_SUBRESOURCE_DATA data{rgba,8,16};ComPtr<ID3D11Texture2D> texture;ComPtr<ID3D11ShaderResourceView> view;
188 NativeUiTest11::HR(device.
Native()->CreateTexture2D(&desc,&data,&texture));
189 NativeUiTest11::HR(device.
Native()->CreateShaderResourceView(texture.Get(),
nullptr,&view));
return view;
190 }
191 ComPtr<ID3D11ShaderResourceView> UnevenTexture(
RenderDevice& device)
192 {
193 DWORD rgba[16]{};
for(
unsigned y=0;y<4;++y)rgba[y*4]=0xffffffff;rgba[3]=0xffffffff;
194 D3D11_TEXTURE2D_DESC desc{};desc.Width=desc.Height=4;desc.MipLevels=desc.ArraySize=desc.SampleDesc.Count=1;
195 desc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;desc.BindFlags=D3D11_BIND_SHADER_RESOURCE;
196 D3D11_SUBRESOURCE_DATA data{rgba,16,64};ComPtr<ID3D11Texture2D> texture;ComPtr<ID3D11ShaderResourceView> view;
197 NativeUiTest11::HR(device.
Native()->CreateTexture2D(&desc,&data,&texture));
198 NativeUiTest11::HR(device.
Native()->CreateShaderResourceView(texture.Get(),
nullptr,&view));
return view;
199 }
200 std::vector<BYTE> Read(
RenderDevice& device,ID3D11Texture2D* source,
unsigned channels)
201 {
202 D3D11_TEXTURE2D_DESC desc{};source->GetDesc(&desc);ComPtr<ID3D11Texture2D> resolved,staging;
203 if(desc.SampleDesc.Count>1)
204 {
205 desc.SampleDesc={1,0};desc.BindFlags=0;
206 NativeUiTest11::HR(device.
Native()->CreateTexture2D(&desc,
nullptr,&resolved));
207 device.
Context()->ResolveSubresource(resolved.Get(),0,source,0,desc.Format);source=resolved.Get();
208 }
209 desc.Usage=D3D11_USAGE_STAGING;desc.CPUAccessFlags=D3D11_CPU_ACCESS_READ;desc.BindFlags=desc.MiscFlags=0;
210 NativeUiTest11::HR(device.
Native()->CreateTexture2D(&desc,
nullptr,&staging));device.
Context()->CopyResource(staging.Get(),source);
211 D3D11_MAPPED_SUBRESOURCE map{};NativeUiTest11::HR(device.
Context()->Map(staging.Get(),0,D3D11_MAP_READ,0,&map));
212 std::vector<BYTE> bytes(size_t(desc.Width)*desc.Height*channels);
213 for(unsigned y=0;y<desc.Height;++y)memcpy(bytes.data()+size_t(y)*desc.Width*channels,static_cast<BYTE*>(map.pData)+size_t(y)*map.RowPitch,desc.Width*channels);
214 device.
Context()->Unmap(staging.Get(),0);
return bytes;
215 }
216 void CloudExport(unsigned samples)
217 {
218 NativeUiTest11 fixture(160,120);if(!fixture.host.Device().SupportsSamples(samples))return;
219 NativeUiTest11::HR(fixture.host.SetSamples(samples));fixture.device.Reset();
222 XMFLOAT4X4 view,projection;
223 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,-.6f,-1,0),XMVectorSet(0,1,0,0)));
224 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1.f,160.f/120,.001f,384));
225 const auto& depth=fixture.host.Device().Depth();
const auto vp=device.
Draws().
Viewport();
226 ComPtr<ID3D11Texture2D> opacity;ComPtr<ID3D11RenderTargetView>
target;
227 D3D11_TEXTURE2D_DESC desc{};fixture.host.Device().SceneColor()->GetDesc(&desc);desc.Format=DXGI_FORMAT_R8_UNORM;
228 NativeUiTest11::HR(device.
Native()->CreateTexture2D(&desc,
nullptr,&opacity));
229 NativeUiTest11::HR(device.
Native()->CreateRenderTargetView(opacity.Get(),
nullptr,&target));
230 const float zero[4]{};
231 auto render=[&](bool diagnostic)
232 {
233 device.
Context()->ClearRenderTargetView(fixture.host.Device().SceneTarget(),zero);
235 device.
Context()->ClearDepthStencilView(depth.WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,1,0);
237 NativeUiTest11::HR(clouds.
Render(device.
Context(),fixture.host.Device().SceneTarget(),depth,vp,view,projection,
238 {0,cloud.radius+14,0},cloud,{0,-1,0},{1,1,1,1},{.3f,.4f,.5f,1}));
240 return Read(device,fixture.host.Device().SceneColor(),4);
241 };
242 const auto baseline=render(false),measured=render(true),alpha=Read(device,opacity.Get(),1);
243 Check(baseline==measured,"opacity MRT preserves cloud color and alpha");
244 unsigned nonzero=0;
245 for(size_t i=0;i<alpha.size();++i){Check(std::abs(int(alpha[i])-int(measured[i*4+3]))<=1,"exported opacity equals actual composite alpha");nonzero+=alpha[i]>0;}
246 Check(nonzero>100,"cloud opacity fixture has visible cloud pixels");
248 std::cout<<samples<<"x cloud opacity MRT matches production composite\n";
249 }
250 void Billboards(unsigned samples)
251 {
252 NativeUiTest11 fixture(320,240);
253 if(!fixture.host.Device().SupportsSamples(samples))return;
254 NativeUiTest11::HR(fixture.host.SetSamples(samples));fixture.device.Reset();
255 auto& device=fixture.device;
auto& draws=device.
Draws();
auto* context=device.
Context();
257 {{-.6f,.6f,.5f},{0,0,-1},{0,0},{0,0}},{{.6f,.6f,.5f},{0,0,-1},{1,0},{1,0}},{{-.6f,-.6f,.5f},{0,0,-1},{0,1},{0,1}},
258 {{-.6f,-.6f,.5f},{0,0,-1},{0,1},{0,1}},{{.6f,.6f,.5f},{0,0,-1},{1,0},{1,0}},{{.6f,-.6f,.5f},{0,0,-1},{1,1},{1,1}}};
259
260
261 for(
auto& vertex:vertices)vertex.
normal={1,0,0};
262 NativeUiTest11::HR(mesh.
Create(device.
Native(),
sizeof(vertices),
false));
void* destination=
nullptr;
263 NativeUiTest11::HR(mesh.
Lock(0,
sizeof(vertices),&destination));memcpy(destination,vertices,
sizeof(vertices));NativeUiTest11::HR(mesh.
Unlock());
265 XMFLOAT4X4 identity;XMStoreFloat4x4(&identity,XMMatrixIdentity());auto world=identity;
268 for(
unsigned f=0;f<4;++f)stats.
Analyze(f,{f==1 ? 0xff000000u : f==2 ? 0x80ffffffu : f==3 ? 0x00ffffffu : 0xffffffffu},1,
true);
269 auto lifetime=std::make_shared<int>(1);
273 auto& parameters=draws.Materials().Values();
274 parameters.Texture("ColorMap",base.Get());parameters.Set("CityOverlayEnabled",1);parameters.Set("Features",XMFLOAT4(26,0,0,0));
275 parameters.Set("WeapPos",XMFLOAT4{});parameters.Set("shiplight",XMFLOAT4{});parameters.Set("light",XMFLOAT4{});
276 parameters.Set("clouduv",XMFLOAT4{});
277 draws.Pipeline().raster.CullMode=D3D11_CULL_NONE;
280 {-.0008f,.0008f,.0002f,0,0,-1,0,0},{.0008f,.0008f,.0002f,0,0,-1,1,0},{-.0008f,-.0008f,.0002f,0,0,-1,0,1},
281 {-.0008f,-.0008f,.0002f,0,0,-1,0,1},{.0008f,.0008f,.0002f,0,0,-1,1,0},{.0008f,-.0008f,.0002f,0,0,-1,1,1}};
283 XMFLOAT4X4 paneWorld;XMStoreFloat4x4(&paneWorld,XMMatrixScaling(1000,1000,1000));
284 double clock=0;
285 const auto sample=[&](unsigned material,unsigned frame,float daylight,const std::vector<XMFLOAT4>& masks={},float cloud=0,float sceneDepth=1,unsigned wet=0,UINT sceneStencil=0)
286 {
287 clock+=.24;
const double source=clock;diagnostic.
BeginFrame(device,source,
true);draws.BindScene();
288 const float zero[4]{};context->ClearRenderTargetView(fixture.host.Device().SceneTarget(),zero);
289 context->ClearDepthStencilView(fixture.host.Device().Depth().WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,sceneDepth,UINT8(sceneStencil));
290 parameters.Set("matWorld",world);parameters.Set("matWorldViewProj",world);parameters.Set("ambient",XMFLOAT4(daylight,daylight,daylight,100));
291 parameters.Texture("CityOverlayMap",frame==1 ? black.Get() : frame==2 ? half.Get() : white.Get());
293 auto before=Read(device,fixture.host.Device().SceneColor(),4);
294 diagnostic.
RegisterSignDraw(device,placement,stats.
Frame(frame),lifetime,frame,4,stats.
Average(),mesh,0,2,material,world,identity,identity,.5f);
296 if(frame!=3)NativeUiTest11::HR(captured);
298 if(wet)
299 {
300 auto& water=WindshieldRain11TestAccess::Water(rain);water.Clear();
301 if(wet==2)
302 for(unsigned y=0;y<16;++y)for(unsigned x=0;x<16;++x)water.Impact({(x+.5f)*.1f,(y+.5f)*.1f},.08f,false);
303 else water.Impact({.8f,.8f},.08f,false);
304 water.Rebuild();
305 const float opacity=wet==3 ? 0.f : 1.f;
306 auto paneTransform=paneWorld;if(wet==5)paneTransform._41=3;
307 const auto renderWater=[&](ID3D11RenderTargetView* exclusion)
308 {
309 return rain.
Render(context,fixture.host.Device().SceneTarget(),fixture.host.Device().Depth().WriteView(),draws.Viewport(),
311 };
312 NativeUiTest11::HR(renderWater(nullptr));const auto baseline=Read(device,fixture.host.Device().SceneColor(),4);
313 draws.BindScene();context->ClearRenderTargetView(fixture.host.Device().SceneTarget(),zero);
315 auto* exclusion=diagnostic.
WetGlassExclusionTarget();Check(exclusion!=
nullptr,
"sampled sign exposes the shared wet-glass target");
316 const HRESULT result=renderWater(exclusion);NativeUiTest11::HR(result);
318 before=Read(device,fixture.host.Device().SceneColor(),4);
319 Check(before==baseline,"wet-glass MRT preserves production rain color at every MSAA level");
320 ComPtr<ID3D11Resource> resource;exclusion->GetResource(&resource);ComPtr<ID3D11Texture2D>
mask;
321 NativeUiTest11::HR(resource.As(&mask));
const auto pixels=Read(device,
mask.Get(),1);
322 const auto affected=std::count_if(pixels.begin(),pixels.end(),[](BYTE v){return v!=0;});
323
324
325 if(wet==3 || wet==5 || (sceneStencil>=3 && sceneDepth<.2f))
326 Check(affected==0,"faded, offscreen or cockpit-hidden water leaves the exposure mask clear");
327 else if(wet==1)Check(affected>20 && affected<10000,"localized water excludes droplets rather than the whole apartment window");
328 }
329 diagnostic.
FinishScene(device,
true,masks);context->Flush();
330 Check(before==Read(device,fixture.host.Device().SceneColor(),4),"billboard measurement does not modify scene color");
332 for(unsigned attempt=0;attempt<200;++attempt)
333 {
334 for(
const auto& item:diagnostic.
Results().
Records())
if(item.first.entity==placement.
entity && item.first.creativeHash==123 &&
335 std::abs(item.second.last.seconds-source)<1e-8){result=item.second;return result;}
336 Sleep(1);diagnostic.
BeginFrame(device,source+.001,
true);
337 }
338 throw std::runtime_error("billboard GPU query did not complete");
339 };
340 for(unsigned material:{2u,3u})
341 {
342 auto value=sample(material,0,1);
344 value=sample(material,0,0);
345 Check(value.reason==
AdViewability::Reason::Passing && value.last.clearPixels/value.last.referencePixels>.99,
"emissive billboard remains readable at night");
346 value=sample(material,1,0);
347 Check(value.last.visiblePixels/value.last.referencePixels>.99 && value.last.sourceMeanLuminance==0 && value.last.artworkVisiblePixels>27000,
348 "black GIF artwork retains physical and alpha visibility");
349 value=sample(material,2,0);
350 Check(std::abs(value.last.artworkVisiblePixels/value.last.visiblePixels-128/255.)<.03,"animated partial-alpha ink uses the current frame");
351 value=sample(material,0,0,{{0,0,.5f,1}});
352 Check(value.last.visiblePixels/value.last.referencePixels>.48 && value.last.visiblePixels/value.last.referencePixels<.52,
353 "billboard UI obstruction uses the same physical pixel mask as vehicle logos");
354 value=sample(material,0,0,{},.7f);
356 "cloud impairment remains separate from raw sign exposure");
357 value=sample(material,0,0,{},0,.1f);
358 Check(value.last.visiblePixels==0,"opaque foreground geometry blocks sign exposure");
359 value=sample(material,0,0,{},0,1,1);
360 Check(value.last.wetGlassExcluded && value.last.visiblePixels/value.last.referencePixels>.9
362 "clear majority of a wet apartment window measures and qualifies the near/far sign");
363 value=sample(material,0,0,{},0,1,2);
364 Check(value.last.wetGlassExcluded && value.last.visiblePixels/value.last.referencePixels<.5,
365 "heavy water does not receive full creative exposure credit");
366 value=sample(material,0,0,{},0,1,3);
367 Check(!value.last.wetGlassExcluded && value.last.visiblePixels/value.last.referencePixels>.99,
368 "fully faded water neither blocks exposure nor reports an active exclusion");
369 value=sample(material,0,0,{},0,.1f,1);
370 Check(value.last.visiblePixels==0,"wet-glass support preserves opaque obstruction checks");
371 for(UINT stencil:{3u,4u})
372 {
373 value=sample(material,0,0,{},0,.1f,1,stencil);
374 Check(value.last.visiblePixels==0,"cockpit foreground depth/stencil remains excluded through wet glass");
375 }
376 value=sample(material,0,0,{},0,1,4);
378 "failed wet-glass mask cannot silently earn sign exposure");
379 value=sample(material,0,0,{},0,1,5);
380 Check(!value.last.wetGlassExcluded && value.last.visiblePixels/value.last.referencePixels>.99,
381 "wet windows outside the view do not block the visible billboard");
382 }
383 for(unsigned triangle=0;triangle<6;triangle+=3)std::swap(vertices[triangle],vertices[triangle+1]);
384 NativeUiTest11::HR(mesh.
Lock(0,
sizeof(vertices),&destination));memcpy(destination,vertices,
sizeof(vertices));NativeUiTest11::HR(mesh.
Unlock());
385 draws.Pipeline().raster.CullMode=D3D11_CULL_BACK;draws.Pipeline().raster.FrontCounterClockwise=TRUE;
387 XMStoreFloat4x4(&world,XMMatrixRotationY(XM_PI)*XMMatrixTranslation(0,0,1));
389 XMStoreFloat4x4(&world,XMMatrixTranslation(1.1f,0,0));
390 const auto clipped=sample(3,0,0);
392 clipped.last.visiblePixels>0 && clipped.last.visiblePixels/clipped.last.referencePixels<.5,"partly off-screen signs retain measured exposure below the 50 percent criterion");
393 world=identity;
394 Check(diagnostic.
Results().
Records().size()==1,
"animation frames retain one sign record and exposure history");
395 for(unsigned f=0;f<6;++f)sample(2,f%2,0);
396 const auto& continuous=diagnostic.
Results().
Records().begin()->second;
397 Check(continuous.qualified && continuous.qualifiedScreenPercentageSeconds>0 &&
398 continuous.aboveMinimumScreenPercentageSeconds>0 && continuous.screenPercentageSeconds>=continuous.qualifiedScreenPercentageSeconds,
399 "animated frame changes preserve SPS and a full continuous qualifying streak");
400 auto value=sample(2,3,0);
401 Check(value.last.sizeRejected && value.last.sourceAlphaPixels==0 && value.continuousSeconds==0,"empty animation frame cannot earn exposure or qualification");
402 placement.
entity=4003;sample(2,0,0);
403 Check(diagnostic.
Results().
Summaries().begin()->second.observedPlacements==2,
"shared GIF counts two physical signs separately");
404
405 placement.
entity=4004;clock+=.24;diagnostic.
BeginFrame(device,clock,
true);draws.BindScene();
406 diagnostic.
RegisterSignDraw(device,placement,stats.
Frame(0),lifetime,0,4,stats.
Average(),mesh,0,2,2,world,identity,identity,.5f);
407 NativeUiTest11::HR(diagnostic.
CaptureScene(device));diagnostic.
FinishScene(device,
true,{});lifetime.reset();context->Flush();Sleep(5);
409 Check(diagnostic.
Results().
Records().size()==2,
"removed artwork cannot publish a delayed query under a new assignment");
410 lifetime=std::make_shared<int>(2);clock+=.24;diagnostic.
BeginFrame(device,clock,
true);draws.BindScene();
411 context->ClearDepthStencilView(fixture.host.Device().Depth().WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,1,0);
412 parameters.Texture(
"CityOverlayMap",white.Get());draws.Material(2);NativeUiTest11::HR(draws.Draw(mesh,layout,
Primitive11::Triangles,0,2));
413 const auto dropped=diagnostic.
Dropped();
414 for(unsigned i=0;i<70;++i)
415 {
417 diagnostic.
RegisterSignDraw(device,placement,stats.
Frame(0),lifetime,0,4,stats.
Average(),mesh,0,2,2,world,identity,identity,.5f);
418 }
421 diagnostic.
SetEnabled(
false);fixture.DebugClean();
422 std::cout<<samples<<"x animated billboard queries passed\n";
423 }
424 void GPU(unsigned samples)
425 {
426 NativeUiTest11 fixture(320,240);
427 if(!fixture.host.Device().SupportsSamples(samples))return;
428 NativeUiTest11::HR(fixture.host.SetSamples(samples));fixture.device.Reset();
429 auto& device=fixture.device;
auto& draws=device.
Draws();
auto* context=device.
Context();
432 {{-.6f,.6f,.5f},{0,0,-1},{0,0},{0,0}},{{.6f,.6f,.5f},{0,0,-1},{1,0},{1,0}},{{-.6f,-.6f,.5f},{0,0,-1},{0,1},{0,1}},
433 {{-.6f,-.6f,.5f},{0,0,-1},{0,1},{0,1}},{{.6f,.6f,.5f},{0,0,-1},{1,0},{1,0}},{{.6f,-.6f,.5f},{0,0,-1},{1,1},{1,1}}};
434 NativeUiTest11::HR(mesh.
Create(device.
Native(),
sizeof(vertices),
false));
void* destination=
nullptr;
435 NativeUiTest11::HR(mesh.
Lock(0,
sizeof(vertices),&destination));memcpy(destination,vertices,
sizeof(vertices));NativeUiTest11::HR(mesh.
Unlock());
436 XMFLOAT4X4 identity;XMStoreFloat4x4(&identity,XMMatrixIdentity());
437 XMFLOAT4X4 world=identity,projection=identity;
439 auto white=
Texture(device,0xffffffff,64),hull=
Texture(device,0xff404040),black=
Texture(device,0xff000000,64),
440 half=
Texture(device,0x80ffffff,64),transparent=
Texture(device,0x00ffffff),sparse=SparseTexture(device),uneven=UnevenTexture(device);
441 auto& parameters=draws.Materials().Values();
442 parameters.Set("matWorld",identity);parameters.Set("matWorldViewProj",identity);
443 parameters.Set("Features",XMFLOAT4(1,1,1,0));parameters.Set("ambient",XMFLOAT4(1,1,1,100));
444 parameters.Set("Sunlight",XMFLOAT4(0,0,0,0));parameters.Set("Radiosity",XMFLOAT4(0,0,0,0));
445 parameters.Set("WeapPos",XMFLOAT4(0,0,0,0));parameters.Set("clouduv",XMFLOAT4(0,0,1,0));
446 parameters.Texture("ColorMap",hull.Get());parameters.Texture("OverlayMap",white.Get());
447 draws.Pipeline().raster.CullMode=D3D11_CULL_NONE;
448 draws.Material(4);
451 double clock=0;
452 struct GlassVertex { XMFLOAT3 position,normal;XMFLOAT2 uv; };
453 const GlassVertex glassVertices[]={
454 {{-1,1,.1f},{0,0,-1},{0,0}},{{1,1,.1f},{0,0,-1},{1,0}},{{-1,-1,.1f},{0,0,-1},{0,1}},
455 {{-1,-1,.1f},{0,0,-1},{0,1}},{{1,1,.1f},{0,0,-1},{1,0}},{{1,-1,.1f},{0,0,-1},{1,1}}};
457 NativeUiTest11::HR(glassMesh.
Lock(0,
sizeof(glassVertices),&destination));memcpy(destination,glassVertices,
sizeof(glassVertices));NativeUiTest11::HR(glassMesh.
Unlock());
459 unsigned glassLayers=0;
DWORD glassColor=0x00ffffff;
460 const auto warm=[&](ID3D11ShaderResourceView* logo)
461 {
462 for(unsigned attempt=0;attempt<200;++attempt)
463 {
464 if(
const auto* ready=diagnostic.
PrepareCreative(device,logo))
return *ready;
465 context->Flush();Sleep(1);clock+=.21;diagnostic.
BeginFrame(device,clock,
true);
466 }
467 throw std::runtime_error("creative metadata did not become ready");
468 };
469 auto sample=[&](
int pass,
float depth,UINT stencil,
const std::vector<XMFLOAT4>& masks,
float opacity,
bool weather=
true,
const char* uiBlocker=
nullptr)
470 {
471 clock+=.21;diagnostic.
BeginFrame(device,clock,
true);draws.BindScene();
472 warm(parameters.Texture("OverlayMap"));
473 context->ClearDepthStencilView(fixture.host.Device().Depth().WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,depth,UINT8(stencil));
474 XMFLOAT4X4 wvp;XMStoreFloat4x4(&wvp,XMLoadFloat4x4(&world)*XMLoadFloat4x4(&projection));
475 parameters.Set("matWorld",world);parameters.Set("matWorldViewProj",wvp);
477 diagnostic.
RegisterDraw(device,placement,1,mesh,0,2,
unsigned(pass),world,identity,projection,.5f);
480 std::vector<BYTE> sceneBefore;
481 if(glassLayers)
482 {
483 auto tint=
Texture(device,glassColor);
484 parameters.Set("matWorld",identity);parameters.Set("matWorldViewProj",identity);
485 parameters.Set("Features",XMFLOAT4(0,0,0,0));parameters.Set("ambient",XMFLOAT4(1,1,1,0));
486 parameters.Texture("ColorMap",tint.Get());
487 auto& blend=draws.Pipeline().blend.RenderTarget[0];blend.BlendEnable=TRUE;
488 blend.SrcBlend=D3D11_BLEND_SRC_ALPHA;blend.DestBlend=D3D11_BLEND_INV_SRC_ALPHA;blend.BlendOp=D3D11_BLEND_OP_ADD;
489 draws.Pipeline().depth.DepthWriteMask=D3D11_DEPTH_WRITE_MASK_ZERO;draws.Pipeline().depth.DepthFunc=D3D11_COMPARISON_ALWAYS;
490 draws.Material(8);
491 for(unsigned layer=0;layer<glassLayers;++layer)
492 {
495 }
496 sceneBefore=Read(device,fixture.host.Device().SceneColor(),4);
497 }
499 if(glassLayers)
500 {
501 Check(sceneBefore==Read(device,fixture.host.Device().SceneColor(),4),"glass opacity replay preserves production scene pixels");
502 parameters.Texture("ColorMap",hull.Get());parameters.Set("Features",XMFLOAT4(1,1,1,0));parameters.Set("ambient",XMFLOAT4(1,1,1,100));
503 draws.Pipeline().blend.RenderTarget[0].BlendEnable=FALSE;
504 draws.Pipeline().depth.DepthWriteMask=D3D11_DEPTH_WRITE_MASK_ALL;draws.Pipeline().depth.DepthFunc=D3D11_COMPARISON_LESS;
505 }
507 {
508 for(
const auto& item:diagnostic.
Results().
Records())
if(std::abs(item.second.last.seconds-clock)<.001)
return &item.second;
509 return nullptr;
510 };
511 for(int attempt=0;attempt<100 && !latest();++attempt)
512 {Sleep(1);diagnostic.
BeginFrame(device,clock+.01,
true);}
513 Check(latest()!=nullptr,"GPU observation returned");
514 const auto& record=*latest();
515 Check(std::abs(record.last.seconds-clock)<.001,"observation source timestamp");
516 return record;
517 };
518 auto record=sample(4,1,0,{},0);
519 std::cout<<samples<<
"x MSAA: reference="<<record.last.referencePixels<<
" visible="<<record.last.visiblePixels<<
" clear="<<record.last.clearPixels<<
" reason="<<
AdViewability::Name(record.reason)<<
"\n";
521 Check(std::abs(record.last.referencePixels/76800-.36)<.01,"MSAA normalized to pixels");
523 XMStoreFloat4x4(&world,XMMatrixScaling(.04f,.04f,1));record=sample(4,1,0,{},0);
525 record.last.visiblePixels>0,"logo around 0.05 percent receives real GPU measurements");
526 const double smallArea=record.screenPercentageSeconds;record=sample(4,1,0,{},0);
527 Check(record.screenPercentageSeconds>smallArea,"small GPU-measured logo contributes diagnostic area-time");
528 XMStoreFloat4x4(&world,XMMatrixScaling(.02f,.02f,1));record=sample(4,1,0,{},0);
529 Check(record.last.sizeRejected,"work below the disclosed 0.05 percent admission floor stays bounded");
530 world=identity;record=sample(5,1,0,{},0);
531 record=sample(4,1,0,{},1);
532 Check(record.last.visiblePixels==0 && record.last.clearPixels==0,"opaque cloud excludes raw as well as readable area");
533 const double hiddenArea=record.screenPercentageSeconds;record=sample(4,1,0,{},1);
534 Check(record.screenPercentageSeconds==hiddenArea,"steady fully cloud-hidden logo earns no area-time");
535 parameters.Set("volumeFog",XMFLOAT4(0,0,0,10));record=sample(5,1,0,{},0);
536 Check(record.last.visiblePixels==0,"zero fog transmission excludes diagnostic visibility");
537 parameters.Set("volumeFog",XMFLOAT4(0,0,0,0));record=sample(5,1,0,{},0);
538
539
540 const double opaqueInk=record.last.artworkVisiblePixels;
541 parameters.Texture("OverlayMap",half.Get());record=sample(4,1,0,{},0);
542 Check(std::abs(record.last.sourceAlphaPixels-4096.*128/255)<1e-7,"source alpha sum weights partial opacity");
543 Check(std::abs(record.last.sourceMeanLuminance-1)<1e-8,"source luminance is alpha weighted in linear light");
544 Check(std::abs(record.last.referencePixels-27648)<1,"partial alpha does not shrink intended area");
545 Check(std::abs(record.last.artworkVisiblePixels/opaqueInk-128./255)<.015,"half opacity contributes half the corresponding sampled opaque coverage");
546 const auto cached=warm(half.Get());
547 Check(cached.hash==record.last.creativeHash && cached.alphaPixels==record.last.sourceAlphaPixels,"metadata is reused for the same texture");
548 parameters.Texture("OverlayMap",uneven.Get());record=sample(4,1,0,{},0);
549 Check(record.last.sourceAlphaPixels==5 && std::abs(record.last.referencePixels-27648)<1,"tight enclosing area retains transparent interior spaces");
550 const double fullInk=record.last.artworkReferencePixels;
551 record=sample(4,1,0,{{0,0,.5f,1}},0);
552 Check(std::abs(record.last.visiblePixels/record.last.referencePixels-.5)<.01,"half the intended area remains visible");
553 Check(record.last.artworkVisiblePixels/fullInk<.4,"uneven ink visibility uses spatial alpha rather than global fill correction");
554 parameters.Texture("OverlayMap",black.Get());parameters.Texture("ColorMap",white.Get());
557 parameters.Texture("ColorMap",black.Get());record=sample(4,1,0,{},0);
559 parameters.Texture("ColorMap",hull.Get());parameters.Set("ambient",XMFLOAT4(.08f,.08f,.08f,100));
561 parameters.Set("ambient",XMFLOAT4(0,0,0,100));record=sample(4,1,0,{},0);
563 parameters.Texture("ColorMap2",white.Get());parameters.Set("clouduv",XMFLOAT4(0,1,1,0));
564 for(int pass:{4,5})
565 {
566 record=sample(pass,1,0,{},0);
568 }
569 parameters.Set("clouduv",XMFLOAT4(0,0,1,0));
570 parameters.Set("ambient",XMFLOAT4(1,1,1,100));parameters.Texture("OverlayMap",white.Get());
571 XMStoreFloat4x4(&world,XMMatrixTranslation(.8f,0,.4f));record=sample(4,1,0,{},0);
573 Check(std::abs(record.last.referencePixels-27648)<2 && std::abs(record.last.visiblePixels/record.last.referencePixels-2./3)<.01,
574 "off-screen part remains in the full reference denominator");
575
576
577 XMStoreFloat4x4(&world,XMMatrixTranslation(1-1/320.f,0,.4f));record=sample(4,1,0,{},0);
579 "exactly half visible qualifies with enough visible screen area");
580 XMStoreFloat4x4(&world,XMMatrixTranslation(1.02f,0,.4f));record=sample(4,1,0,{},0);
582 XMStoreFloat4x4(&world,XMMatrixScaling(3,3,1));record=sample(4,1,0,{},0);
584 "oversized creative reference includes both off-screen edges");
585 world=identity;
586
587
588 auto sloped=std::vector<AdDiagnostics11::Vertex>(std::begin(vertices),std::end(vertices));
589 for(auto& v:sloped){v.position.z+=v.position.x*.173239f+v.position.y*.217231f;v.logo={v.logo.x*1.4f-.2f,v.logo.y*1.4f-.2f};}
590 NativeUiTest11::HR(mesh.
Lock(0,
sizeof(vertices),&destination));memcpy(destination,sloped.data(),
sizeof(vertices));NativeUiTest11::HR(mesh.
Unlock());
591 for(int i=0;i<12;++i)
592 {
593 XMStoreFloat4x4(&world,XMMatrixTranslation(0,0,float(i)*.0000007f));record=sample(4,1,0,{},0);
594 Check(record.last.visiblePixels/record.last.referencePixels>.995,"sloped coplanar logo remains visible under tiny depth motion");
595 }
596 world=identity;NativeUiTest11::HR(mesh.
Lock(0,
sizeof(vertices),&destination));memcpy(destination,vertices,
sizeof(vertices));NativeUiTest11::HR(mesh.
Unlock());
597 record=sample(4,.49999f,0,{},0);
598 Check(record.last.visiblePixels==0,"near coplanar foreground blocker remains opaque");
599 glassLayers=1;record=sample(4,1,0,{},0);
601 glassColor=0x40ffffff;record=sample(4,1,0,{},0);
603 glassColor=0x66ffffff;record=sample(4,1,0,{},0);
605 glassColor=0xffffffff;record=sample(4,1,0,{},0);
607 glassLayers=2;glassColor=0x33ffffff;record=sample(4,1,0,{},0);
609 glassColor=0x19ffffff;record=sample(5,1,0,{},0);
611 glassLayers=0;
613 record=sample(4,.1f,0,{},0);Check(record.last.visiblePixels==0,"opaque depth obstruction");
614 record=sample(4,1,3,{},0);Check(record.last.visiblePixels==0,"cockpit stencil occlusion");
616 parameters.Texture("OverlayMap",sparse.Get());record=sample(4,1,0,{},0);
618 record.last.referencePixels==record.last.visiblePixels,"transparent padding excluded from visibility denominator");
619 parameters.Texture("OverlayMap",transparent.Get());record=sample(4,1,0,{},0);
620 Check(record.last.clearPixels==0,"transparent overlay earns no clear pixels");
621 parameters.Texture("OverlayMap",white.Get());parameters.Set("ambient",XMFLOAT4(0,0,0,100));
622 record=sample(4,1,0,{},0);Check(record.last.clearPixels==0,"unlit logo earns no clear pixels");
623 parameters.Set("ambient",XMFLOAT4(1,1,1,100));
625 XMStoreFloat4x4(&world,XMMatrixRotationZ(XM_PI));record=sample(4,1,0,{},0);
627 XMStoreFloat4x4(&world,XMMatrixScaling(-1,1,1));record=sample(4,1,0,{},0);
629 world=identity;
630 record=sample(4,1,0,{},0,true,"help tooltip");
632 "actually drawn tooltip excludes exposure");
633 Check(diagnostic.
Blocker()==
"help tooltip",
"specific UI blocker exposed");
634 record=sample(4,1,0,{},0);
636 "absent UI permits measurement and clears blocker");
637 for(int i=0;i<5;++i)record=sample(4,1,0,{},0);
638 Check(record.continuousSeconds>=1,"uncovered view can accumulate one second");
639
640
641 clock+=.01;diagnostic.
BeginFrame(device,clock,
true);
642 Check(!diagnostic.
Collecting(),
"fixture is between scheduled observations");
643 diagnostic.
FinishScene(device,
true,{},
"help tooltip");
644 auto whitePlacement=placement;whitePlacement.
creativeHash=warm(white.Get()).hash;
645 Check(diagnostic.
Results().
Records().at(whitePlacement).continuousSeconds==0,
646 "UI appearance between polls immediately interrupts exposure");
647 Check(diagnostic.
Blocker()==
"help tooltip",
"non-sampled UI blocker visible");
648 clock+=.01;diagnostic.
BeginFrame(device,clock,
true);
650 record=sample(4,1,0,{},0);
651 Check(record.continuousSeconds==0,"exposure cannot bridge a covered frame");
652 clock+=.21;diagnostic.
BeginFrame(device,clock,
false,
"game not in foreground");
654 Check(!diagnostic.
Collecting() && diagnostic.
Blocker()==
"game not in foreground",
655 "specific inactive-view blocker preserved");
656 record=sample(4,1,0,{},0);
658 "active view resumes with a new streak");
659 auto rhVertices=std::vector<AdDiagnostics11::Vertex>(std::begin(vertices),std::end(vertices));
660 for(auto& vertex:rhVertices){vertex.position.z=-.5f;vertex.normal.z=1;}
661 NativeUiTest11::HR(mesh.
Lock(0,
sizeof(vertices),&destination));memcpy(destination,rhVertices.data(),
sizeof(vertices));NativeUiTest11::HR(mesh.
Unlock());
662 XMStoreFloat4x4(&projection,XMMatrixOrthographicRH(2,2,.001f,2));
664
665
666 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1.f,320.f/240,.001f,384));
667 for(unsigned pass:{4u,5u})for(unsigned pose=0;pose<16;++pose)
668 {
669 XMStoreFloat4x4(&world,XMMatrixScaling(.01f,.01f,.01f)*XMMatrixRotationX(.43f)*
670 XMMatrixRotationY(-.17f)*XMMatrixRotationZ(-.22f)*
671 XMMatrixTranslation(float(pose)*.000031f,-.004f,-.04f));
672 record=sample(pass,1,0,{},0);
673 const double visible=record.last.visiblePixels/record.last.referencePixels;
674 if(visible<.995)std::cout<<samples<<"x perspective pass="<<pass<<" pose="<<pose<<" visible="<<visible<<'\n';
675 Check(visible>.995,"unobstructed perspective vehicle logo remains fully visible");
676 }
677 world=identity;XMStoreFloat4x4(&projection,XMMatrixOrthographicRH(2,2,.001f,2));
678
679 NativeUiTest11::HR(mesh.
Create(device.
Native(),
sizeof(vertices),
false));
680 NativeUiTest11::HR(mesh.
Lock(0,
sizeof(vertices),&destination));memcpy(destination,rhVertices.data(),
sizeof(vertices));NativeUiTest11::HR(mesh.
Unlock());
682 const auto oldCount=record.observations;
683 clock+=.21;diagnostic.
BeginFrame(device,clock,
true);
684 diagnostic.
RegisterDraw(device,placement,1,mesh,0,2,4,world,identity,projection,.5f);
686 Read(device,fixture.host.Device().SceneColor(),4);
688 Check(diagnostic.
Results().
Records().at(whitePlacement).observations==oldCount,
"pending result ignored after slot/creative replacement");
690
691
693 {{-.14f,.14f,.53f},{0,0,-1},{0,0},{0,0}},{{0,.14f,.5f},{0,0,-1},{.5f,0},{.5f,0}},{{-.14f,-.14f,.53f},{0,0,-1},{0,1},{0,1}},
694 {{-.14f,-.14f,.53f},{0,0,-1},{0,1},{0,1}},{{0,.14f,.5f},{0,0,-1},{.5f,0},{.5f,0}},{{0,-.14f,.5f},{0,0,-1},{.5f,1},{.5f,1}},
695 {{0,.14f,.5f},{0,0,-1},{.5f,0},{.5f,0}},{{.14f,.14f,.53f},{0,0,-1},{1,0},{1,0}},{{0,-.14f,.5f},{0,0,-1},{.5f,1},{.5f,1}},
696 {{0,-.14f,.5f},{0,0,-1},{.5f,1},{.5f,1}},{{.14f,.14f,.53f},{0,0,-1},{1,0},{1,0}},{{.14f,-.14f,.53f},{0,0,-1},{1,1},{1,1}}};
697 NativeUiTest11::HR(mesh.
Create(device.
Native(),
sizeof(folded),
false));
698 NativeUiTest11::HR(mesh.
Lock(0,
sizeof(folded),&destination));memcpy(destination,folded,
sizeof(folded));NativeUiTest11::HR(mesh.
Unlock());
700 clock+=.21;diagnostic.
BeginFrame(device,clock,
true);draws.BindScene();
701 context->ClearDepthStencilView(fixture.host.Device().Depth().WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,1,0);
702 parameters.Set("matWorld",identity);parameters.Set("matWorldViewProj",identity);draws.Material(4);
704 diagnostic.
RegisterDraw(device,placement,1,mesh,0,4,4,world,identity,projection,.5f);
706 Read(device,fixture.host.Device().SceneColor(),4);diagnostic.
BeginFrame(device,clock+.01,
true);
707 Check(diagnostic.
Results().
Records().size()==1,
"connected UV facets form one creative");
708 const auto& combined=diagnostic.
Results().
Records().begin()->second;
710 "combined creative passes even though individual facets are below 1.5%");
712
713 auto repeated=std::vector<AdDiagnostics11::Vertex>(std::begin(folded),std::end(folded));
714 for(size_t i=0;i<repeated.size();++i)repeated[i].logo.x=i<6 ? repeated[i].logo.x*2 : (repeated[i].logo.x-.5f)*2;
715 NativeUiTest11::HR(mesh.
Lock(0,
sizeof(folded),&destination));memcpy(destination,repeated.data(),
sizeof(folded));NativeUiTest11::HR(mesh.
Unlock());
717 diagnostic.
RegisterDraw(device,placement,1,mesh,0,4,4,world,identity,projection,.5f);
719 Read(device,fixture.host.Device().SceneColor(),4);diagnostic.
BeginFrame(device,clock+.01,
true);
720 Check(diagnostic.
Results().
Records().size()==2,
"two repeated logos are not summed into one creative");
723
724
725 const auto panelTest=[&](float left,float crease,float right,float z,float farZ,bool passes)
726 {
728 {{left,.4f,z},{0,0,-1},{0,0},{0,0}},{{crease,.4f,z},{0,0,-1},{.8f,0},{.8f,0}},{{left,-.4f,z},{0,0,-1},{0,1},{0,1}},
729 {{left,-.4f,z},{0,0,-1},{0,1},{0,1}},{{crease,.4f,z},{0,0,-1},{.8f,0},{.8f,0}},{{crease,-.4f,z},{0,0,-1},{.8f,1},{.8f,1}},
730 {{crease,.4f,z},{0,0,-1},{.8f,0},{.8f,0}},{{right,.4f,farZ},{0,0,-1},{1,0},{1,0}},{{crease,-.4f,z},{0,0,-1},{.8f,1},{.8f,1}},
731 {{crease,-.4f,z},{0,0,-1},{.8f,1},{.8f,1}},{{right,.4f,farZ},{0,0,-1},{1,0},{1,0}},{{right,-.4f,farZ},{0,0,-1},{1,1},{1,1}}};
732 NativeUiTest11::HR(mesh.
Lock(0,
sizeof(panels),&destination));memcpy(destination,panels,
sizeof(panels));NativeUiTest11::HR(mesh.
Unlock());
733 diagnostic.
SetEnabled(
true);clock+=.21;diagnostic.
BeginFrame(device,clock,
true);draws.BindScene();
734 context->ClearDepthStencilView(fixture.host.Device().Depth().WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,1,0);
736 diagnostic.
RegisterDraw(device,placement,1,mesh,0,4,4,world,identity,projection,.5f);
738 Read(device,fixture.host.Device().SceneColor(),4);diagnostic.
BeginFrame(device,clock+.01,
true);
739 Check(diagnostic.
Results().
Records().size()==1,
"angular fixture remains one connected creative");
740 const auto& result=diagnostic.
Results().
Records().begin()->second;
745 };
746 panelTest(-.6f,.3f,.5f,.8f,.95f,true);
747 panelTest(-.4f,-.1f,.5f,.3f,.9f,false);
748 auto back=std::vector<AdDiagnostics11::Vertex>(std::begin(vertices),std::end(vertices));
749 for(auto& v:back)v.normal.z=1;
750 NativeUiTest11::HR(mesh.
Lock(0,
sizeof(vertices),&destination));memcpy(destination,back.data(),
sizeof(vertices));NativeUiTest11::HR(mesh.
Unlock());
752 diagnostic.
RegisterDraw(device,placement,1,mesh,0,2,4,world,identity,projection,.5f);
753 const auto& hidden=diagnostic.
Results().
Records().begin()->second;
755 Check(diagnostic.
CaptureScene(device)==S_FALSE,
"back-facing-only scene does not copy depth or run queries");
757 std::vector<AdDiagnostics11::Vertex> corrugated;
758 for(unsigned strip=0;strip<128;++strip)
759 {
760 const float u=float(strip)/128,v=float(strip+1)/128;
761 const float za=.7f+(strip%2)*.004f,zb=.7f+((strip+1)%2)*.004f;
762 const AdDiagnostics11::Vertex a{{u-.5f,.3f,za},{0,0,-1},{u,0},{u,0}},b{{v-.5f,.3f,zb},{0,0,-1},{v,0},{v,0}},
763 c{{u-.5f,-.3f,za},{0,0,-1},{u,1},{u,1}},d{{v-.5f,-.3f,zb},{0,0,-1},{v,1},{v,1}};
764 corrugated.insert(corrugated.end(),{a,b,c,c,b,d});
765 }
767 NativeUiTest11::HR(mesh.
Create(device.
Native(),budgetBytes,
false));
768 NativeUiTest11::HR(mesh.
Lock(0,budgetBytes,&destination));memcpy(destination,corrugated.data(),budgetBytes);NativeUiTest11::HR(mesh.
Unlock());
769 diagnostic.
SetEnabled(
true);clock+=.21;diagnostic.
BeginFrame(device,clock,
true);draws.BindScene();
770 context->ClearDepthStencilView(fixture.host.Device().Depth().WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,1,0);
772 diagnostic.
RegisterDraw(device,placement,1,mesh,0,
unsigned(corrugated.size()/3),4,world,identity,projection,.5f);
774 Check(diagnostic.
Results().
Records().size()==1,
"corrugated fixture is one connected creative");
776 "excessive facet draw work is bounded and unmeasured");
777 diagnostic.
SetEnabled(
false);fixture.DebugClean();
778 }
779}
781{
782 try{Model();AnimatedMetadata();OverlayBounds();for(unsigned samples:{1u,2u,4u,8u}){GPU(samples);Billboards(samples);CloudExport(samples);}std::cout<<checks<<" ad viewability checks passed\n";return 0;}
783 catch(const std::exception& error){std::cerr<<"FAIL: "<<error.what()<<"\n";return 1;}
784}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
std::map< CreativeKey, CreativeSummary > Summaries() const
void Interrupt(double now, Reason reason)
const std::map< Placement, Record > & Records() const
bool Observe(const Placement &key, const Observation &value)
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)
const AdViewability::Tracker & Results() const
void SetAnimatedInventory(bool value)
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)
void SetEnabled(bool value)
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)
const std::string & Blocker() const
void BeginFrame(RenderDevice &device, double now, bool eligible, const char *blocker=nullptr)
void RegisterOverlayDraw(RenderDevice &device, Geometry11 &geometry, unsigned first, unsigned count, unsigned material)
void SetOverlayVisible(bool value)
ID3D11RenderTargetView * CloudOpacityTarget() const
ID3D11RenderTargetView * WetGlassExclusionTarget() const
static constexpr unsigned MaximumCandidates
void FinishScene(RenderDevice &device, bool weatherMeasured, const std::vector< DirectX::XMFLOAT4 > &uiRects, const char *uiBlocker=nullptr)
const CreativeMetadata * PrepareCreative(RenderDevice &device, ID3D11ShaderResourceView *view)
HRESULT CaptureScene(RenderDevice &device)
void SetAdOpacityTarget(ID3D11RenderTargetView *target)
bool AdOpacityWritten() const
HRESULT Render(ID3D11DeviceContext *context, ID3D11RenderTargetView *scene, const SceneDepth11 &depth, const D3D11_VIEWPORT &viewport, const Matrix &view, const Matrix &projection, const Vector &planetEye, const CloudVolume::Parameters ¶ms, const Vector &sunlight, const Color &light, const Color &ambient, const Color &airglow=Color(.125f,.375f,.25f, 1), const Color &horizonHaze=Color(0, 0, 0, 0), const Color &atmosphereHaze=Color(0, 0, 0, 0), const Color &nightVisionGain=Color(1, 1, 1, 0))
void SetLightningEnabled(bool value)
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &shaderDirectory={})
const D3D11_VIEWPORT & Viewport() const
HRESULT Create(ID3D11Device *device, UINT bytes, bool dynamic, bool index=false, bool indices32=false)
HRESULT Lock(UINT offset, UINT size, void **destination, bool readOnly=false, bool discard=false)
ID3D11DeviceContext * Context()
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &shaderDirectory={})
HRESULT Render(ID3D11DeviceContext *context, ID3D11RenderTargetView *target, ID3D11DepthStencilView *depth, const D3D11_VIEWPORT &viewport, const std::vector< Matrix > &world, const Matrix &viewProjection, float opacity=1, DepthLayout depthLayout=DepthLayout::Unified, float cockpitLight=0, ID3D11RenderTargetView *adExclusion=nullptr)
void AddGlass(int component, const Vertex *vertices, size_t count)
std::vector< Pane > panes
Reason Evaluate(const Observation &value)
const char * Name(Reason reason)
HRESULT CreateFontW(RenderDevice *owner, INT height, UINT width, UINT weight, UINT mipLevels, BOOL italic, DWORD charset, DWORD precision, DWORD quality, DWORD pitch, const wchar_t *face, RenderFont **result)
HRESULT CreateSprite(RenderDevice *owner, RenderSprite **result)