Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/CloudTopPrototype11.h

Source at documentation-generation time. See Test catalog for fixture associations.

1// Controlled above-deck previews and GPU timestamps, using the shipping renderer.
2// No live client, camera, weather server or input is changed by this fixture.
3#include "CloudTopScene11.h"
4static void CloudTopHeightAudit(const fs::path& output,bool organic)
5{
6 using namespace CloudVolume;
7 const auto& billows=CloudBillows::Values();
8 for(int z=0;z<64;++z)for(int y=0;y<64;++y)for(int x=0;x<64;++x)
9 {
10 const auto at=[&](int a,int b,int c){return billows[(((c&63)*64+(b&63))*64)+(a&63)];};
11 const float center=at(x,y,z);
12 Check(std::isfinite(center) && center>=0,"finite nonnegative billow distance");
13 Check(std::abs(center-at(x+1,y,z))<=.125001f && std::abs(center-at(x,y+1,z))<=.125001f
14 && std::abs(center-at(x,y,z+1))<=.125001f,"billow Lipschitz bound used by clearance");
15 }
16 std::ofstream csv(output/"heights.csv");
17 csv<<"convection,minimum_km,mean_km,maximum_km,weather_allowance_maximum_km,columns,organic\n";
18 Parameters params;params.organic=organic;
19 for(unsigned weather:{0u,77u,153u,255u})
20 {
21 auto map=std::make_shared<CloudWeather::Map>();
22 map->mips.push_back({64,32,std::vector<uint8_t>(64*32,uint8_t(weather))});
24 params.weather.blend=1;
25 float minimum=100,maximum=0,allowanceMaximum=0;double sum=0;unsigned columns=0;
26 for(int y=-32;y<32;++y)for(int x=-32;x<32;++x)
27 {
28 const Point raw{.438f*params.radius+x*4.f,.895f*params.radius,.073f*params.radius+y*4.f};
29 const Point radial=Scale(raw,1.f/Length(raw)),surface=Scale(radial,params.radius);
30 const auto column=Boundaries(surface,params);
31 // Independent upper bound from the selected weather-growth and
32 // maximum shallow-relief allowances. Local crests may move as the
33 // shallow field changes; the regional height budget must not grow.
34 const float coarse=Noise(Add(Scale(surface,.01f),{19,7,31}));
35 const Point warp=Scale({1.5f,-1.1f,.9f},coarse-.5f);
36 const float broad=.65f*Noise(Add(Scale(surface,.04f),warp))+.35f*coarse;
37 const float cluster=organic ? Smooth((broad-.35f)/.3f) : Smooth((broad-.25f)/.5f);
38 const float topBillow=organic ? 1.f : Noise(Add(Scale(surface,.17f),warp));
39 const float normalizedWeather=weather/255.f;
40 const float growth=organic ? std::pow(normalizedWeather,.75f) : Smooth((normalizedWeather-.15f)/.85f);
41 const float allowedTop=(std::max)(column.base+2.5f,params.top+.7f+cluster*.12f+topBillow*.08f
42 +(.4f+.4f*column.structure)+growth*(cluster*8.2f+topBillow*(.5f+1.5f*cluster)));
43 Check(column.top<=allowedTop+.005f,"rounded tops stay within existing weather allowance");
44 Check(column.top<=params.top+MaxTopRiseKm,"22 km search envelope retained");
45 Check(Density(Scale(radial,params.radius+params.top),params)>.1f,"continuous nominal deck retained");
46 Check(Density(Scale(radial,params.radius+MaxTopRiseKm+params.top+.1f),params)==0,"empty above envelope");
47 float high=column.top+.01f,low=high;
48 while(Density(Scale(radial,params.radius+low),params)<.001f && low>params.top)low-=.1f;
49 high=low+.1f;
50 for(unsigned i=0;i<10;++i)
51 {
52 const float middle=(low+high)*.5f;
53 if(Density(Scale(radial,params.radius+middle),params)>=.001f)low=middle;else high=middle;
54 }
55 minimum=(std::min)(minimum,low);maximum=(std::max)(maximum,low);
56 allowanceMaximum=(std::max)(allowanceMaximum,allowedTop);sum+=low;++columns;
57 const auto p=Scale(surface,.13f);
58 Check(std::abs(CloudBillows::Sample(p.x,p.y,p.z)-CloudBillows::Sample(p.x+8,p.y-8,p.z+8))<.001f,
59 "billow texture wraps without a seam");
60 }
61 csv<<weather<<','<<minimum<<','<<sum/columns<<','<<maximum<<','<<allowanceMaximum<<','<<columns<<','<<organic<<'\n';
62 std::cout<<"Height audit "<<weather<<": "<<minimum<<".."<<maximum<<" km, mean "<<sum/columns<<std::endl;
63 }
64 Check(csv.good(),"top height output");
65}
66static void CloudTopPrototype(Device11& gpu,const fs::path& shaders,const fs::path& output,
67 const fs::path& reference,const fs::path& weatherPath)
68{
69 using namespace DirectX;
70 fs::create_directories(output);
71 SetEnvironmentVariableA("RISE_VOLUMETRIC_CLOUDS","1");
72 SetEnvironmentVariableA("RISE_CLOUD_SEED","0x52495345");
73 CloudRenderer11 renderer;
74 HR(renderer.Initialize(gpu.Device(),shaders),"top prototype renderer");
75 renderer.SetLightningEnabled(false);
76 CloudRenderer11 baseline;
77 if(!reference.empty())
78 {
79 HR(baseline.Initialize(gpu.Device(),reference),"top baseline renderer");
80 baseline.SetLightningEnabled(false);fs::create_directories(output/"before");
81 }
82 char nadirSetting[8]{};
83 const bool nadir=GetEnvironmentVariableA("RISE_TOP_NADIR",nadirSetting,sizeof(nadirSetting))!=0;
84 const auto option=[](const char* name,unsigned fallback) {
85 char text[32]{};const auto length=GetEnvironmentVariableA(name,text,sizeof(text));
86 if(!length)return fallback;
87 Check(length<sizeof(text),"top option length");
88 size_t end=0;const auto value=std::stoul(text,&end);
89 Check(end==length,"top option is an integer");return unsigned(value);
90 };
91 const unsigned samples=option("RISE_TOP_SAMPLES",1),batches=option("RISE_TOP_BATCHES",12);
92 const unsigned selectedAltitude=option("RISE_TOP_ALTITUDE",0),selectedWeather=option("RISE_TOP_WEATHER",999);
93 const unsigned selectedSun=option("RISE_TOP_SUN",9);
94 const unsigned resolutionPercent=option("RISE_TOP_RESOLUTION_PERCENT",50);
95 Check(resolutionPercent>=25 && resolutionPercent<=50,"top resolution percentage");
96 renderer.Pass().SetResolutionScale(float(resolutionPercent)*.01f);
97 Check(samples==1 || samples==2 || samples==4 || samples==8,"supported top MSAA");
98 Check(batches>=12 && batches<=512,"top timing batches");
99 Check(selectedAltitude==0 || selectedAltitude==18 || selectedAltitude==30 || selectedAltitude==117
100 || selectedAltitude==500 || selectedAltitude==1000 || selectedAltitude==3000,"top altitude selector");
101 Check(selectedWeather==999 || selectedWeather==25 || selectedWeather==77 || selectedWeather==153
102 || selectedWeather==255 || selectedWeather==256,"top weather selector");
103 Check(selectedSun==9 || selectedSun<=2,"top sunlight selector");
104 const bool wide=nadir || option("RISE_TOP_WIDE",0)!=0;
105 const unsigned sceneMode=option("RISE_TOP_SCENE",0);
106 Check(sceneMode<=2,"top scene must be sky, planet, or planet with foreground");
107 CloudTopScene11 geometry;
108 if(sceneMode)geometry.Initialize(gpu.Device(),shaders);
109 // Isolated shape diagnostics can bind a separately baked distance field.
110 // The shipping renderer and baseline continue using their original noise.
111 char billowPath[MAX_PATH]{};
112 if(GetEnvironmentVariableA("RISE_TOP_BILLOW_VOLUME",billowPath,MAX_PATH))
113 {
114 std::ifstream file(billowPath,std::ios::binary);
115 const UINT size=Integer(file),levels=Integer(file);
116 Check((size==128 && levels==8) || (size==256 && levels==9),"diagnostic billow dimensions");
117 std::vector<std::vector<uint16_t>> data(levels);
118 std::vector<D3D11_SUBRESOURCE_DATA> initial(levels);
119 for(UINT mip=0;mip<levels;++mip)
120 {
121 const UINT side=size>>mip;
122 data[mip].resize(size_t(side)*side*side);
123 file.read(reinterpret_cast<char*>(data[mip].data()),data[mip].size()*sizeof(uint16_t));
124 Check(file.good(),"diagnostic billow mip bytes");
125 initial[mip]={data[mip].data(),side*sizeof(uint16_t),side*side*sizeof(uint16_t)};
126 }
127 Check(file.peek()==std::char_traits<char>::eof(),"exact diagnostic billow payload");
128 D3D11_TEXTURE3D_DESC vd{};
129 vd.Width=vd.Height=vd.Depth=size;vd.MipLevels=levels;
130 vd.Format=DXGI_FORMAT_R16_FLOAT;vd.Usage=D3D11_USAGE_IMMUTABLE;vd.BindFlags=D3D11_BIND_SHADER_RESOURCE;
131 ComPtr<ID3D11Texture3D> volume;ComPtr<ID3D11ShaderResourceView> field;
132 HR(gpu.Device()->CreateTexture3D(&vd,initial.data(),&volume),"diagnostic billow volume");
133 HR(gpu.Device()->CreateShaderResourceView(volume.Get(),nullptr,&field),"diagnostic billow view");
134 // This fixture owns a non-const renderer; change only its diagnostic binding.
135 const_cast<Parameters11&>(renderer.Parameters()).Texture("billowVolume",field.Get());
136 }
137 char macroPath[MAX_PATH]{};
138 if(GetEnvironmentVariableA("RISE_TOP_MACRO_MAP",macroPath,MAX_PATH))
139 {
140 std::ifstream file(macroPath,std::ios::binary);
141 const UINT w=Integer(file),h=Integer(file),levels=Integer(file);
142 Check((w==2048 || w==4096) && h==w/2 && levels==(w==2048 ? 12u : 13u),"diagnostic macro dimensions");
143 std::vector<std::vector<uint16_t>> data(levels);
144 std::vector<D3D11_SUBRESOURCE_DATA> initial(levels);
145 for(UINT mip=0;mip<levels;++mip)
146 {
147 const UINT mw=(std::max)(1u,w>>mip),mh=(std::max)(1u,h>>mip);
148 data[mip].resize(size_t(mw)*mh*4);
149 file.read(reinterpret_cast<char*>(data[mip].data()),data[mip].size()*sizeof(uint16_t));
150 Check(file.good(),"diagnostic macro mip bytes");
151 initial[mip]={data[mip].data(),mw*4*sizeof(uint16_t),0};
152 }
153 Check(file.peek()==std::char_traits<char>::eof(),"exact diagnostic macro payload");
154 D3D11_TEXTURE2D_DESC md{};
155 md.Width=w;md.Height=h;md.MipLevels=levels;md.ArraySize=1;md.SampleDesc={1,0};
156 md.Format=DXGI_FORMAT_R16G16B16A16_FLOAT;md.Usage=D3D11_USAGE_IMMUTABLE;md.BindFlags=D3D11_BIND_SHADER_RESOURCE;
157 ComPtr<ID3D11Texture2D> texture;ComPtr<ID3D11ShaderResourceView> field;
158 HR(gpu.Device()->CreateTexture2D(&md,initial.data(),&texture),"diagnostic macro map");
159 HR(gpu.Device()->CreateShaderResourceView(texture.Get(),nullptr,&field),"diagnostic macro view");
160 const_cast<Parameters11&>(renderer.Parameters()).Texture("cloudMacro",field.Get());
161 }
162 // Reduced software previews are shape comparisons only. Default dimensions
163 // remain the native test target; CSV dimensions make reduced runs explicit.
164 const unsigned previewDivisor=option("RISE_TOP_PREVIEW_DIVISOR",1);
165 Check(previewDivisor==1 || previewDivisor==2 || previewDivisor==4,"supported preview divisor");
166 const unsigned viewportHeight=option("RISE_TOP_VIEWPORT_HEIGHT",wide ? 1351u : 1440u);
167 Check(viewportHeight>=256 && viewportHeight<=4096,"supported top viewport height");
168 const UINT width=((wide ? 3440u : 2560u)+previewDivisor-1)/previewDivisor;
169 const UINT height=(viewportHeight+previewDivisor-1)/previewDivisor;
170 const bool useTemporal=option("RISE_TOP_TEMPORAL",0)!=0;
171 const bool pipelinedTiming=option("RISE_TOP_PIPELINED_TIMING",0)!=0;
172 const float motionKms=float(option("RISE_TOP_MOTION_MPS",0))*.001f;
173 Check(!useTemporal || resolutionPercent==25,"temporal prototype requires quarter-resolution input");
174 CloudTemporalPrototype11 temporal;
175 if(useTemporal)temporal.Initialize(gpu.Device(),shaders,width,height);
176 D3D11_TEXTURE2D_DESC desc{};
177 desc.Width=width;desc.Height=height;desc.MipLevels=desc.ArraySize=1;
178 desc.SampleDesc={samples,0};desc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;
179 desc.BindFlags=D3D11_BIND_RENDER_TARGET;
180 ComPtr<ID3D11Texture2D> image;ComPtr<ID3D11RenderTargetView> target;
181 HR(gpu.Device()->CreateTexture2D(&desc,nullptr,&image),"top image");
182 HR(gpu.Device()->CreateRenderTargetView(image.Get(),nullptr,&target),"top target");
183 SceneDepth11 depth;HR(depth.Create(gpu.Device(),width,height,desc.SampleDesc),"top depth");
184 const D3D11_VIEWPORT viewport{0,0,float(width),float(height),0,1};
185 const auto angleOption=[](const char* name,float fallback) {
186 char text[48]{};const auto size=GetEnvironmentVariableA(name,text,sizeof(text));
187 if(!size)return fallback;
188 Check(size<sizeof(text),"top geographic option length");
189 size_t end=0;const float value=std::stof(text,&end);
190 Check(end==size && std::isfinite(value),"finite top geographic option");return value;
191 };
192 const float latitude=angleOption("RISE_TOP_LATITUDE",-4.1901f),longitude=angleOption("RISE_TOP_LONGITUDE",-26.07645f);
193 Check(std::abs(latitude)<=90 && std::abs(longitude)<=180,"valid top geographic coordinates");
194 const float lat=XMConvertToRadians(latitude),lon=XMConvertToRadians(longitude);
195 const auto radial=XMVectorSet(-std::sin(lon)*std::cos(lat),std::cos(lon)*std::cos(lat),std::sin(lat),0);
196 const auto east=XMVector3Normalize(XMVector3Cross(radial,XMVectorSet(0,0,1,0)));
197 XMFLOAT4X4 view,projection;
198 // Finite geometry must use the live exterior projection (globals.h),
199 // including its D24 depth precision and far clipping. Keep the historical
200 // empty-sky fixture unchanged for comparison with its earlier captures.
201 const float nearZ=sceneMode ? .001f : .0001f;
202 const float farZ=sceneMode ? 384.f : 100000.f;
203 const float nearWidth=nearZ*std::tan(XMConvertToRadians(115.f)*.5f);
204 XMStoreFloat4x4(&projection,XMMatrixPerspectiveRH(nearWidth,nearWidth*height/width,nearZ,farZ));
205 D3D11_QUERY_DESC query{D3D11_QUERY_TIMESTAMP_DISJOINT,0};
206 ComPtr<ID3D11Query> disjoint,begin,middle,end;
207 HR(gpu.Device()->CreateQuery(&query,&disjoint),"top timing frequency");
208 query.Query=D3D11_QUERY_TIMESTAMP;
209 HR(gpu.Device()->CreateQuery(&query,&begin),"top timing begin");
210 HR(gpu.Device()->CreateQuery(&query,&middle),"top timing middle");
211 HR(gpu.Device()->CreateQuery(&query,&end),"top timing end");
212 std::ofstream csv(output/"timings.csv");
213 csv<<"view,width,height,cloud_gpu_ms,baseline_gpu_ms,msaa,cloud_gpu_p95_ms,baseline_gpu_p95_ms,resolution_percent,raw_cloud_gpu_ms,reconstruction_gpu_ms,cloud_gpu_max_ms,cloud_frames_over_12_ms,cloud_measured_frames,scene_mode\n";
215 params.organic=option("RISE_TOP_ORGANIC",0)!=0;
216 CloudTopHeightAudit(output,params.organic);
217 Check(!params.organic || !useTemporal,"integrated organic pass owns temporal reconstruction");
218 for(unsigned weather:{25u,77u,153u,255u,256u})
219 {
220 if(selectedWeather!=999 && weather!=selectedWeather)continue;
221 if(weather==256 && weatherPath.empty())continue;
222 auto map=std::make_shared<CloudWeather::Map>();
223 if(weather==256)
224 {
225 // Little-endian uint32 width,height followed by unmodified R8 pixels.
226 std::ifstream file(weatherPath,std::ios::binary);
227 const UINT w=Integer(file),h=Integer(file);
228 Check((w==2048 || w==4096) && h==w/2,"supported captured convection dimensions");
229 map->mips.push_back({w,h,std::vector<uint8_t>(size_t(w)*h)});
230 file.read(reinterpret_cast<char*>(map->mips[0].pixels.data()),size_t(w)*h);
231 Check(file.good() && file.peek()==std::char_traits<char>::eof(),"exact captured convection size");
232 }
233 else map->mips.push_back({64,32,std::vector<uint8_t>(64*32,uint8_t(weather))});
235 std::cout<<"Top comparison: upload weather "<<weather<<std::endl;
236 renderer.UpdateWeather(map,60);
237 for(unsigned i=0;i<256 && renderer.WeatherFrame().current!=map;++i)
238 HR(renderer.PrepareResources(gpu.Context()),"top weather");
239 Check(renderer.WeatherFrame().current==map,"complete captured convection upload");
240 renderer.UpdateWeather(map,60);params.weather=renderer.WeatherFrame();
241 if(!reference.empty())
242 {
243 baseline.UpdateWeather(map,60);
244 for(unsigned i=0;i<256 && baseline.WeatherFrame().current!=map;++i)
245 HR(baseline.PrepareResources(gpu.Context()),"baseline weather");
246 Check(baseline.WeatherFrame().current==map,"complete baseline convection upload");
247 baseline.UpdateWeather(map,60);
248 }
249 for(float altitude:{18.f,30.f,117.f,500.f,1000.f,3000.f})for(unsigned lighting:{0u,1u,2u})
250 {
251 // Preserve the default suite; distant orbital cases are explicit.
252 if(!selectedAltitude && altitude>117)continue;
253 if(selectedAltitude && unsigned(altitude)!=selectedAltitude)continue;
254 if(selectedSun!=9 && lighting!=selectedSun)continue;
255 if(nadir && (altitude<117 || lighting==1))continue;
256 const float downSlope=angleOption("RISE_TOP_DOWN_SLOPE",altitude==117 ? .55f : .22f);
257 Check(downSlope>=0 && downSlope<=10,"valid diagnostic downward camera slope");
258 const auto direction=nadir ? -radial : XMVector3Normalize(east-radial*downSlope);
259 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),direction,nadir ? east : radial));
260 XMFLOAT3 eye,sun;
261 XMStoreFloat3(&eye,radial*(params.radius+altitude));
262 XMStoreFloat3(&sun,lighting==2 ? -radial : XMVector3Normalize(-radial*(lighting ? .35f : .8f)
263 -east*(lighting ? .8f : .3f)-XMVector3Cross(east,radial)*.45f));
264 // Match render.cpp's incident light and atmospheric extinction.
265 // SUN1 (fixture sun2) is overhead. Keep published/client haze
266 // calibration distinct from clear-weather visibility.
267 const float incident=std::exp(-.5f*std::exp(-params.top/7.5f));
268 const XMFLOAT4 haze(192.f/255,192.f/255,1,CloudVolume::AtmosphericHazeDistanceKm(params.top));
269 const auto name=std::to_string(unsigned(altitude))+"km-"+(weather==256 ? "live" : "w"+std::to_string(weather))
270 +"-sun"+std::to_string(lighting);
271 temporal.ResetHistory();
272 const XMFLOAT3 originalEye=eye;
273 double total[2]{},rawTotal=0,resolveTotal=0;unsigned measured[2]{};std::vector<double> durations[2];
274 struct Timing {ComPtr<ID3D11Query> disjoint,begin,middle,end;unsigned batch,variant;};
275 std::vector<Timing> pending;
276 const auto collect=[&](const Timing& q) {
277 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT timing{};UINT64 a=0,b=0,m=0;
278 const auto wait=[&](ID3D11Query* queryObject,void* data,UINT bytes) {
279 const auto limit=GetTickCount64()+30000;HRESULT hr;
280 while((hr=gpu.Context()->GetData(queryObject,data,bytes,0))==S_FALSE)
281 {Check(GetTickCount64()<limit,"top timing timeout");Sleep(1);}
282 HR(hr,"top timestamp readback");
283 };
284 wait(q.disjoint.Get(),&timing,sizeof(timing));wait(q.begin.Get(),&a,sizeof(a));wait(q.middle.Get(),&m,sizeof(m));wait(q.end.Get(),&b,sizeof(b));
285 if(q.batch>=4 && !timing.Disjoint){const double ms=1000.*double(b-a)/double(timing.Frequency);
286 total[q.variant]+=ms;++measured[q.variant];durations[q.variant].push_back(ms);
287 if(!q.variant){rawTotal+=1000.*double(m-a)/double(timing.Frequency);resolveTotal+=1000.*double(b-m)/double(timing.Frequency);}}
288 };
289 for(unsigned batch=0;batch<batches;++batch)for(unsigned pass=0;pass<(reference.empty() ? 1u : 2u);++pass)
290 {
291 const unsigned variant=reference.empty() ? 0 : (pass+batch)%2;
292 Timing q{disjoint,begin,middle,end,batch,variant};
293 if(pipelinedTiming)
294 {
295 D3D11_QUERY_DESC description{D3D11_QUERY_TIMESTAMP_DISJOINT,0};
296 HR(gpu.Device()->CreateQuery(&description,&q.disjoint),"pipelined frequency query");
297 description.Query=D3D11_QUERY_TIMESTAMP;
298 HR(gpu.Device()->CreateQuery(&description,&q.begin),"pipelined begin query");
299 HR(gpu.Device()->CreateQuery(&description,&q.middle),"pipelined middle query");
300 HR(gpu.Device()->CreateQuery(&description,&q.end),"pipelined end query");
301 }
302 auto& active=variant ? baseline : renderer;
303 const float travelled=(float(batch)-float(batches-1))*motionKms/60;
304 XMStoreFloat3(&eye,XMLoadFloat3(&originalEye)+east*travelled);
305 if(useTemporal && !variant)
306 {
307 temporal.BeginFrame(view,projection,eye,sun,params,batch);
308 const_cast<Parameters11&>(renderer.Parameters()).Set("riseCloudJitterUV",temporal.Jitter());
309 }
310 const float background[]={.025f,.035f,.07f,1};
311 const auto firstDrawStarted=GetTickCount64();
312 if(batch==0)std::cout<<"Top first draw: "<<name<<" variant="<<variant<<" prepare geometry"<<std::endl;
313 gpu.Context()->ClearRenderTargetView(target.Get(),background);
314 gpu.Context()->ClearDepthStencilView(depth.WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,1,0);
315 if(sceneMode)geometry.Draw(gpu.Context(),target.Get(),depth,viewport,view,projection,eye,params.radius,sceneMode==2);
316 if(batch==0)std::cout<<"Top first draw: "<<name<<" variant="<<variant<<" submit clouds"<<std::endl;
317 gpu.Context()->Begin(q.disjoint.Get());gpu.Context()->End(q.begin.Get());
318 HR(active.Render(gpu.Context(),target.Get(),depth,viewport,view,projection,eye,params,sun,
319 {240.f/255*incident,245.f/255*incident,incident,1},{.3f,.4f,.5f,1},{.125f,.375f,.25f,1},
320 {.6f,.7f,.8f,CloudVolume::ClearVisibilityKm},haze),"top render");
321 gpu.Context()->End(q.middle.Get());
322 if(useTemporal && !variant)
323 temporal.Render(gpu.Context(),renderer.Pass().Image(),renderer.Pass().Distance(),target.Get(),viewport,view,projection,eye);
324 gpu.Context()->End(q.end.Get());gpu.Context()->End(q.disjoint.Get());
325 if(batch==0)std::cout<<"Top first draw submitted: "<<name<<" variant="<<variant<<" wall="<<GetTickCount64()-firstDrawStarted<<" ms"<<std::endl;
326 if(pipelinedTiming)pending.push_back(std::move(q));
327 else{gpu.Context()->Flush();collect(q);}
328 }
329 for(const auto& q:pending)collect(q);
330 // Complete every timestamp before any screenshot readback. Saving
331 // the first variant inside the last paired batch could stall over
332 // 350 ms and reset only the second variant's temporal history.
333 // Give both images an identical fresh eight-frame static history,
334 // independently of benchmark scheduling, shader cost or save time.
335 constexpr unsigned previewFrames=8;
336 for(unsigned variant=0;variant<(reference.empty() ? 1u : 2u);++variant)
337 {
338 auto& active=variant ? baseline : renderer;
339 active.Pass().ResetCloudHistory();temporal.ResetHistory();eye=originalEye;
340 for(unsigned frame=0;frame<previewFrames;++frame)
341 {
342 if(useTemporal && !variant)
343 {
344 temporal.BeginFrame(view,projection,eye,sun,params,frame);
345 const_cast<Parameters11&>(renderer.Parameters()).Set("riseCloudJitterUV",temporal.Jitter());
346 }
347 const float background[]={.025f,.035f,.07f,1};
348 gpu.Context()->ClearRenderTargetView(target.Get(),background);
349 gpu.Context()->ClearDepthStencilView(depth.WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,1,0);
350 if(sceneMode)geometry.Draw(gpu.Context(),target.Get(),depth,viewport,view,projection,eye,params.radius,sceneMode==2);
351 HR(active.Render(gpu.Context(),target.Get(),depth,viewport,view,projection,eye,params,sun,
352 {240.f/255*incident,245.f/255*incident,incident,1},{.3f,.4f,.5f,1},{.125f,.375f,.25f,1},
353 {.6f,.7f,.8f,CloudVolume::ClearVisibilityKm},haze),"top preview render");
354 if(useTemporal && !variant)
355 temporal.Render(gpu.Context(),renderer.Pass().Image(),renderer.Pass().Distance(),target.Get(),viewport,view,projection,eye);
356 }
357 HR(SaveWICTextureToFile(gpu.Context(),image.Get(),GUID_ContainerFormatPng,
358 ((variant ? output/"before" : output)/(name+".png")).c_str()),"save top preview");
359 }
360 Check(measured[0]>0 && (reference.empty() || measured[1]>0),"top valid timestamps");
361 const auto percentile=[](std::vector<double>& values) {
362 if(values.empty())return 0.;std::sort(values.begin(),values.end());
363 return values[(size_t)(std::ceil(values.size()*.95)-1)];
364 };
365 csv<<name<<','<<width<<','<<height<<','<<total[0]/measured[0]<<','
366 <<(measured[1] ? total[1]/measured[1] : 0)<<','<<samples<<','
367 <<percentile(durations[0])<<','<<percentile(durations[1])<<','<<unsigned(renderer.Pass().ResolutionScale()*100)<<','<<rawTotal/measured[0]<<','<<resolveTotal/measured[0]<<','
368 <<*std::max_element(durations[0].begin(),durations[0].end())<<','
369 <<std::count_if(durations[0].begin(),durations[0].end(),[](double ms){return ms>12;})<<','<<measured[0]<<','<<sceneMode<<'\n';
370 std::cout<<name<<": "<<total[0]/measured[0]<<" ms cloud GPU"<<std::endl;
371 }
372 }
373 Check(csv.good(),"top timing output");
374 std::ofstream captures(output/"capture-procedure.txt");
375 captures<<"All benchmark timestamp results are collected before image readback.\n"
376 <<"Each variant independently resets integrated and optional prototype temporal history,\n"
377 <<"then renders eight identical static preview frames at the final measured camera position.\n"
378 <<"The eighth frame is saved outside every measured timestamp region.\n"
379 <<"Candidate and before/ filenames retain the same weather/sun convention.\n";
380 Check(captures.good(),"top capture procedure output");
381 DebugMessages(gpu);
382}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
const std::vector< float > & Values()
float Sample(float x, float y, float z)
float Smooth(float x)
Definition CloudVolume.h:51
constexpr float MaxTopRiseKm
Definition CloudVolume.h:23
Point Scale(Point p, float s)
Definition CloudVolume.h:93
float AtmosphericHazeDistanceKm(float nominalTop)
Point Add(Point a, Point b)
Definition CloudVolume.h:95
float Noise(Point p, uint32_t seed=DefaultSeed, int mask=63)
Column Boundaries(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
float Density(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
float Length(Point p)
Definition CloudVolume.h:94
void BuildMips(Map &map)
Definition DDS.h:24
DIRECTX_TOOLKIT_API HRESULT __cdecl SaveWICTextureToFile(_In_ ID3D11DeviceContext *pContext, _In_ ID3D11Resource *pSource, _In_ REFGUID guidContainerFormat, _In_z_ const wchar_t *fileName, _In_opt_ const GUID *targetFormat=nullptr, _In_ std::function< void __cdecl(IPropertyBag2 *)> setCustomProps=nullptr, _In_ bool forceSRGB=false)
CloudWeather::Frame weather
Definition CloudVolume.h:35