1#pragma once
2#include "../Rendering/CloudTemporal11.h"
3#include <DirectXPackedVector.h>
4#include <limits>
5
6static void CloudTemporalAudit(Device11& gpu,const fs::path& shaders)
7{
9 using History=CloudTemporal11;
10 char reuseSetting[8]{};
11 const bool reuseAudit=GetEnvironmentVariableA("RISE_TEMPORAL_REUSE_AUDIT",reuseSetting,sizeof(reuseSetting))!=0;
12 const bool currentProof=reuseAudit && reuseSetting[0]=='2';
13 History history;HR(history.Initialize(gpu.Device(),shaders),"history initialize");
14 History::Frame frame;
15 XMStoreFloat4x4(&frame.view,XMMatrixIdentity());frame.inverseView=frame.view;
16 XMStoreFloat4x4(&frame.projection,XMMatrixPerspectiveFovRH(1,1,.001f,10000));
17 frame.eye={0,3056.6f,0};frame.sun={0,-1,0};frame.layer={2939.6f,1.8f,10,0};
18 frame.light={.8f,.9f,1,1};frame.ambient={.3f,.4f,.5f,1};frame.milliseconds=1000;
19 auto orbit=frame;orbit.eye.x+=5.28f/60;orbit.milliseconds+=17;
20 Check(History::Compatible(frame,orbit),"normal orbital translation reprojects");
21 auto pan=orbit;XMStoreFloat4x4(&pan.view,XMMatrixRotationY(.03f));
22 Check(History::Compatible(frame,pan),"ordinary camera pan reprojects");
23 auto wrapA=frame,wrapB=frame;wrapA.noiseOffset.x=3199.99f;wrapB.noiseOffset.x=-3199.99f;
24 Check(History::Compatible(wrapA,wrapB),"advection wrap retains history");
25 unsigned resets=0;
26 const auto reject=[&](const History::Frame& next) {Check(!History::Compatible(frame,next),"history discontinuity rejected");++resets;};
27 auto next=frame;next.eye.z+=10;reject(next);
28 next=frame;next.milliseconds+=500;reject(next);
29 next=frame;next.milliseconds-=1;reject(next);
30 next=frame;next.sun.x=.1f;reject(next);
31 next=frame;next.light.x=.1f;reject(next);
32 next=frame;next.ambient.x=.9f;reject(next);
33 next=frame;next.airglow.y=.2f;reject(next);
34 next=frame;next.horizon.z=.2f;reject(next);
35 next=frame;next.atmosphere.w=57;reject(next);
36 next=frame;next.transientLight=true;reject(next);
37 Check(!History::Compatible(next,frame),"transient light ending resets history");
38 next=frame;next.nightVision.w=1;reject(next);
39 next=frame;next.layer.z=11;reject(next);
40 next=frame;next.projection._11*=1.5f;reject(next);
41 next=frame;next.currentWeather=&next;reject(next);
42 next=frame;next.previousWeather=&frame;reject(next);
43 next=frame;next.weatherBlend=.5f;reject(next);
44 next=frame;XMStoreFloat4x4(&next.view,XMMatrixRotationY(1));reject(next);
45 next=frame;next.noiseOffset.x=1;reject(next);
46 next=frame;next.eye.x=std::numeric_limits<float>::quiet_NaN();reject(next);
47 next=frame;next.weatherBlend=std::numeric_limits<float>::infinity();reject(next);
48
49 constexpr unsigned width=8,height=8;
50 std::vector<XMFLOAT4> pixels(width*height,{.2f,.4f,.6f,1});
51 std::vector<XMFLOAT2> distances(width*height,{100,101});
52 ComPtr<ID3D11Texture2D> source,sourceDepth;
53 ComPtr<ID3D11ShaderResourceView> image,depth;
54 D3D11_TEXTURE2D_DESC td{};td.Width=width;td.Height=height;td.MipLevels=td.ArraySize=1;
55 td.SampleDesc={1,0};td.Format=DXGI_FORMAT_R32G32B32A32_FLOAT;td.BindFlags=D3D11_BIND_SHADER_RESOURCE;
56 D3D11_SUBRESOURCE_DATA data{pixels.data(),width*sizeof(XMFLOAT4),0};
57 HR(gpu.Device()->CreateTexture2D(&td,&data,&source),"history source");
58 HR(gpu.Device()->CreateShaderResourceView(source.Get(),nullptr,&image),"history source view");
59 td.Format=DXGI_FORMAT_R32G32_FLOAT;data={distances.data(),width*sizeof(XMFLOAT2),0};
60 HR(gpu.Device()->CreateTexture2D(&td,&data,&sourceDepth),"history depth");
61 HR(gpu.Device()->CreateShaderResourceView(sourceDepth.Get(),nullptr,&depth),"history depth view");
62 ComPtr<ID3D11DepthStencilState> noDepth;D3D11_DEPTH_STENCIL_DESC ds{};
63 HR(gpu.Device()->CreateDepthStencilState(&ds,&noDepth),"history no depth");
64 ComPtr<ID3D11RasterizerState> raster;D3D11_RASTERIZER_DESC rs{};
65 rs.FillMode=D3D11_FILL_SOLID;rs.CullMode=D3D11_CULL_NONE;rs.DepthClipEnable=TRUE;
66 HR(gpu.Device()->CreateRasterizerState(&rs,&raster),"history rasterizer");
67 const auto render=[&] {
68 gpu.Context()->ClearState();gpu.Context()->OMSetDepthStencilState(noDepth.Get(),0);
69 gpu.Context()->RSSetState(raster.Get());gpu.Context()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
70 HR(history.Resolve(gpu.Context(),image.Get(),depth.Get()),"history resolve");
71 };
72 const auto read=[&](ID3D11ShaderResourceView* view,
const auto& inspect) {
73 ComPtr<ID3D11Resource> resource;view->GetResource(&resource);ComPtr<ID3D11Texture2D> texture,staging;
74 HR(resource.As(&texture),"history texture");D3D11_TEXTURE2D_DESC desc{};texture->GetDesc(&desc);
75 desc.Usage=D3D11_USAGE_STAGING;desc.BindFlags=0;desc.CPUAccessFlags=D3D11_CPU_ACCESS_READ;
76 HR(gpu.Device()->CreateTexture2D(&desc,nullptr,&staging),"history readback");
77 gpu.Context()->CopyResource(staging.Get(),texture.Get());D3D11_MAPPED_SUBRESOURCE mapped{};
78 HR(gpu.Context()->Map(staging.Get(),0,D3D11_MAP_READ,0,&mapped),"history map");
79 for(unsigned y=0;y<desc.Height;++y)inspect(static_cast<const uint8_t*>(mapped.pData)+y*mapped.RowPitch,desc.Width);
80 gpu.Context()->Unmap(staging.Get(),0);
81 };
82 for(unsigned i=0;i<8;++i)
83 {
84 frame.milliseconds+=17;frame.eye.x+=.088f;
85 HR(history.BeginFrame(frame,32,32,width,height),"history begin");
86 if(i)Check(history.HasHistory(),"continuous orbit preserves history");
87 render();
88 }
89 float largestOpaqueBound=0;
90 read(history.Distance(),[&](
const uint8_t* row,
unsigned count) {
91 const auto* value=reinterpret_cast<const XMFLOAT2*>(row);
92 for(unsigned i=0;i<count;++i)
93 {
94 Check(value[i].x==100,"history retains current cloud hit");
95 largestOpaqueBound=(std::max)(largestOpaqueBound,value[i].y);
96 if(currentProof)Check(value[i].y==101,"current opacity proof does not accumulate camera displacement");
97 else if(reuseAudit)Check(value[i].y>=101 && value[i].y<=101.617f,"opaque history includes accumulated camera displacement");
98 else Check(value[i].y==1e8f,"history forbids unproven opaque reuse");
99 }
100 });
101 if(reuseAudit)
102 {
103 if(!currentProof)Check(largestOpaqueBound>101.615f,"opaque history bound accumulates all seven camera displacements");
104
105
106 history.ResetHistory();
107 for(auto& distance:distances)distance={100,101};
108 distances[3*width+3].y=150;
109 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
110 frame.milliseconds+=17;HR(history.BeginFrame(frame,32,32,width,height),"opaque bound footprint frame");
111 const auto jitter=history.Jitter();render();unsigned rowIndex=0,farContributors=0;
112 read(history.Distance(),[&](
const uint8_t* row,
unsigned count) {
113 const auto* value=reinterpret_cast<const XMFLOAT2*>(row);
114 for(unsigned x=0;x<count;++x)
115 {
116 const int cellX=int(std::floor(((x+.5f)/count-jitter.x)*width-.5f));
117 const int cellY=int(std::floor(((rowIndex+.5f)/16-jitter.y)*height-.5f));
118 const bool contains=cellX<=3 && cellX+1>=3 && cellY<=3 && cellY+1>=3;
119 Check(value[x].y==(contains ? 150.f : 101.f),"opaque bound uses furthest bilinear contributor");
120 farContributors+=contains;
121 }
122 ++rowIndex;
123 });
124 Check(farContributors>0,"distant contributor was exercised");
125 for(auto& distance:distances)distance.y=101;
126 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
127 frame.milliseconds+=17;HR(history.BeginFrame(frame,32,32,width,height),"previous opaque bound frame");render();
128 unsigned retained=0;
129 read(history.Distance(),[&](
const uint8_t* row,
unsigned count) {
130 const auto* value=reinterpret_cast<const XMFLOAT2*>(row);
131 for(unsigned x=0;x<count;++x){Check(value[x].y==101 || value[x].y==150,"retained bound is not averaged");retained+=value[x].y==150;}
132 });
133 if(currentProof)Check(retained==0,"old bounds cannot spread into the current opacity proof");
134 else Check(retained>0,"reprojected history retains its farther opacity bound");
135
136
137 history.ResetHistory();distances[3*width+3].y=1e8f;
138 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
139 frame.milliseconds+=17;HR(history.BeginFrame(frame,32,32,width,height),"transparent bound frame");render();
140 unsigned unproven=0;
141 read(history.Distance(),[&](
const uint8_t* row,
unsigned count) {
142 const auto* value=reinterpret_cast<const XMFLOAT2*>(row);
143 for(unsigned x=0;x<count;++x){Check(value[x].y==101 || value[x].y==1e8f,"transparent bound is not averaged");unproven+=value[x].y==1e8f;}
144 });
145 Check(unproven==farContributors,"every transparent contributor prevents opaque reuse");
146 if(currentProof)
147 {
148 history.ResetHistory();
149 for(auto& pixel:pixels)pixel={.16f,.32f,.48f,.8f};
150 for(auto& distance:distances)distance={100,1e8f};
151 gpu.Context()->UpdateSubresource(source.Get(),0,nullptr,pixels.data(),width*sizeof(XMFLOAT4),0);
152 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
153 frame.milliseconds+=17;HR(history.BeginFrame(frame,32,32,width,height),"translucent retained color frame");render();
154 for(auto& pixel:pixels)pixel={.2f,.4f,.6f,1};
155 for(auto& distance:distances)distance={100,101};
156 gpu.Context()->UpdateSubresource(source.Get(),0,nullptr,pixels.data(),width*sizeof(XMFLOAT4),0);
157 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
158 frame.milliseconds+=17;HR(history.BeginFrame(frame,32,32,width,height),"opaque current but translucent reconstruction frame");render();
159 read(history.Distance(),[&](
const uint8_t* row,
unsigned count) {
160 const auto* value=reinterpret_cast<const XMFLOAT2*>(row);
161 for(unsigned x=0;x<count;++x)Check(value[x].y==101,"uniform opaque neighborhood clamps away translucent history");
162 });
163
164
165
166
167 history.ResetHistory();
168 for(auto& pixel:pixels)pixel={.16f,.32f,.48f,.8f};
169 for(auto& distance:distances)distance={100,1e8f};
170 gpu.Context()->UpdateSubresource(source.Get(),0,nullptr,pixels.data(),width*sizeof(XMFLOAT4),0);
171 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
172 frame.milliseconds+=17;HR(history.BeginFrame(frame,32,32,width,height),"edge translucent history frame");render();
173 for(unsigned y=0;y<height;++y)for(unsigned x=2;x<=5;++x)
174 {
175 pixels[y*width+x]={.2f,.4f,.6f,1};
176 distances[y*width+x]={100,101};
177 }
178 gpu.Context()->UpdateSubresource(source.Get(),0,nullptr,pixels.data(),width*sizeof(XMFLOAT4),0);
179 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
180 frame.milliseconds+=17;HR(history.BeginFrame(frame,32,32,width,height),"opaque stripe with translucent neighbor frame");
181 const auto stripeJitter=history.Jitter();render();
182 std::vector<float> reconstructedAlpha;
183 read(history.Image(),[&](
const uint8_t* row,
unsigned count) {
184 const auto* value=reinterpret_cast<const uint16_t*>(row);
185 for(unsigned x=0;x<count;++x)reconstructedAlpha.push_back(PackedVector::XMConvertHalfToFloat(value[x*4+3]));
186 });
187 unsigned rejected=0,outputPixel=0;
188 read(history.Distance(),[&](
const uint8_t* row,
unsigned count) {
189 const auto* value=reinterpret_cast<const XMFLOAT2*>(row);
190 for(unsigned x=0;x<count;++x,++outputPixel)
191 {
192 const int cellX=int(std::floor(((x+.5f)/count-stripeJitter.x)*width-.5f));
193 if(cellX>=2 && cellX+1<=5 && reconstructedAlpha[outputPixel]<.99f)
194 {
195 Check(value[x].y==1e8f,"nonopaque reconstructed coverage prevents current-depth reuse");
196 ++rejected;
197 }
198 }
199 });
200 Check(rejected>0,"translucent reconstruction over four opaque current rays was exercised");
201 }
202 std::cout<<"PASS: temporal opacity proof mode "<<(currentProof ? 2 : 1)<<", motion, furthest and transparent contributors\n";
203 }
204
205 for(auto& pixel:pixels)pixel={0,0,0,0};for(auto& distance:distances)distance={0,1e8f};
206 gpu.Context()->UpdateSubresource(source.Get(),0,nullptr,pixels.data(),width*sizeof(XMFLOAT4),0);
207 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
208 frame.milliseconds+=17;HR(history.BeginFrame(frame,32,32,width,height),"clear history frame");render();
209 read(history.Image(),[&](
const uint8_t* row,
unsigned count) {
210 const auto* value=reinterpret_cast<const uint16_t*>(row);
211 for(unsigned i=0;i<count*4;++i)Check(value[i]==0,"disoccluded clear sky has no stale cloud radiance");
212 });
213 {
214
215
216
217 unsigned visibleEdges=0;double absoluteError=0;unsigned compared=0;float largestColorError=0;
218 for(float polarity:{1.f,-1.f})
219 {
220 history.ResetHistory();
221 for(unsigned iteration=0;iteration<16;++iteration)
222 {
223 const float threshold=.55f+.015f*iteration;
224 frame.milliseconds+=17;HR(history.BeginFrame(frame,32,32,width,height),"edge history frame");
225 const auto jitter=history.Jitter();
226 for(unsigned y=0;y<height;++y)for(unsigned x=0;x<width;++x)
227 {
228 const float u=(x+.5f)/width+jitter.x,v=(y+.5f)/height+jitter.y;
229 const bool occupied=polarity*(u+.6f*v-threshold)>0;
230 pixels[y*width+x]=occupied ? XMFLOAT4(.2f,.4f,.6f,1) : XMFLOAT4(0,0,0,0);
231 distances[y*width+x]={occupied ? 100.f : 0.f,1e8f};
232 }
233 gpu.Context()->UpdateSubresource(source.Get(),0,nullptr,pixels.data(),width*sizeof(XMFLOAT4),0);
234 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
235 render();std::vector<float> alpha,hits;
236 read(history.Image(),[&](
const uint8_t* row,
unsigned count) {
237 const auto* values=reinterpret_cast<const uint16_t*>(row);
238 for(unsigned i=0;i<count;++i)
239 {
240 const float a=PackedVector::XMConvertHalfToFloat(values[i*4+3]);alpha.push_back(a);
241 for(unsigned channel=0;channel<3;++channel)
242 {
243 const float c=PackedVector::XMConvertHalfToFloat(values[i*4+channel]);
244 largestColorError=(std::max)(largestColorError,std::abs(c-(channel+1)*.2f*a));
245 }
246 }
247 });
248 read(history.Distance(),[&](
const uint8_t* row,
unsigned count) {
249 const auto* values=reinterpret_cast<const XMFLOAT2*>(row);
250 for(unsigned i=0;i<count;++i){hits.push_back(values[i].x);Check(values[i].y==1e8f,"edge history retains conservative opaque depth");}
251 });
252 for(unsigned y=0;y<16;++y)for(unsigned x=0;x<16;++x)
253 {
254 const unsigned i=y*16+x;const float line=polarity*((x+.5f)/16+.6f*(y+.5f)/16-threshold);
255 Check(std::isfinite(alpha[i]) && alpha[i]>=0 && alpha[i]<=1,"finite bounded edge coverage");
256 if(alpha[i]>.001f){Check(std::abs(hits[i]-100)<.001f,"visible edge retains cloud distance without blending empty sky");++visibleEdges;}
257 if(line<-.2f)Check(alpha[i]==0,"moving edge leaves distant clear sky clean");
258 if(line>.2f)Check(alpha[i]>.99f,"opaque interior survives edge reconstruction");
259 unsigned covered=0;
260 for(unsigned sy=0;sy<8;++sy)for(unsigned sx=0;sx<8;++sx)
261 covered+=polarity*((x+(sx+.5f)/8)/16+.6f*(y+(sy+.5f)/8)/16-threshold)>0;
262 absoluteError+=std::abs(alpha[i]-covered/64.f);++compared;
263 }
264 }
265 }
266 Check(visibleEdges>100,"edge fixture exercised reconstructed cloud coverage");
267 Check(absoluteError/compared<.04,"moving edge coverage stays within supersampled reference tolerance");
268
269
270 std::cout<<"Temporal premultiplied edge maximum error: "<<largestColorError<<'\n';
271 Check(largestColorError<.003f,"edge filtering preserves premultiplied cloud color within half-float history precision");
272 std::cout<<"Temporal diagonal coverage mean absolute error: "<<absoluteError/compared<<"\n";
273 }
274 {
275
276
277
278
279 const auto shadow=[&](float hit,bool uniform) {
280 history.ResetHistory();
281 for(auto& pixel:pixels)pixel={.8f,.8f,.8f,1};
282 if(!uniform)pixels[3*width+3]={.05f,.05f,.05f,1};
283 for(auto& distance:distances)distance={hit,hit+1};
284 gpu.Context()->UpdateSubresource(source.Get(),0,nullptr,pixels.data(),width*sizeof(XMFLOAT4),0);
285 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
286 frame.milliseconds+=17;HR(history.BeginFrame(frame,32,32,width,height),"distance-filter shadow frame");render();
287 XMFLOAT2 result{1,0};unsigned countPixels=0;
288 read(history.Image(),[&](
const uint8_t* row,
unsigned count) {
289 const auto* value=reinterpret_cast<const uint16_t*>(row);
290 for(unsigned x=0;x<count;++x)
291 {
292 const float red=PackedVector::XMConvertHalfToFloat(value[x*4]);
293 result.x=(std::min)(result.x,red);result.y+=red;++countPixels;
294 Check(value[x*4+3]==PackedVector::XMConvertFloatToHalf(1),"radiance filter retains opaque coverage");
295 }
296 });
297 result.y/=countPixels;return result;
298 };
299 const auto nearShadow=shadow(1,false),farShadow=shadow(100,false),flat=shadow(100,true);
300 Check(farShadow.x>nearShadow.x+.1f,"under-resolved shadow has less isolated contrast");
301 Check(std::abs(farShadow.y-nearShadow.y)<.002f,"distance filter does not brighten the cloud field");
302 Check(std::abs(flat.x-.8f)<.001f && std::abs(flat.y-.8f)<.001f,"uniform radiance remains unchanged");
303 std::cout<<"PASS: distance-filter shadow contrast, conserved brightness and opaque coverage\n";
304 }
305 {
306
307
308
309
310 for(float syntheticHit:{1.f,100.f})
311 {
312 double error=0;unsigned compared=0;float largestJump=0;
313 std::vector<float> previousResidual;
314 history.ResetHistory();
315 for(unsigned iteration=0;iteration<24;++iteration)
316 {
317 const float threshold=.55f+.004f*iteration;
318 frame.milliseconds+=17;HR(history.BeginFrame(frame,32,32,width,height),"internal edge frame");
319 const auto jitter=history.Jitter();
320 for(unsigned y=0;y<height;++y)for(unsigned x=0;x<width;++x)
321 {
322 const float u=(x+.5f)/width+jitter.x,v=(y+.5f)/height+jitter.y;
323 const bool bright=u+.6f*v>threshold;
324 pixels[y*width+x]=bright ? XMFLOAT4(.8f,.8f,.8f,1) : XMFLOAT4(.2f,.2f,.2f,1);
325 distances[y*width+x]={syntheticHit,syntheticHit*(bright ? 1.01f : 1.10f)};
326 }
327 gpu.Context()->UpdateSubresource(source.Get(),0,nullptr,pixels.data(),width*sizeof(XMFLOAT4),0);
328 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
329 render();std::vector<float> red;
330 read(history.Image(),[&](
const uint8_t* row,
unsigned count) {
331 const auto* value=reinterpret_cast<const uint16_t*>(row);
332 for(unsigned x=0;x<count;++x)
333 {
334 const float r=PackedVector::XMConvertHalfToFloat(value[x*4]);red.push_back(r);
335 Check(std::isfinite(r) && r>=.199f && r<=.801f,"internal filter preserves radiance range");
336 Check(value[x*4+3]==PackedVector::XMConvertFloatToHalf(1),"internal edges remain opaque");
337 }
338 });
339 read(history.Distance(),[&](
const uint8_t* row,
unsigned count) {
340 const auto* value=reinterpret_cast<const XMFLOAT2*>(row);
341 for(unsigned x=0;x<count;++x)
342 {
343 Check(std::abs(value[x].x-syntheticHit)<.001f,"opaque internal edge retains valid cloud distance");
344 Check(value[x].y==syntheticHit*1.01f || value[x].y==syntheticHit*1.10f,"internal reconstruction never averages visibility bounds");
345 }
346 });
347 std::vector<float> residual;
348 for(unsigned y=0;y<16;++y)for(unsigned x=0;x<16;++x)
349 {
350 unsigned bright=0;
351 for(unsigned sy=0;sy<8;++sy)for(unsigned sx=0;sx<8;++sx)
352 bright+=(x+(sx+.5f)/8)/16+.6f*(y+(sy+.5f)/8)/16>threshold;
353 const float reference=.2f+.6f*bright/64.f;
354 residual.push_back(red[y*16+x]-reference);
355 error+=std::abs(residual.back());++compared;
356 if(!previousResidual.empty())largestJump=(std::max)(largestJump,std::abs(residual.back()-previousResidual[y*16+x]));
357 }
358 previousResidual=std::move(residual);
359 }
360 Check(error/compared<.04,"moving opaque cloud boundary stays near area reference");
361 Check(largestJump<.35f,"moving opaque cloud boundary avoids a large single-frame brightness jump");
362 std::cout<<"Opaque diagonal distance="<<syntheticHit<<" mean absolute error: "<<error/compared<<", maximum residual jump: "<<largestJump<<'\n';
363 }
364 }
365 {
366
367
368
369 history.ResetHistory();
370 for(unsigned y=0;y<height;++y)for(unsigned x=0;x<width;++x)
371 {
372 const float shade=(x+y)%2 ? .8f : .2f;
373 pixels[y*width+x]={shade,shade,shade,1};distances[y*width+x]={1,2};
374 }
375 distances[3*width+3].y=10;
376 gpu.Context()->UpdateSubresource(source.Get(),0,nullptr,pixels.data(),width*sizeof(XMFLOAT4),0);
377 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
378 frame.milliseconds+=17;HR(history.BeginFrame(frame,32,32,width,height),"internal edge visibility footprint");
379 const auto jitter=history.Jitter();render();unsigned rowIndex=0,farContributors=0;
380 read(history.Distance(),[&](
const uint8_t* row,
unsigned count) {
381 const auto* value=reinterpret_cast<const XMFLOAT2*>(row);
382 for(unsigned x=0;x<count;++x)
383 {
384 const int cx=int(std::floor(((x+.5f)/count-jitter.x)*width));
385 const int cy=int(std::floor(((rowIndex+.5f)/16-jitter.y)*height));
386 const bool contains=std::abs(cx-3)<=1 && std::abs(cy-3)<=1;
387 Check(value[x].y==(contains ? 10.f : 2.f),"internal filter proves opacity for every wider radiance contributor");
388 farContributors+=contains;
389 }
390 ++rowIndex;
391 });
392 Check(farContributors==36,"internal edge fixture exercises the expanded visibility footprint");
393 }
394
395
396
397 for(unsigned y=0;y<height;++y)for(unsigned x=0;x<width;++x)
398 pixels[y*width+x]={float(x%3)*.3f,float(y%4)*.2f,float((x+y)%2)*.8f,1};
399 for(auto& distance:distances)distance={100,101};
400 gpu.Context()->UpdateSubresource(source.Get(),0,nullptr,pixels.data(),width*sizeof(XMFLOAT4),0);
401 gpu.Context()->UpdateSubresource(sourceDepth.Get(),0,nullptr,distances.data(),width*sizeof(XMFLOAT2),0);
402 const auto translatedHistory=[&](float offset) {
403 history.ResetHistory();auto translated=frame;
404 XMStoreFloat4x4(&translated.view,XMMatrixTranslation(offset,offset*.4f,0));
405 XMStoreFloat4x4(&translated.inverseView,XMMatrixTranslation(-offset,-offset*.4f,0));
406 for(unsigned i=0;i<8;++i)
407 {
408 translated.milliseconds+=17;
409 HR(history.BeginFrame(translated,32,32,width,height),"translated camera history");render();
410 }
411 std::vector<uint16_t> result;
412 read(history.Image(),[&](
const uint8_t* row,
unsigned count) {
413 const auto* value=reinterpret_cast<const uint16_t*>(row);result.insert(result.end(),value,value+count*4);
414 });
415 return result;
416 };
417 Check(translatedHistory(0)==translatedHistory(10),"external-camera translation does not smear history");
418 history.ResetHistory();Check(!history.HasHistory() && !history.Image(),"simulator/reposition reset removes old output");
419 next=frame;next.transientLight=true;
420 HR(history.BeginFrame(next,32,32,width,height),"flash can render without retained history");render();
421 HR(history.BeginFrame(frame,32,32,width,height),"flash end reinitializes history");
422 Check(!history.HasHistory(),"flash history cannot persist after extinction");
423 HR(history.BeginFrame(frame,32,32,width,height),"rearm after reset");render();
424 HR(history.BeginFrame(frame,40,24,width,height),"resize history");Check(!history.HasHistory(),"resize invalidates history");render();
425 next=frame;next.projection._11=0;
426 Check(history.BeginFrame(next,32,32,width,height)==E_INVALIDARG && !history.HasHistory(),"invalid projection clears history");
427 history.ReleaseTargets();Check(!history.HasHistory() && !history.Image(),"device-size release clears history");
428 history.Reset();gpu.Context()->ClearState();DebugMessages(gpu);
429 std::cout<<"PASS: temporal orbit/pan/wind wrap, "<<resets<<" discontinuity cases, GPU clear disocclusion, conservative depth, reset/rearm/resize\n";
430}