1#define main CityLogoUnitMain
2#include "CityLogoTests.cpp"
3#undef main
4#include "../Viewscreen/CityCampaignLogos.h"
5#include "../Rendering/ClientRenderer11.h"
6#include <d3d11sdklayers.h>
7#include "../Rendering/GifAnimationWorker.h"
8
9template<class Ready> void WaitFor(Ready ready, const char* message)
10{
11 const auto until=GetTickCount64()+10000;
12 while(!ready()){Check(GetTickCount64()<until,message);Sleep(1);}
13}
14
15int main()
16{
17 try
18 {
22 std::vector<CityLogos::AssignmentAsset> requests;
24 auto bytes=Header(1,1);Frame(bytes,0,0,1,1,1,3,{1});Frame(bytes,0,0,1,1,1,5,{2});bytes.push_back(0x3b);
25 const auto read=[&](int32_t group)
26 {
27 auto* texture=cache.
Texture(group);Check(texture!=
nullptr,
"available current frame");
29 const DWORD pixel=*
static_cast<const DWORD*
>(mapped.
pBits);Check(SUCCEEDED(texture->UnlockRect(0)),
"readback unlock");
return pixel;
30 };
31 const auto awaitFrame=[&](int32_t group,unsigned frame,uint64_t now,bool measure=false)
32 {
33 WaitFor([&]{
36 },"background frame available");
37 };
38 Check(!cache.
Texture(4002),
"geometry before assignment has no overlay");
39 Check(cache.
Assign(4002,
"campaign",9) && cache.
Assign(-32768,
"campaign",9),
"groups assigned before artwork");
40 Check(!cache.
Texture(4002),
"pending asset uses ordinary shading");
41 cache.
Update(&device,100,send);Check(requests.size()==1,
"shared download");
const auto token=requests.back().token;
42 Check(cache.
Receive(&device,token,bytes.data(),bytes.size(),100),
"GIF transfer accepted");
43 awaitFrame(4002,0,100);
44 Check(cache.
Texture(4002)==cache.
Texture(-32768),
"instances share the GPU asset");
45 Check(
read(4002)==0xffff0000,
"first GIF frame is straight-alpha red");
46 auto measurement=cache.
Measure(4002);
47 Check(measurement.filename && *measurement.filename=="campaign" && !measurement.metadata && measurement.frameCount==2,
48 "draw requests lazy frame statistics without a GPU readback");
50 Check(!cache.
Measure(4002).
metadata,
"ADVIEW off performs no GIF metadata analysis");
52 Check(measurement.metadata && measurement.metadata->alphaPixels==1 && std::abs(measurement.metadata->meanLuminance-.2126)<1e-9,
53 "current composed GIF frame supplies exact alpha and luminance metadata");
54 const auto hash=measurement.hash;
56 awaitFrame(4002,1,130,true);
57 Check(
read(-32768)==0xff00ff00 && cache.
Texture(4002)==texture,
"animation advances in place once per frame");
58 measurement=cache.
Measure(4002);
59 Check(measurement.metadata && measurement.metadata->hash==hash && measurement.frame==1 &&
60 cache.
Measure(-32768).
metadata==measurement.metadata,
"groups share statistics while animation retains one creative identity");
61 Check(measurement.average.analyzedFraction==1 && std::abs(measurement.average.luminance-(.2126*3+.7152*5)/8)<1e-9,
62 "whole-GIF summary respects unequal frame delays");
63 Check(cache.
Assign(4002,
"CAMPAIGN",9),
"repeat packet uses cache");cache.
Update(&device,131,send);
64 Check(requests.size()==1 &&
read(4002)==0xff00ff00,
"cache hit neither requests nor restarts animation");
65 Check(!measurement.lifetime.expired(),"duplicate assignment preserves pending measurement validity");
66 Check(cache.
Assign(4002,
"next",5),
"new assignment clears old overlay");Check(!cache.
Texture(4002),
"no stale artwork during replacement");
67 Check(measurement.lifetime.expired() && cache.
Texture(-32768)==texture,
68 "group reassignment invalidates pending exposure even when another group retains the old GIF");
69 cache.
Update(&device,140,send);
const auto old=requests.back().token;
70 Check(cache.
Assign(4002,
"latest",7),
"replace pending assignment");cache.
Update(&device,141,send);
const auto latest=requests.back().token;
71 Check(!cache.
Receive(&device,old,bytes.data(),bytes.size(),142) && !cache.
Texture(4002),
"stale download rejected");
72 Check(!cache.
Receive(&device,latest,
nullptr,0,143),
"explicit transfer failure");
73 cache.
Update(&device,30142,send);Check(requests.back().token!=latest,
"retry has new correlation token");
74 Check(cache.
Receive(&device,requests.back().token,bytes.data(),bytes.size(),30142),
"late retry recovers assignment");
75 awaitFrame(4002,0,30142);
76 Check(
read(4002)==0xffff0000 && cache.
Texture(4002)!=cache.
Texture(-32768),
"new filename has independent playback");
77 Check(!cache.
Receive(&device,0,bytes.data(),bytes.size(),30143),
"vehicle ordinal cannot enter GIF cache");
78 cache.
Reset();Check(!cache.
Texture(4002) && !cache.
Texture(-32768),
"device teardown releases association and textures");
79 Check(measurement.lifetime.expired(),"pending billboard queries can reject removed campaign assets");
80
81
82
83 Check(cache.
Assign(1,
"visible",8) && cache.
Assign(2,
"visible",8),
"visibility fixture shares artwork");
84 cache.
Update(&device,10000,send);
85 Check(cache.
Receive(&device,requests.back().token,bytes.data(),bytes.size(),10000),
"visibility fixture received");
86 awaitFrame(1,0,10000);
88 cache.
Update(&device,10040,send,
true);
90 "undrawn artwork skips decoding, texture updates and ADVIEW analysis despite lookups");
92 awaitFrame(1,1,10050);
94 "either visible group wakes the shared animation with ADVIEW disabled");
95 cache.
Update(&device,10080,send,
true);cache.
Update(&device,10100,send,
true);
97 "draw requests are consumed and off-screen artwork stays paused");
99 awaitFrame(1,0,10170,true);
101 "returning artwork catches up across skipped loops without replacing its texture");
102 Check(cache.
Measure(1).
metadata!=
nullptr,
"visible artwork resumes metadata analysis");
104
105
106
107 CityCampaignLogos largeCache;std::vector<CityLogos::AssignmentAsset> largeRequests;
109 auto largeBytes=Header(512,512);Frame(largeBytes,0,0,1,1,1,3,{1});largeBytes.push_back(0x3b);
110 Check(largeCache.
Assign(1,
"large-a",8) && largeCache.
Assign(2,
"large-b",8) && largeCache.
Assign(3,
"large-c",8),
111 "partial analysis fixtures assigned");
112 largeCache.
Update(&device,20000,largeSend);
113 for(const auto& request:largeRequests)
114 Check(largeCache.
Receive(&device,request.token,largeBytes.data(),largeBytes.size(),20000),
"large fixture received");
115 WaitFor([&]{largeCache.
Update(&device,20000,largeSend);
116 return largeCache.
Texture(1) && largeCache.
Texture(2) && largeCache.
Texture(3);},
"initial large frames available");
117 for(
int group=1;group<=3;++group)largeCache.
Measure(group);
118 for(unsigned tick=0;tick<2;++tick)
119 {
120 for(
int group=1;group<=3;++group)largeCache.
MarkDrawn(group);
121 largeCache.
Update(&device,20001+tick,largeSend,
true);
122 }
123 for(unsigned tick=0;tick<4;++tick)
124 {
125 largeCache.
MarkDrawn(3);largeCache.
Update(&device,20003+tick,largeSend,
true);
126 }
128 "off-screen partial snapshots release analysis slots for visible artwork");
129 for(unsigned tick=0;tick<4;++tick)
130 {
131 largeCache.
MarkDrawn(1);largeCache.
Update(&device,20007+tick,largeSend,
true);
132 }
134 "resumed analysis restarts a discarded partial scan correctly");
136
137
138
139 auto sequence=Header(512,512);
140 for(unsigned i=0;i<128;++i)Frame(sequence,i%16,i/16,1,1,1+i%3,1,{static_cast<unsigned char>(1+i%3)});
141 sequence.push_back(0x3b);
142 GifAnimationDecoder reference;Check(SUCCEEDED(reference.
Open(sequence.data(),sequence.size())),
"reference GIF opens");
143 {
145 auto state=worker.
Open(sequence.data(),sequence.size());
146 std::shared_ptr<const GifAnimationWorker::Result> completed;
147 WaitFor([&]{completed=state->Take();return bool(completed);},"initial worker decode");
148 for(size_t target:{size_t(127),size_t(0),size_t(83),size_t(2)})
149 {
151 WaitFor([&]{completed=state->Take();return bool(completed);},"worker catch-up decode");
152 const std::vector<uint32_t>* expected=nullptr;
153 Check(SUCCEEDED(reference.
RenderFrame(target,expected)) && completed->frame==target &&
154 completed->pixels==*expected,"asynchronous catch-up preserves exact disposal pixels");
155 }
156
157
158 std::atomic<bool> held{false},release{false};
159 std::thread publisher([&]{
160 std::unique_lock<std::mutex> hold(state->resultMutex);held.store(true);
161 while(!release.load())Sleep(1);
162 });
163 while(!held.load())Sleep(1);
165 const bool didNotWait=!state->Take();
166 release.store(true);publisher.join();
167 Check(didNotWait,"renderer never waits for a busy publication");
168 WaitFor([&]{completed=state->Take();return bool(completed);},"blocked publication recovers");
170 for(unsigned i=0;i<20;++i)
171 {
172 auto cancelled=worker.
Open(sequence.data(),sequence.size());
174 }
175 auto invalid=worker.
Open(
"broken",6);
176 WaitFor([&]{return FAILED(invalid->error.load());},"invalid background decode is reported");
178 }
179
180 Check(cache.
Assign(3,
"broken",7),
"malformed assignment");
181 cache.
Update(&device,40000,send);
182 Check(cache.
Receive(&device,requests.back().token,
"broken",6,40000),
"malformed transfer queued");
184 const auto beforeRetry=requests.size();cache.
Update(&device,70000,send);
185 Check(requests.size()==beforeRetry+1 && !cache.
Texture(3),
"failed worker decode schedules a fresh download");
187
188 Microsoft::WRL::ComPtr<ID3D11InfoQueue> queue;Check(SUCCEEDED(gpu.
Device()->QueryInterface(IID_PPV_ARGS(&queue))),
"debug queue available");
189 for(UINT64 i=0;i<queue->GetNumStoredMessages();++i)
190 {
191 SIZE_T size=0;queue->GetMessage(i,nullptr,&size);std::vector<unsigned char> storage(size);
192 auto* message=reinterpret_cast<D3D11_MESSAGE*>(storage.data());queue->GetMessage(i,message,&size);
193 Check(message->Severity>D3D11_MESSAGE_SEVERITY_WARNING,"no GPU integration warnings");
194 }
195 std::cout<<"PASS: "<<checks<<" production city cache/GIF/texture checks on WARP\n";return 0;
196 }
197 catch(const std::exception& e){std::cerr<<"FAIL: "<<e.what()<<'\n';return 1;}
198}
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
bool Receive(Rendering::RenderDevice *device, int32_t token, const void *bytes, size_t size, uint64_t now)
Rendering::RenderTexture * Texture(int32_t group) const
bool Assign(int32_t group, const char *filename, size_t capacity)
bool HasAnimatedArtwork() const
void Update(Rendering::RenderDevice *device, uint64_t now, const std::function< void(const CityLogos::AssignmentAsset &)> &send, bool measure=false)
void MarkDrawn(int32_t group) const
Measurement Measure(int32_t group) const
HRESULT Open(const wchar_t *path)
HRESULT RenderFrame(std::size_t index, const std::vector< std::uint32_t > *&pixels)
std::shared_ptr< State > Open(const void *bytes, size_t size)
void Cancel(const std::shared_ptr< State > &state)
void Request(const std::shared_ptr< State > &state, size_t frame)
ID3D11Device * Device() const
HRESULT Create(const DeviceOptions11 &options={})
HRESULT Initialize(Device11 &device, const std::filesystem::path &shaderDirectory={})
constexpr uint32_t READONLY
const Rendering::AdCreativeMetadata * metadata