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

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

1#include "../Rendering/CloudOrbitResolution11.h"
2
3// A shadowed cloud column with no emission cannot acquire solar radiance
4// solely from the atmospheric haze overlay. Exercise real GPU output with
5// nonzero haze, rather than reproducing the shader's lighting expression.
6static void TestOrganicNightExterior(Device11& gpu,CloudRenderer11& renderer)
7{
8 Scene scene(gpu.Device(),4);Pipeline pipeline(gpu.Device(),4);
9 XMFLOAT4X4 view,projection;
10 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,-1,0,0),XMVectorSet(0,0,1,0)));
11 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(.02f,float(Width)/Height,.001f,10000));
12 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height),0,1};
13 for(uint8_t convection:{uint8_t(0),uint8_t(127),uint8_t(255)})
14 {
15 auto map=std::make_shared<CloudWeather::Map>();map->mips.push_back({32,16,std::vector<uint8_t>(32*16,convection)});
16 CloudWeather::BuildMips(*map);renderer.UpdateWeather(map,60);
17 HR(renderer.PrepareResources(gpu.Context()),"night exterior weather upload");renderer.UpdateWeather(map,60);
18 for(float altitude:{117.f,1000.f,3000.f})for(bool nvg:{false,true})
19 {
20 CloudVolume::Parameters cloud;cloud.organic=true;cloud.weather=renderer.WeatherFrame();
21 const XMFLOAT4 gain=nvg ? XMFLOAT4(18.193232f,23.544182f,25.684563f,1) : XMFLOAT4(1,1,1,0);
22 for(bool glow:{false,true})
23 {
24 renderer.ResetCloudHistory();scene.Clear(gpu.Context());
25 HR(renderer.Render(gpu.Context(),scene.target.Get(),scene.depth,viewport,view,projection,
26 {0,cloud.radius+altitude,0},cloud,{.9797959f,.2f,0},
27 {0,0,0,1},{0,0,0,1},glow ? XMFLOAT4(.5f,.5f,.5f,1) : XMFLOAT4(0,0,0,1),
28 {},{.4f,.45f,.5f,57},gain),"shadowed orbital haze");
29 const auto pixels=pipeline.Pixels(gpu,scene,4);float maximum=0;
30 for(const auto& pixel:pixels)for(unsigned c=0;c<3;++c)
31 {
32 Check(std::isfinite(pixel.color[c]),"finite orbital night radiance");
33 maximum=(std::max)(maximum,pixel.color[c]);
34 }
35 if(!glow)Check(maximum==0,"unlit orbital haze must not invent light or terrain relief");
36 else if(nvg)Check(maximum>0,"real airglow remains visible through NVG");
37 }
38 }
39 }
40 DebugMessages(gpu);
41 std::cout<<"PASS: orbital night haze and NVG emission at 117/1000/3000 km\n";
42}
43
44// Check actual rendered colors across the upper lighting blend and the
45// Flight/Top selection boundary. This catches an altitude pop even when both
46// shader sets compile and their resolution/state transitions are correct.
47static void TestOrganicLightingHandoff(Device11& gpu,CloudRenderer11& renderer)
48{
49 Scene scene(gpu.Device(),4);Pipeline pipeline(gpu.Device(),4);
50 XMFLOAT4X4 view,projection;
51 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,-.5f,-1,0),XMVectorSet(0,1,0,0)));
52 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1,float(Width)/Height,.001f,10000));
53 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height),0,1};
54 for(uint8_t convection:{uint8_t(0),uint8_t(127),uint8_t(255)})
55 {
56 auto map=std::make_shared<CloudWeather::Map>();map->mips.push_back({32,16,std::vector<uint8_t>(32*16,convection)});
57 CloudWeather::BuildMips(*map);renderer.UpdateWeather(map,60);
58 HR(renderer.PrepareResources(gpu.Context()),"handoff weather upload");renderer.UpdateWeather(map,60);
59 for(unsigned lighting=0;lighting<3;++lighting)for(float seam:{9.25f,9.5f,22.65f,22.85f,37.f,52.f})
60 {
61 CloudVolume::Parameters cloud;cloud.organic=true;cloud.weather=renderer.WeatherFrame();
62 std::vector<Sample> before;
63 for(float offset:{-.001f,.001f,-.001f})
64 {
65 renderer.ResetCloudHistory();scene.Clear(gpu.Context());
66 // Exercise the descending refinement boundary with its state
67 // armed, rather than resetting both sides to the lower path.
68 if(seam==9.25f)
69 {
70 HR(renderer.Render(gpu.Context(),scene.target.Get(),scene.depth,viewport,view,projection,
71 {0,cloud.radius+10.5f,0},cloud,{0,-1,0},{1,1,1,1},{.02f,.02f,.02f,1}),
72 "arm descending deck search");
73 scene.Clear(gpu.Context());
74 }
75 HR(renderer.Render(gpu.Context(),scene.target.Get(),scene.depth,viewport,view,projection,
76 {0,cloud.radius+seam+offset,0},cloud,lighting ? XMFLOAT3(0,1,0) : XMFLOAT3(.6f,-.8f,0),
77 {1,1,1,1},{.02f,.02f,.02f,1},{.125f,.375f,.25f,1},{},{},
78 // Retained live replay gain, not a new optical coefficient.
79 lighting==2 ? XMFLOAT4(18.193232f,23.544182f,25.684563f,1) : XMFLOAT4(1,1,1,0)),"organic lighting handoff");
80 const auto now=pipeline.Pixels(gpu,scene,4);
81 if(!before.empty())
82 {
83 double difference=0,brightness=0;
84 for(size_t i=0;i<now.size();++i)for(unsigned c=0;c<3;++c)
85 {
86 Check(std::isfinite(now[i].color[c]),"finite upper lighting color");
87 difference+=std::abs(now[i].color[c]-before[i].color[c]);brightness+=now[i].color[c];
88 }
89 const double mean=difference/(now.size()*3);
90 std::cout<<"Lighting handoff weather="<<unsigned(convection)<<" mode="<<lighting<<" altitude="<<seam
91 <<" direction="<<(offset>0 ? "ascent" : "descent")<<" mean delta="<<mean<<'\n';
92 Check(mean<.02,"upper lighting transition must not pop across two meters");
93 if(!lighting)Check(brightness/(now.size()*3)>.05,"daylight handoff fixture must show clouds");
94 }
95 before=now;
96 }
97 }
98 }
99 DebugMessages(gpu);
100 std::cout<<"PASS: deck-search and upper lighting handoffs in daylight/night/NVG and quiet/moderate/strong convection\n";
101 TestOrganicNightExterior(gpu,renderer);
102}
103
104// Exercise the real renderer's orbital quality handoff in both directions.
105static void TestOrganicTransitions(Device11& gpu,CloudRenderer11& renderer,float diagnosticAltitude=-1)
106{
107 Scene scene(gpu.Device(),4);
108 XMFLOAT4X4 view,projection;
109 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,-1,-1,0),XMVectorSet(0,1,0,0)));
110 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1,float(Width)/Height,.001f,10000));
111 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height),0,1};
112 CloudVolume::Parameters cloud;cloud.weather=renderer.WeatherFrame();
113 constexpr float flightScale=.5f,topScale=.25f,orbitScale=.5f;
114 Check(CloudRefinedFlightResolution11(1672,941)==.25f,"reference-sized refined flight keeps its quarter grid");
115 const float deckScale=CloudRefinedFlightResolution11(3440,1351);
116 const auto deckRays=unsigned(3440*deckScale)*unsigned(1351*deckScale);
117 Check(deckRays>103000 && deckRays<=105000,"ultrawide deck search has bounded ray work");
118 Check(CloudRefinedFlightResolution11(7680,4320)==.125f,"refined flight retains an eighth-grid floor");
119 Check(CloudRefinedFlightResolution11(0,0)==.25f
120 && CloudRefinedFlightResolution11(std::numeric_limits<float>::quiet_NaN(),1351)==.25f,
121 "invalid deck dimensions use the safe original grid");
122 Check(CloudOrbitResolution11(1672,941)==.5f,"reference-size orbit keeps its detail");
123 const auto rays=[](float width,float height) {
124 const float scale=CloudOrbitResolution11(width,height);
125 return double(unsigned(width*scale))*unsigned(height*scale);
126 };
127 const double wideRays=rays(3440,1331),matchedRays=rays(3344,1882);
128 Check(wideRays>285000 && wideRays<=290000 && matchedRays>390000 && matchedRays<=395000,
129 "ultrawide orbit bounds ray work while larger targets retain the quarter-scale floor");
130 Check(CloudOrbitResolution11(3440,1351)==.25f,"ultrawide continuous-sheet rendering fits the supported quarter grid");
131 const float distantScale=CloudOrbitResolution11(3440,1351,true);
132 const double distantRays=double(unsigned(3440*distantScale))*unsigned(1351*distantScale);
133 Check(distantRays>355000 && distantRays<=360000,"distant orbit has bounded ray work");
134 const float globeScale=CloudOrbitResolution11(3440,1351,true,true);
135 const double globeRays=double(unsigned(3440*globeScale))*unsigned(1351*globeScale);
136 Check(globeRays>675000 && globeRays<=680000,"globe orbit has bounded denser sampling");
137 Check(!CloudGlobeOrbit11(2000,false) && CloudGlobeOrbit11(2000.1f,false)
138 && CloudGlobeOrbit11(1600.1f,true) && !CloudGlobeOrbit11(1600,true),"globe sampling ascent and descent hysteresis");
139 Check(!CloudGlobeOrbit11(std::numeric_limits<float>::quiet_NaN(),true),"invalid altitude cannot retain globe sampling");
140 Check(!CloudDistantOrbit11(117,false) && !CloudDistantOrbit11(250,false)
141 && CloudDistantOrbit11(250.1f,false),"distant sampling enters only above 250 km");
142 Check(CloudDistantOrbit11(249,true) && CloudDistantOrbit11(200.1f,true)
143 && !CloudDistantOrbit11(200,true),"distant sampling holds until descent reaches 200 km");
144 Check(!CloudDistantOrbit11(std::numeric_limits<float>::quiet_NaN(),true),"invalid altitude cannot retain distant sampling");
145 Check(CloudOrbitResolution11(7680,4320)==.25f,"large viewport respects supported quarter-scale floor");
146 Check(renderer.OrganicReady(),"complete matching organic renderer is available");
147 Check(CloudVolume::SelectOrganicMode(cloud,renderer.OrganicReady(),false),"real flight activates organic mode");
148 const auto render=[&](float altitude,float expected) {
149 std::cout<<"Organic transition: altitude="<<altitude<<" km organic="<<cloud.organic<<" base="<<cloud.base<<" km\n";
150 const auto frameStarted=GetTickCount64();
151 scene.Clear(gpu.Context());
152 HR(renderer.Render(gpu.Context(),scene.target.Get(),scene.depth,viewport,view,projection,
153 {0,cloud.radius+altitude,0},cloud,{0,-1,0},{1,1,1,1},{.3f,.4f,.5f,1}),"organic quality transition");
154 Check(renderer.Pass().ResolutionScale()==expected,"organic orbit/re-entry quality hysteresis");
155 const auto path=(!cloud.organic || CloudOrganicShape::Weight(cloud)<=0) ? CloudPass11::OrganicPath::Legacy : !CloudBaseWeather::Active(cloud.localBase) && altitude>cloud.top+CloudVolume::MaxTopRiseKm+.65f
156 ? CloudPass11::OrganicPath::Top : CloudPass11::OrganicPath::Flight;
157 Check(renderer.Pass().SelectedOrganicPath()==path,"matching specialized field/march/composite selection");
158 Check(renderer.Parameters().ZeroOrUnset("riseCloudRefinedSearch")
159 == !(path==CloudPass11::OrganicPath::Flight && expected==topScale),
160 "refined search and matching ray budget are selected together");
161 // Render only submits work. Wait before calling a transition successful
162 // so a deferred GPU failure is attributed to the draw that caused it.
163 D3D11_QUERY_DESC description{D3D11_QUERY_EVENT,0};ComPtr<ID3D11Query> completion;
164 HR(gpu.Device()->CreateQuery(&description,&completion),"transition completion query");
165 gpu.Context()->End(completion.Get());gpu.Context()->Flush();
166 const auto started=GetTickCount64();
167 HRESULT completed=S_FALSE;
168 while((completed=gpu.Context()->GetData(completion.Get(),nullptr,0,D3D11_ASYNC_GETDATA_DONOTFLUSH))==S_FALSE)
169 {
170 HR(gpu.RemovalReason(),"transition device removal");
171 Check(GetTickCount64()-started<60000,"transition GPU completion timed out");
172 Sleep(1);
173 }
174 if(FAILED(completed))std::cerr<<"Transition device removal reason: 0x"<<std::hex<<unsigned(gpu.RemovalReason())<<std::dec<<'\n';
175 HR(completed,"transition GPU completion");DebugMessages(gpu);
176 std::cout<<"Transition draw and completion: "<<GetTickCount64()-frameStarted<<" ms wall time\n";
177 };
178 renderer.ResetCloudHistory();
179 if(diagnosticAltitude>=0)
180 {
181 render(diagnosticAltitude,diagnosticAltitude>37 ? orbitScale : diagnosticAltitude>9.5f ? topScale : flightScale);
182 renderer.ReleaseSizeDependent();DebugMessages(gpu);
183 std::cout<<"PASS: single organic diagnostic draw completed on the GPU\n";
184 return;
185 }
186 for(const auto test:std::array<XMFLOAT2,23>{{{.1f,flightScale},{9,flightScale},{9.49f,flightScale},
187 {9.51f,topScale},{9.4f,topScale},{9.251f,topScale},{9.249f,flightScale},{9.4f,flightScale},
188 {9.51f,topScale},{10.3f,topScale},{10.64f,topScale},{10.66f,topScale},{18,topScale},{18.1f,topScale},
189 {17.8f,topScale},{17.49f,topScale},{18.1f,topScale},{22.64f,topScale},
190 {22.66f,topScale},{22.64f,topScale},{17.49f,topScale},{10.64f,topScale},{9,flightScale}}})render(test.x,test.y);
191 render(10.5f,topScale);renderer.ResetCloudHistory();render(9.4f,flightScale);
192 for(const auto test:std::array<XMFLOAT2,13>{{{18,topScale},{31,topScale},{36,topScale},{38,orbitScale},{500,orbitScale},
193 {1000,orbitScale},{3000,orbitScale},{1000,orbitScale},{500,orbitScale},
194 {117,orbitScale},{34,orbitScale},{31,topScale},{36,topScale}}})render(test.x,test.y);
195 render(38,orbitScale);
196 renderer.ResetCloudHistory();render(35,topScale); // simulator/reposition cannot restore an old orbit state
197 render(117,orbitScale);
198 Check(CloudVolume::SelectOrganicMode(cloud,renderer.OrganicReady(),true),"simulator entry changes CPU cloud mode");
199 renderer.ResetCloudHistory();render(117,flightScale);
200 // Simulator entry directly from upper flight must also restore the old
201 // half-grid, even though neither the Top nor Orbit path was active.
202 cloud.organic=true;render(10.5f,topScale);cloud.organic=false;render(10.5f,flightScale);
203 Check(!CloudVolume::SelectOrganicMode(cloud,renderer.OrganicReady(),true),"simulator remains on baseline field");
204 Check(CloudVolume::SelectOrganicMode(cloud,renderer.OrganicReady(),false),"simulator exit rearms real cloud field");
205 renderer.ResetCloudHistory();render(117,orbitScale);
206 Check(CloudVolume::SelectOrganicMode(cloud,false,false),"missing native program set disables matching CPU field");
207 renderer.ResetCloudHistory();render(117,flightScale);
208 Check(CloudVolume::SelectOrganicMode(cloud,renderer.OrganicReady(),false),"restored native set rearms cloud field");
209 renderer.ResetCloudHistory();render(117,orbitScale);
210 // The specialized top compositor assumes the observer-local base frame
211 // is inactive. A retained active frame (for example during a relocation)
212 // must use the complete field until its observer weight reaches zero.
213 auto localBase=std::make_shared<CloudBaseWeather::Grid>();
214 localBase->cube=0;localBase->u=CloudBaseWeather::CenterU[0];localBase->v=CloudBaseWeather::CenterV[0];
215 for(auto& cell:localBase->cells)cell={cloud.base,.5f,1,0};localBase->Bounds();
216 cloud.localBase={localBase,1};render(117,flightScale);
217 render(10.5f,flightScale);
218 cloud.localBase.weight=0;render(10.5f,topScale);
219 render(117,orbitScale);
220 cloud.localBase={};
221 cloud.base=9.5f;render(117,flightScale); // administrative thin/high layer retains full flight field
222 renderer.ReleaseSizeDependent();DebugMessages(gpu);
223 std::cout<<"PASS: organic ascent/coast/orbit/re-entry hysteresis, reset, disable/re-enable and high-ceiling fallback\n";
224}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
bool Active(const Frame &frame)
constexpr int CenterV[]
constexpr int CenterU[]
float Weight(const Parameters &params)
constexpr float MaxTopRiseKm
Definition CloudVolume.h:23
bool SelectOrganicMode(Parameters &params, bool matchingRendererReady, bool simulator)
Definition CloudVolume.h:42
void BuildMips(Map &map)
float CloudOrbitResolution11(float width, float height, bool distant=false, bool globe=false)
bool CloudGlobeOrbit11(float altitudeKm, bool wasGlobe)
bool CloudDistantOrbit11(float altitudeKm, bool wasDistant)
float CloudRefinedFlightResolution11(float width, float height)
path
Definition erin.py:153
CloudWeather::Frame weather
Definition CloudVolume.h:35
CloudBaseWeather::Frame localBase
Definition CloudVolume.h:36