1
2
3#include "../Rendering/CloudRenderer11.h"
4#include "../Rendering/FrameProfiler11.h"
5#include "../Viewscreen/CloudNightVision.h"
6#include "../Rendering/ExteriorRain11.h"
7#include "../Rendering/ProceduralLightning11.h"
8#include "../Rendering/WindshieldRain11.h"
9#include <d3dcompiler.h>
10#include <d3d11sdklayers.h>
11#include <cmath>
12#include <cstring>
13#include <fstream>
14#include <iostream>
15#include <stdexcept>
16#include "CloudTestDiagnostics.h"
19using Microsoft::WRL::ComPtr;
20namespace
21{
22#ifdef RISE_CLOUD_ULTRAWIDE_FOREGROUND
23 constexpr UINT Width=3440,Height=1351;
24#elif defined(RISE_CLOUD_FULL_RESOLUTION_FOREGROUND)
25
26
27 constexpr UINT Width=1600,Height=1200;
28#else
29 constexpr UINT Width=160,Height=120;
30#endif
31 unsigned checks=0;
32 void Check(bool value,const char* message) {++checks;if(!value)throw std::runtime_error(message);}
33 void HR(
HRESULT hr,
const char* message) {
if(FAILED(hr))
throw std::runtime_error(std::string(message)+
": "+std::to_string(hr));}
34 constexpr char source[]=R"(
35#if SAMPLES == 1
36Texture2D<float4> image : register(t0);
37Texture2D<float> depth : register(t1);
38#else
39Texture2DMS<float4,SAMPLES> image : register(t0);
40Texture2DMS<float,SAMPLES> depth : register(t1);
41#endif
42struct Sample {float4 color;float depth;float3 padding;};
43RWStructuredBuffer<Sample> result : register(u0);
44[numthreads(8,8,1)] void Read(uint3 id:SV_DispatchThreadID)
45{
46 if(id.x>=FIXTURE_WIDTH || id.y>=FIXTURE_HEIGHT)return;
47 Sample value=(Sample)0;
48#if SAMPLES == 1
49 value.color=image.Load(int3(id.xy,0));value.depth=depth.Load(int3(id.xy,0));
50#else
51 value.color=image.Load(id.xy,id.z);value.depth=depth.Load(id.xy,id.z);
52#endif
53 result[(id.y*FIXTURE_WIDTH+id.x)*SAMPLES+id.z]=value;
54}
55float4 Fullscreen(uint vertex:SV_VertexID):SV_Position
56{return float4(vertex==2 ? 3 : -1,vertex==1 ? 3 : -1,.5,1);}
57float4 Silhouette(uint vertex:SV_VertexID):SV_Position
58{return float4(vertex==2 ? .6 : -1,vertex==1 ? -2 : .6,0,1);}
59float4 NearHull(uint vertex:SV_VertexID):SV_Position
60{float4 p=Fullscreen(vertex);p.z=.96+.01*p.x;return p;}
61float4 CityWall(uint vertex:SV_VertexID):SV_Position
62{float4 p=Fullscreen(vertex);p.z=.999+.0002*p.x;return p;}
63float4 Blue():SV_Target {return float4(.1,.2,.8,1);}
64float4 Black():SV_Target {return float4(0,0,0,1);}
65float4 NoCloud():SV_Target {discard;return 0;}
66)";
67 ComPtr<ID3DBlob> Compile(const char* entry,const char* profile,UINT samples)
68 {
69 const auto count=std::to_string(samples),width=std::to_string(Width),height=std::to_string(Height);
70 const D3D_SHADER_MACRO definitions[]={{"SAMPLES",count.c_str()},
71 {"FIXTURE_WIDTH",width.c_str()},{"FIXTURE_HEIGHT",height.c_str()},{nullptr,nullptr}};
72 ComPtr<ID3DBlob> code,errors;
73 const auto hr=D3DCompile(source,strlen(source),"CloudScene11.inline.hlsl",definitions,nullptr,entry,profile,
74 D3DCOMPILE_ENABLE_STRICTNESS|D3DCOMPILE_WARNINGS_ARE_ERRORS|D3DCOMPILE_OPTIMIZATION_LEVEL3,0,&code,&errors);
75 if(errors)std::cerr<<static_cast<const char*>(errors->GetBufferPointer());HR(hr,"compile scene fixture");return code;
76 }
77 struct Sample {
float color[4],depth,padding[3];};
78 std::filesystem::path ReferenceShaders(const std::filesystem::path& sourceDirectory)
79 {
80
81
82
83
84 const auto directory=std::filesystem::path("outputs")/("cloud-reference-"+std::to_string(GetCurrentProcessId()));
85 std::filesystem::create_directories(directory);
86 for(const auto& file:std::filesystem::directory_iterator(sourceDirectory))
87 if(file.is_regular_file() && file.path().extension()==".cso")
88 std::filesystem::copy_file(file.path(),directory/file.path().filename(),std::filesystem::copy_options::overwrite_existing);
89 auto discard=Compile("NoCloud","ps_5_0",1);
90 std::filesystem::copy_file(sourceDirectory/"CloudVolume-composite-1.cso",directory/"CloudVolume-compositePixel-1.cso",
91 std::filesystem::copy_options::overwrite_existing);
92 std::filesystem::copy_file(sourceDirectory/"CloudVolume-composite-1.cso",directory/"CloudVolume-compositeFogPixel-1.cso",
93 std::filesystem::copy_options::overwrite_existing);
94 for(unsigned samples:{2u,4u,8u})
95 {
96 const auto suffix=std::to_string(samples)+".cso";
97 std::filesystem::copy_file(sourceDirectory/("CloudVolume-composite-"+suffix),directory/("CloudVolume-compositeEdge-"+suffix),
98 std::filesystem::copy_options::overwrite_existing);
99 std::ofstream pixel(directory/("CloudVolume-compositePixel-"+suffix),std::ios::binary);
100 pixel.write(static_cast<const char*>(discard->GetBufferPointer()),discard->GetBufferSize());
101 Check(bool(pixel),"write discard reference shader");
102 std::filesystem::copy_file(sourceDirectory/("CloudVolume-composite-"+suffix),directory/("CloudVolume-compositeFogEdge-"+suffix),
103 std::filesystem::copy_options::overwrite_existing);
104 std::ofstream fogPixel(directory/("CloudVolume-compositeFogPixel-"+suffix),std::ios::binary);
105 fogPixel.write(static_cast<const char*>(discard->GetBufferPointer()),discard->GetBufferSize());
106 Check(bool(fogPixel),"write fog discard reference shader");
107 }
108 return directory;
109 }
110 struct Scene
111 {
112 ComPtr<ID3D11Texture2D> color;
113 ComPtr<ID3D11RenderTargetView>
target;
114 ComPtr<ID3D11ShaderResourceView> view;
115 SceneDepth11 depth;
116 Scene(ID3D11Device* device,UINT samples,UINT width=Width,UINT height=Height,DXGI_FORMAT format=DXGI_FORMAT_R8G8B8A8_UNORM)
117 {
118 D3D11_TEXTURE2D_DESC desc{};desc.Width=width;desc.Height=height;desc.ArraySize=desc.MipLevels=1;
119 desc.Format=format;desc.SampleDesc={samples,0};desc.BindFlags=D3D11_BIND_RENDER_TARGET|D3D11_BIND_SHADER_RESOURCE;
120 HR(device->CreateTexture2D(&desc,nullptr,&color),"scene color");HR(device->CreateRenderTargetView(color.Get(),nullptr,&target),"scene RTV");
121 HR(device->CreateShaderResourceView(color.Get(),
nullptr,&view),
"scene color SRV");HR(depth.
Create(device,width,height,desc.SampleDesc),
"scene depth");
122 }
123 void Clear(ID3D11DeviceContext* context)
124 {
125 const float black[]={0,0,0,1};context->ClearRenderTargetView(
target.Get(),black);
126 context->ClearDepthStencilView(depth.
WriteView(),D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,1,0);
127 }
128 };
129 struct Pipeline
130 {
131 ComPtr<ID3D11VertexShader> full,silhouette,nearHull,cityWall;
132 ComPtr<ID3D11PixelShader> blue,black;
133 ComPtr<ID3D11ComputeShader>
read;
134 ComPtr<ID3D11RasterizerState> raster;
135 ComPtr<ID3D11DepthStencilState> stencil,foreground;
136 Pipeline(ID3D11Device* device,UINT samples)
137 {
138 auto code=Compile("Fullscreen","vs_5_0",samples);HR(device->CreateVertexShader(code->GetBufferPointer(),code->GetBufferSize(),nullptr,&full),"full VS");
139 code=Compile("Silhouette","vs_5_0",samples);HR(device->CreateVertexShader(code->GetBufferPointer(),code->GetBufferSize(),nullptr,&silhouette),"silhouette VS");
140 code=Compile("NearHull","vs_5_0",samples);HR(device->CreateVertexShader(code->GetBufferPointer(),code->GetBufferSize(),nullptr,&nearHull),"near hull VS");
141 code=Compile("CityWall","vs_5_0",samples);HR(device->CreateVertexShader(code->GetBufferPointer(),code->GetBufferSize(),nullptr,&cityWall),"city wall VS");
142 code=Compile("Blue","ps_5_0",samples);HR(device->CreatePixelShader(code->GetBufferPointer(),code->GetBufferSize(),nullptr,&blue),"blue PS");
143 code=Compile("Black","ps_5_0",samples);HR(device->CreatePixelShader(code->GetBufferPointer(),code->GetBufferSize(),nullptr,&black),"black PS");
144 code=Compile("Read","cs_5_0",samples);HR(device->CreateComputeShader(code->GetBufferPointer(),code->GetBufferSize(),nullptr,&read),"sample CS");
145 D3D11_RASTERIZER_DESC rs{};rs.FillMode=D3D11_FILL_SOLID;rs.CullMode=D3D11_CULL_NONE;rs.DepthClipEnable=TRUE;rs.MultisampleEnable=TRUE;
146 HR(device->CreateRasterizerState(&rs,&raster),"scene rasterizer");
147 D3D11_DEPTH_STENCIL_DESC ds{};ds.StencilEnable=TRUE;ds.StencilReadMask=ds.StencilWriteMask=255;ds.DepthFunc=D3D11_COMPARISON_ALWAYS;
148 ds.FrontFace=ds.BackFace={D3D11_STENCIL_OP_KEEP,D3D11_STENCIL_OP_KEEP,D3D11_STENCIL_OP_REPLACE,D3D11_COMPARISON_ALWAYS};
149 HR(device->CreateDepthStencilState(&ds,&stencil),"stencil bands");
150 ds.StencilEnable=FALSE;ds.DepthEnable=TRUE;ds.DepthWriteMask=D3D11_DEPTH_WRITE_MASK_ALL;
151 HR(device->CreateDepthStencilState(&ds,&foreground),"foreground depth");
152 }
153 void Hull(ID3D11DeviceContext* context,Scene& scene,const D3D11_VIEWPORT& viewport,bool city=false)
154 {
155 context->ClearState();
auto*
target=scene.target.Get();
156 context->OMSetRenderTargets(1,&target,scene.depth.WriteView());
157 context->RSSetState(raster.Get());context->RSSetViewports(1,&viewport);
158 context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
159 context->VSSetShader(city ? cityWall.Get() : nearHull.Get(),nullptr,0);context->PSSetShader(blue.Get(),nullptr,0);
160 context->OMSetDepthStencilState(foreground.Get(),0);context->Draw(3,0);
161 context->OMSetRenderTargets(0,nullptr,nullptr);
162 }
163 void Occlude(Device11& gpu,Scene& scene,bool horizon=false)
164 {
165 auto* context=gpu.
Context();
auto*
target=scene.target.Get();context->ClearState();
166 context->OMSetRenderTargets(1,&target,scene.depth.WriteView());context->RSSetState(raster.Get());
167 context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);context->VSSetShader(full.Get(),nullptr,0);context->PSSetShader(black.Get(),nullptr,0);
168
169 for(UINT band=0;band<5;++band)
170 {
171 const D3D11_VIEWPORT viewport{float(band*Width/5),0,float(Width/5),float(Height),0,1};context->RSSetViewports(1,&viewport);
172 context->OMSetDepthStencilState(stencil.Get(),band);context->Draw(3,0);
173 }
174
175
176 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height)*(horizon ? .5f : 1.f),0,1};context->RSSetViewports(1,&viewport);
177 context->OMSetDepthStencilState(foreground.Get(),0);context->VSSetShader(silhouette.Get(),nullptr,0);context->PSSetShader(blue.Get(),nullptr,0);context->Draw(3,0);
178 context->OMSetRenderTargets(0,nullptr,nullptr);
179 }
180 std::vector<Sample>
Pixels(Device11& gpu,Scene& scene,UINT samples)
181 {
183 D3D11_BUFFER_DESC desc{};desc.ByteWidth=bytes;desc.BindFlags=D3D11_BIND_UNORDERED_ACCESS;
184 desc.MiscFlags=D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;desc.StructureByteStride=
sizeof(
Sample);
185 ComPtr<ID3D11Buffer>
output,staging;HR(gpu.
Device()->CreateBuffer(&desc,
nullptr,&output),
"sample result");
186 desc.Usage=D3D11_USAGE_STAGING;desc.BindFlags=desc.MiscFlags=desc.StructureByteStride=0;desc.CPUAccessFlags=D3D11_CPU_ACCESS_READ;
187 HR(gpu.
Device()->CreateBuffer(&desc,
nullptr,&staging),
"sample staging");ComPtr<ID3D11UnorderedAccessView> uav;
188 HR(gpu.
Device()->CreateUnorderedAccessView(
output.Get(),
nullptr,&uav),
"sample UAV");
189 ID3D11ShaderResourceView* views[]={scene.view.Get(),scene.depth.ShaderView()};auto* write=uav.Get();
190 context->CSSetShaderResources(0,2,views);context->CSSetUnorderedAccessViews(0,1,&write,
nullptr);context->CSSetShader(
read.Get(),
nullptr,0);
191 context->Dispatch(Width/8,Height/8,samples);context->ClearState();context->CopyResource(staging.Get(),
output.Get());
192 D3D11_MAPPED_SUBRESOURCE mapped{};
const HRESULT mapResult=context->Map(staging.Get(),0,D3D11_MAP_READ,0,&mapped);
193 if(FAILED(mapResult))std::cerr<<
"Device removal reason: 0x"<<std::hex<<unsigned(gpu.
RemovalReason())<<std::dec<<std::endl;
194 HR(mapResult,"sample map");
195 std::vector<Sample> pixels(Width*Height*samples);memcpy(pixels.data(),mapped.pData,bytes);context->Unmap(staging.Get(),0);return pixels;
196 }
197 };
198 ComPtr<ID3D11Buffer> Buffer(ID3D11Device* device,const void* bytes,UINT size,UINT kind=D3D11_BIND_VERTEX_BUFFER)
199 {
200 D3D11_BUFFER_DESC desc{};desc.ByteWidth=size;desc.Usage=D3D11_USAGE_IMMUTABLE;desc.BindFlags=kind;
201 D3D11_SUBRESOURCE_DATA data{bytes,0,0};ComPtr<ID3D11Buffer> buffer;HR(device->CreateBuffer(&desc,&data,&buffer),"geometry buffer");return buffer;
202 }
203 void Protected(const std::vector<Sample>& before,const std::vector<Sample>& after,const std::vector<Sample>& reference,UINT samples,unsigned minimumChanged=20)
204 {
205 unsigned changed[5]{},edges=0;
206 for(UINT y=0;y<
Height;++y)
for(UINT x=0;x<
Width;++x)
207 {
208 unsigned covered=0;
const UINT band=x/(
Width/5);
209 for(UINT s=0;s<samples;++s)
210 {
211 const size_t i=(y*
Width+x)*samples+s;
const bool front=before[i].depth<1;
212 covered+=front;Check(after[i].depth==before[i].depth,"effect changed original scene depth");
213 const auto& expected=front || band>=3 ? before[i] : reference[i];
214 for(unsigned c=0;c<4;++c)
215 {
216 const bool matches=std::abs(after[i].color[c]-expected.color[c])<=1.01f/255;
217 if(!matches)std::cerr<<"Foreground mismatch: pixel="<<x<<','<<y<<" sample="<<s
218 <<" band="<<band<<" front="<<front<<" channel="<<c
219 <<" expected="<<expected.color[c]<<" actual="<<after[i].color[c]<<std::endl;
220 Check(matches,"foreground/stencil/sample color mismatch");
221 }
222 if(!front && band<3 && std::abs(after[i].color[0]-before[i].color[0])>2.f/255)++changed[band];
223 }
224 if(covered>0 && covered<samples)++edges;
225 }
226 for(unsigned band=0;band<3;++band)
227 {
228 if(changed[band]<=minimumChanged)std::cerr<<"band "<<band<<" changed "<<changed[band]<<" samples\n";
229 Check(changed[band]>minimumChanged,"exterior band was not visibly rendered");
230 }
231 if(samples>1)Check(edges>20,"fixture did not contain partial MSAA edges");
232 }
234 {
235 ComPtr<ID3D11InfoQueue> queue;
if(FAILED(gpu.
Device()->QueryInterface(IID_PPV_ARGS(&queue))))
return;
236 for(UINT64 i=0;i<queue->GetNumStoredMessages();++i)
237 {
238 SIZE_T size=0;queue->GetMessage(i,nullptr,&size);std::vector<char> bytes(size);auto* message=reinterpret_cast<D3D11_MESSAGE*>(bytes.data());
239 HR(queue->GetMessage(i,message,&size),"debug message");if(message->Severity<=D3D11_MESSAGE_SEVERITY_WARNING)throw std::runtime_error(message->pDescription);
240 }
241 queue->ClearStoredMessages();
242 }
243 void TestWindshield(
Device11& gpu,UINT samples,
const std::filesystem::path& shaderDirectory)
244 {
246 Pipeline pipeline(gpu.
Device(),samples);Scene scene(gpu.
Device(),samples);
248 const WindshieldRain11::Vertex glass[]={{-.001f,.001f,0,0,0,-1,0,0},{.001f,.001f,0,0,0,-1,1,0},{-.001f,-.001f,0,0,0,-1,0,1},
249 {.001f,.001f,0,0,0,-1,1,0},{.001f,-.001f,0,0,0,-1,1,1},{-.001f,-.001f,0,0,0,-1,0,1}};
251 XMFLOAT4X4 identity,world,projection;XMStoreFloat4x4(&identity,XMMatrixIdentity());
252 XMStoreFloat4x4(&world,XMMatrixTranslation(0,0,.5f));XMStoreFloat4x4(&projection,XMMatrixScaling(1000,1000,1));
253 for(
unsigned i=0;i<60;++i)rain.
Update(.05f,1,{0,9.8f,0},{0,0,-4},{identity},1,
false);
254 Check(rain.
Wet(),
"windshield fixture has water");
255 scene.Clear(gpu.
Context());pipeline.Occlude(gpu,scene);
const auto before=pipeline.Pixels(gpu,scene,samples);
256 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height),0,1};
257 const auto render=[&]() {
258 gpu.
Context()->RSSetState(pipeline.raster.Get());
259 HR(rain.
Render(gpu.
Context(),scene.target.Get(),scene.depth.ReadView(),viewport,{world},projection,1,
261 };
262 render();const auto after=pipeline.Pixels(gpu,scene,samples);
263 unsigned changed[4]{},worldFrontChanged=0,edges=0;
264 for(UINT y=0;y<
Height;++y)
for(UINT x=0;x<
Width;++x)
265 {
266 const UINT band=x/(
Width/5);
unsigned covered=0;
267 for(UINT s=0;s<samples;++s)
268 {
269 const size_t i=(y*
Width+x)*samples+s;
const bool front=before[i].depth<.5f;covered+=front;
270 Check(after[i].depth==before[i].depth,"windshield altered an original depth sample");
271 const bool protect=band==4 || (band==3 && front);
272 bool different=false;
273 for(unsigned c=0;c<4;++c)
274 {
275 if(protect)Check(after[i].color[c]==before[i].color[c],"windshield changed a protected cockpit/wiper sample");
276 different|=std::abs(after[i].color[c]-before[i].color[c])>2.f/255;
277 }
278 if(!protect && different){++changed[band];if(band<3 && front)++worldFrontChanged;}
279 }
280 if(covered>0 && covered<samples)++edges;
281 }
282 for(unsigned band=0;band<4;++band)Check(changed[band]>20,"wet glass missing from visible stencil band");
283 Check(worldFrontChanged>20,"world projection depth incorrectly occludes cockpit water");
284 if(samples>1)Check(edges>20,"windshield fixture lacks partial MSAA edges");
285
286
287 for(bool resetDevice:{false,true})
288 {
291 scene.Clear(gpu.
Context());pipeline.Occlude(gpu,scene);render();
const auto recreated=pipeline.Pixels(gpu,scene,samples);
292 for(size_t i=0;i<after.size();++i)
293 {
294 Check(recreated[i].depth==after[i].depth,"recreated windshield depth");
295 for(unsigned c=0;c<4;++c)Check(recreated[i].color[c]==after[i].color[c],"recreated windshield image");
296 }
297 }
298 Scene mismatch(gpu.
Device(),samples==1 ? 2 : 1);
299 Check(rain.
Render(gpu.
Context(),scene.target.Get(),mismatch.depth.ReadView(),viewport,{world},projection)==E_INVALIDARG,
"mismatched windshield depth rejected");
301 std::cout<<"PASS: windshield refraction, cockpit/wiper/original "<<samples<<"x samples and resource recreation\n";
302 }
304 {
306 Pipeline pipeline(gpu.
Device(),samples);Scene scene(gpu.
Device(),samples),reference(gpu.
Device(),samples);
307 Check(scene.depth.StencilView()!=nullptr,"test adapter must exercise stencil sampling");
308 XMFLOAT4X4 view,projection;
309 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1.f,float(Width)/Height,.001f,384));
310 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height),0,1};
311 const float altitudes[]={14,14,9,3,9,30,.01f,14,9,10,11,12,13,14,15,22,15,14,.05f,.35f,.05f,.35f,.05f,.35f,0,.025f,.05f,-.1f,-.025f,0,
312 .300293f,.300293f,.300293f,.300293f,.300293f,.300293f,.300293f,.300293f,.300293f,
313 .300293f,.300293f,.300293f,.300293f,.300293f,.300293f,.300293f,.300293f,.300293f};
314 const float slopes[]={-.6f,-.03f,0,.4f,-.1f,-.6f,.5f,-.2f,0,.4f,-.4f,1,-1,0,1,0,-.2f,-.2f,.2f,.2f,0,0,.2f,.2f,0,.2f,-.2f,0,.2f,-.2f,
315 0,0,.2f,-.2f,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
316
317
318 const float fogRanges[]={1.f,1.5f,2.f,.999f,1.001f,1.01f,1.99f,2.01f,42.16f};
319 float largest=0;unsigned differing=0;
320 for(unsigned scenario=0;scenario<std::size(altitudes);++scenario)
321 {
322
323 const float nearPlane=scenario>=36 && scenario<=38 ? .0004f+.0001f*(scenario-36) : .001f;
324 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1.f,float(Width)/Height,nearPlane,384));
327 if(scenario>=18)cloud.
base=scenario%2==0 ? .25f : 0;
328 if(scenario>=24)cloud.
base=scenario<27 ? 0.f : -.25f;
329 if(scenario>=30)cloud.
base=.3f;
330 if(scenario>=16 && scenario<18)
331 {
332
333
334 const unsigned position=scenario==16 ? 43u : 7u;
335 const float longitude=position*1.31f,latitude=float(int(position%7)-3)*.35f;
336 const CloudVolume::Point unit{std::sin(longitude)*std::cos(latitude),std::cos(longitude)*std::cos(latitude),std::sin(latitude)};
339 }
340 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,slopes[scenario],-1,0),XMVectorSet(0,1,0,0)));
341 for(Scene* target:{&scene,&reference})
342 {
344
345
346 if(scenario%2==0)
347 gpu.
Context()->ClearDepthStencilView(
target->depth.WriteView(),D3D11_CLEAR_DEPTH,
348 -projection._33+projection._43/30.f,0);
349 if(scenario>=7)
350 pipeline.Hull(gpu.
Context(),*target,viewport,scenario>=18 && scenario!=34);
351 pipeline.Occlude(gpu,*target);
353 context->OMSetRenderTargets(1,&rtv,
target->depth.WriteView());context->RSSetViewports(1,&viewport);
354
355
356 auto stencilViewport=viewport;stencilViewport.TopLeftX=
Width/8.f+.35f;
357 context->RSSetViewports(1,&stencilViewport);
358 context->OMSetDepthStencilState(pipeline.stencil.Get(),3);
359 context->VSSetShader(pipeline.silhouette.Get(),nullptr,0);context->Draw(3,0);
360 context->OMSetRenderTargets(0,nullptr,nullptr);
361 }
362 if(samples>1 && scenario>=7)
363 {
364 const auto hull=pipeline.Pixels(gpu,scene,samples);unsigned mixed=0;
365 for(size_t pixel=0;pixel<hull.size();pixel+=samples)
366 for(unsigned s=1;s<samples;++s)mixed+=hull[pixel].depth!=hull[pixel+s].depth;
367 Check(mixed>Width*Height/2,"near hull must exercise differing depth samples");
368 }
370 {
371 const bool night=scenario==3 || (scenario>=22 && scenario!=30);
372 std::vector<CloudRenderer11::Headlight> lights;
373 if(scenario==4)lights.push_back({{0,cloud.
radius+altitudes[scenario],0},{0,0,-1},{4,4,4,1},2});
374 if(scenario==32)lights.push_back({{0,eye.
y,0},{0,0,-1},{4,4,4,1},2});
378 {eye.x,eye.y,eye.z},cloud,{0,night ? 1.f : -1.f,0},
379 night && scenario>=22 ? XMFLOAT4(0,0,0,1) : XMFLOAT4(1,1,1,1),{.3f,.4f,.5f,1},
380 {.125f,.375f,.25f,1},scenario>=30 ? XMFLOAT4(.05f,.06f,.07f,scenario>=39 ? fogRanges[scenario-39] : scenario==35 ? .02f : .5f) : scenario>=22 ? XMFLOAT4(.05f,.06f,.07f,8) : XMFLOAT4()),"composite parity draw");
381 };
382 render(baseline,reference);render(
renderer,scene);
383 if(scenario>=16 && scenario<18)
384 {
385 std::cout<<
"Local billow clearance scenario "<<scenario<<
": "<<
renderer.ClearAirRadius()
386 <<
" km, eye "<<eye.
x<<
','<<eye.
y<<
','<<eye.
z<<std::endl;
387 Check(
renderer.ClearAirRadius()>=.125f,
"local billow regression must prove nearby clear air");
388 }
389 const auto old=pipeline.Pixels(gpu,reference,samples),now=pipeline.Pixels(gpu,scene,samples);
390 float scenarioMax=0;double scenarioTotal=0;
391 for(size_t i=0;i<old.size();++i)
392 {
393 Check(old[i].depth==now[i].depth,"composite parity depth changed");
394 for(unsigned c=0;c<4;++c)
395 {
396 const float delta=std::abs(old[i].color[c]-now[i].color[c]);
397 largest=(std::max)(largest,delta);differing+=delta!=0;
398 scenarioMax=(std::max)(scenarioMax,delta);scenarioTotal+=delta;
399
400
401
402
403 if(!inspect)Check(delta<=(scenario==0 ? 10.01f : 1.01f)/255,"composite exceeds filtered color bound");
404 }
405 }
406 if(!inspect)Check(scenarioTotal*255/(old.size()*4)<.1,"filtered opaque composite exceeds 0.1-level mean error");
407 if(inspect)std::cout<<"Comparison "<<samples<<"x scene "<<scenario<<": max "<<scenarioMax*255<<", mean "<<scenarioTotal*255/(old.size()*4)<<" levels"<<std::endl;
408 }
411 DebugMessages(gpu);
412 std::cout<<"PASS: original vs optimized composite "<<samples<<"x, "<<std::size(altitudes)<<" cloud/lighting/depth scenarios, max error "
413 <<largest*255<<" levels, "<<differing<<" differing channels\n";
414 }
416 {
417 Pipeline pipeline(gpu.
Device(),samples);Scene scene(gpu.
Device(),samples);
418 XMFLOAT4X4 view,projection;
419 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,.2f,-1,0),XMVectorSet(0,1,0,0)));
420 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1.f,float(Width)/Height,.001f,384));
421 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height),0,1};
422 float largest=0;
423 for(float ceiling:{0.f,.15f,.6f})for(float seam:{1.f,2.f})for(bool night:{false,true})
424 {
426 std::vector<Sample> before;
427 for(float offset:{-.001f,.001f})
428 {
429 scene.Clear(gpu.
Context());pipeline.Hull(gpu.
Context(),scene,viewport,
true);
430 HR(
renderer.Render(gpu.
Context(),scene.target.Get(),scene.depth,viewport,view,projection,
431 {0,cloud.radius+.300293f,0},cloud,{0,night ? 1.f : -1.f,0},
432 night ? XMFLOAT4(0,0,0,1) : XMFLOAT4(1,1,1,1),{.3f,.4f,.5f,1},
433 {.125f,.375f,.25f,1},{.05f,.06f,.07f,seam+offset}),"fog continuity draw");
434 const auto pixels=pipeline.Pixels(gpu,scene,samples);
435 if(before.empty()){before=pixels;continue;}
436 double total=0;float maximum=0;size_t worstPixel=0;unsigned worstChannel=0;
437 for(size_t i=0;i<pixels.size();++i)
438 {
439 Check(pixels[i].depth==before[i].depth,"visibility adjustment changed scene depth");
440 for(unsigned c=0;c<4;++c)
441 {
442 const float delta=std::abs(pixels[i].color[c]-before[i].color[c]);
443 largest=(std::max)(largest,delta);total+=delta;
444 if(delta>maximum){maximum=delta;worstPixel=i;worstChannel=c;}
445 }
446 }
447 std::cout<<"Fog continuity "<<samples<<"x ceiling "<<ceiling<<" seam "<<seam<<" night "<<night
448 <<": max "<<maximum*255<<" mean "<<total*255/(pixels.size()*4)
449 <<" pixel "<<worstPixel<<" channel "<<worstChannel<<" before "<<before[worstPixel].color[worstChannel]
450 <<" after "<<pixels[worstPixel].color[worstChannel]<<std::endl;
451 Check(maximum<=4.01f/255,"visible pop at former fog specialization boundary");
452 Check(total*255/(pixels.size()*4)<.25,"fog boundary average changed abruptly");
453 }
454 }
455 std::cout<<"PASS: 1/2 km visibility continuity "<<samples<<"x, largest change "<<largest*255<<" levels\n";
456 }
458 {
459
460
461 constexpr UINT width=3440,height=1351;
462 Pipeline pipeline(gpu.
Device(),samples);Scene scene(gpu.
Device(),samples,width,height);
464 XMFLOAT4X4 view,projection;
465 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,-.2f,-1,0),XMVectorSet(0,1,0,0)));
466 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1.f,float(width)/height,.001f,384));
467 const D3D11_VIEWPORT viewport{0,0,float(width),float(height),0,1};
468 ComPtr<ID3D11Query> disjoint,begin,end;
469 D3D11_QUERY_DESC desc{D3D11_QUERY_TIMESTAMP_DISJOINT,0};HR(gpu.
Device()->CreateQuery(&desc,&disjoint),
"benchmark disjoint");
470 desc.Query=D3D11_QUERY_TIMESTAMP;HR(gpu.
Device()->CreateQuery(&desc,&begin),
"benchmark start");HR(gpu.
Device()->CreateQuery(&desc,&end),
"benchmark end");
472 for(unsigned scenario=lowCloud ? 5u : 0u;scenario<(lowCloud ? 13u : 5u);++scenario)
473 {
475 if(scenario>=5)
476 {
477 cloud.
base=scenario%2 ? .25f : 0;
478 eye={0,cloud.
radius+(scenario%2 ? .05f : .35f),0};
479 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,.2f,-1,0),XMVectorSet(0,1,0,0)));
481 }
482 if(scenario>=9)
483 {
484
486 eye={0,cloud.
radius+.30f,0};
487 }
488 if(scenario>=11)
489 {
491 eye={0,cloud.
radius+.300293f,0};
492 }
493 if(scenario==4)
494 {
495 const float longitude=43*1.31f,latitude=-2*.35f;
496 const CloudVolume::Point unit{std::sin(longitude)*std::cos(latitude),std::cos(longitude)*std::cos(latitude),std::sin(latitude)};
498
499
501 }
502 double totals[2]{};unsigned counts[2]{};
503 for(unsigned iteration=0;iteration<16;++iteration)for(unsigned version=0;version<2;++version)
504 {
505 const unsigned variant=version^(iteration&1);
506 context->ClearState();scene.Clear(context);
507 if(scenario==2)context->ClearDepthStencilView(scene.depth.WriteView(),D3D11_CLEAR_DEPTH,-projection._33+projection._43/15.f,0);
508 if(scenario>=3)
509 pipeline.Hull(context,scene,viewport,scenario>=5);
510 if(scenario==1)
511 {
512
513
514 auto*
target=scene.target.Get();context->OMSetRenderTargets(1,&target,scene.depth.WriteView());
515 context->RSSetState(pipeline.raster.Get());
516 const D3D11_VIEWPORT lower{0,float(height)/2,float(width),float(height)/2,.9998f,1};context->RSSetViewports(1,&lower);
517 context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);context->VSSetShader(pipeline.full.Get(),nullptr,0);context->PSSetShader(pipeline.blue.Get(),nullptr,0);
518 context->OMSetDepthStencilState(pipeline.foreground.Get(),0);context->Draw(3,0);
519 context->OMSetDepthStencilState(pipeline.stencil.Get(),3);context->Draw(3,0);
520 }
521 auto& clouds=variant ?
renderer : baseline;
522 context->Begin(disjoint.Get());context->End(begin.Get());
523
524
525 constexpr unsigned batch=4;
526 for(unsigned repeat=0;repeat<batch;++repeat)
527 HR(clouds.
Render(context,scene.target.Get(),scene.depth,viewport,view,projection,
528 {eye.x,eye.y,eye.z},cloud,{0,(scenario>=7 && scenario!=9 && scenario!=11) ? 1.f : -1.f,0},
529 (scenario>=7 && scenario!=9 && scenario!=11) ? XMFLOAT4(0,0,0,1) : XMFLOAT4(1,1,1,1),{.3f,.4f,.5f,1},
530 {.125f,.375f,.25f,1},scenario>=11 ? XMFLOAT4(.05f,.06f,.07f,.5f) : (scenario>=7 && scenario!=9) ? XMFLOAT4(.05f,.06f,.07f,8) : XMFLOAT4()),"benchmark draw");
531 context->End(end.Get());context->End(disjoint.Get());context->Flush();
532 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT timing{};UINT64 first=0,last=0;
533 const auto read=[&](ID3D11Query* query,void* data,UINT bytes)
534 {
535 const ULONGLONG deadline=GetTickCount64()+30000;HRESULT hr;
536 while((hr=context->GetData(query,data,bytes,D3D11_ASYNC_GETDATA_DONOTFLUSH))==S_FALSE)
537 {if(GetTickCount64()>deadline)throw std::runtime_error("benchmark query timeout");Sleep(1);}
538 HR(hr,"benchmark query result");
539 };
540 read(disjoint.Get(),&timing,
sizeof(timing));
read(begin.Get(),&first,
sizeof(first));
read(end.Get(),&last,
sizeof(last));
541 if(iteration>=4 && !timing.Disjoint && timing.Frequency)
542 {totals[variant]+=1000.*double(last-first)/(double(timing.Frequency)*batch);++counts[variant];}
543 }
544 Check(counts[0]>0 && counts[1]>0,"valid benchmark samples");
545 std::cout<<"Cloud total GPU, 3440x1351 "<<samples<<"x MSAA, "<<(scenario==11 ? "day BCL0 with 500m fog at Deois" : scenario==12 ? "night BCL0 with 500m fog at Deois" : scenario==9 ? "day 150m AGL base at Deois elevation" : scenario==10 ? "night 150m AGL base at Deois elevation" : scenario==7 ? "night 250m base" : scenario==8 ? "night zero base" : scenario==5 ? "250m base over sloped city depth" : scenario==6 ? "zero base inside cloud over sloped city depth" : scenario==1 ? "half cockpit" : scenario==2 ? "finite scene depth" : scenario==3 ? "near hull depth" : scenario==4 ? "local clear-top hull (previous bounds fallback)" : "clear sky")
546 <<": baseline "<<totals[0]/counts[0]<<" ms, optimized "<<totals[1]/counts[1]<<" ms\n";
547 }
548 DebugMessages(gpu);
549 }
550 void Test(
Device11& gpu,
CloudRenderer11&
renderer,UINT samples,
const std::filesystem::path& shaderDirectory,
bool organic=
false,
float altitude=30,
bool horizon=
false)
551 {
552 if(!gpu.
SupportsSamples(samples)){std::cout<<
"UNVERIFIED: unsupported "<<samples<<
"x MSAA\n";
return;}
553 Pipeline pipeline(gpu.
Device(),samples);Scene reference(gpu.
Device(),samples),scene(gpu.
Device(),samples);
555 XMFLOAT4X4 view,projection,identity,inverseView;
556 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),XMVectorSet(0,-1,-1,0),XMVectorSet(0,1,0,0)));
557 if(horizon)
558 {
559
560
561
562 const float depression=std::acos((cloud.
radius+cloud.
top)/(cloud.
radius+altitude))+.055f;
563 XMStoreFloat4x4(&view,XMMatrixLookAtRH(XMVectorZero(),
564 XMVectorSet(0,-std::sin(depression),-std::cos(depression),0),XMVectorSet(0,1,0,0)));
565 }
566 XMStoreFloat4x4(&inverseView,XMMatrixInverse(nullptr,XMLoadFloat4x4(&view)));
567 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1.f,float(Width)/Height,.001f,384));XMStoreFloat4x4(&identity,XMMatrixIdentity());
568 const D3D11_VIEWPORT viewport{0,0,float(Width),float(Height),0,1};
569 const auto render=[&](Scene&
target) {
571
572
573 Scene scratch(gpu.
Device(),samples);
574 for(unsigned frame=0;frame<(organic && altitude>37 ? 8u : 1u);++frame)
575 {
576
577
579 auto& destination=frame+1==(organic && altitude>37 ? 8u : 1u) ? target : scratch;
580 HR(
renderer.Render(gpu.
Context(),destination.target.Get(),destination.depth,viewport,view,projection,
581 {0,cloud.radius+altitude,0},cloud,{0,-1,0},{1,1,1,1},{.3f,.4f,.5f,1},
582 {.125f,.375f,.25f,1},{.1f,.2f,.3f,100},{.1f,.2f,.3f,168.64f}),
renderer.InitializationStatus().c_str());
583#ifdef RISE_CLOUD_FULL_RESOLUTION_FOREGROUND
584 if(organic && altitude==117 &&
HasShaderBytecode11(shaderDirectory/
"CloudOrganicCoverage-resolveCoverage-1.cso"))
585 Check(!
renderer.Parameters().ZeroOrUnset(
"_testCoverageActive"),
"large foreground fixture exercises silhouette refinement");
586#endif
587 }
588 };
589
590
591
592 if(organic && altitude>37)
593 {
594 Scene warmup(gpu.
Device(),samples);warmup.Clear(gpu.
Context());render(warmup);
595 pipeline.Pixels(gpu,warmup,samples);
596 }
597 reference.Clear(gpu.
Context());render(reference);
auto expected=pipeline.Pixels(gpu,reference,samples);
598 scene.Clear(gpu.
Context());pipeline.Occlude(gpu,scene,horizon);
const auto before=pipeline.Pixels(gpu,scene,samples);render(scene);
599 auto actual=pipeline.Pixels(gpu,scene,samples);
600 if(horizon)std::cout<<"Horizon cloud foreground at "<<altitude<<" km, "<<samples<<"x MSAA\n";
601 Protected(before,actual,expected,samples);
602
603 struct RingVertex {XMFLOAT3 position;uint32_t color;XMFLOAT2 uv;};RingVertex ring[4]{};
604 for(unsigned i=0;i<4;++i)
605 {
606 const float x=(i&1) ? 1.f : -1.f,y=(i&2) ? -1.f : 1.f;
607 const XMVECTOR camera=XMVectorSet(x*200/projection._11,y*200/projection._22,-200,1);
608 XMStoreFloat3(&ring[i].position,XMVector3TransformCoord(camera,XMLoadFloat4x4(&inverseView)));
609 ring[i].color=0xff30a0e0;ring[i].uv={float(i&1),float((i>>1)&1)};
610 }
611 auto vertices=Buffer(gpu.
Device(),ring,
sizeof(ring));
const uint32_t color=0xc0cc9966;
612 D3D11_TEXTURE2D_DESC desc{};desc.Width=desc.Height=desc.ArraySize=desc.MipLevels=1;desc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;
613 desc.SampleDesc.Count=1;desc.Usage=D3D11_USAGE_IMMUTABLE;desc.BindFlags=D3D11_BIND_SHADER_RESOURCE;
614 const D3D11_SUBRESOURCE_DATA data{&color,4,0};ComPtr<ID3D11Texture2D> texture;ComPtr<ID3D11ShaderResourceView> atmosphere;
615 HR(gpu.
Device()->CreateTexture2D(&desc,&data,&texture),
"atmosphere texture");HR(gpu.
Device()->CreateShaderResourceView(texture.Get(),
nullptr,&atmosphere),
"atmosphere SRV");
617 for(Scene* target:{&reference,&scene})HR(
renderer.Pass().RenderSkyRing(gpu.
Context(),parameters,
target->target.Get(),
target->depth,viewport,
618 atmosphere.Get(),vertices.Get(),identity,1,1),"native sky ring");
619 expected=pipeline.Pixels(gpu,reference,samples);actual=pipeline.Pixels(gpu,scene,samples);
620 if(horizon)std::cout<<"Horizon sky-ring foreground\n";
621 Protected(before,actual,expected,samples);
622
623
626 rain.
Update(.5f,rainParameters,identity);
627 for(bool attenuate:{false,true})
628 {
629 if(horizon)std::cout<<"Horizon particle foreground, attenuation "<<attenuate<<'\n';
630 reference.Clear(gpu.
Context());scene.Clear(gpu.
Context());pipeline.Occlude(gpu,scene,horizon);
631 const auto rainBefore=pipeline.Pixels(gpu,scene,samples);
633 view,projection,attenuate ? &
renderer :
nullptr),
"particle draw");
634 expected=pipeline.Pixels(gpu,reference,samples);actual=pipeline.Pixels(gpu,scene,samples);Protected(rainBefore,actual,expected,samples,0);
635 }
637 Scene mismatched(gpu.
Device(),samples==1 ? 2 : 1);
638 Check(
renderer.Pass().Render(gpu.
Context(),parameters,mismatched.target.Get(),scene.depth,viewport)==E_INVALIDARG,
"incompatible scene target rejected");
639 renderer.ReleaseSizeDependent();DebugMessages(gpu);std::cout<<
"PASS: cloud, ring and rain foreground/stencil/original "<<samples<<
"x samples\n";
640 }
641}
642#include "CloudClearance11Tests.h"
643#include "CloudSearch11Tests.h"
644#include "CloudUpperSearch11Tests.h"
645#include "CloudVisibilityBenchmark11.h"
646#include "CloudDiffuseLighting11Tests.h"
647#include "NightVisionCloud11Tests.h"
648#include "CloudNightVision11Tests.h"
649#include "RainCurtains11Tests.h"
650#include "RainMsaa11Tests.h"
651#include "RainCloudOcclusion11Tests.h"
652#include "ProceduralLightning11Tests.h"
653#include "CloudOrganicTransitions11Tests.h"
654#include "LocalCloudBase11Tests.h"
655#include "CloudOrganicOpacity11Tests.h"
656#include "CloudStartup11Tests.h"
657#include "CloudFullResolution11Tests.h"
658#include "CloudLower11Tests.h"
659#include "CloudLowerBenchmark11Tests.h"
660#include "CloudFlightPerformance11Tests.h"
661
662int main(
int argc,
char** argv)
663{
664 InitializeCloudTestDiagnostics();
665 try
666 {
667 bool boltOnly=false,rainOnly=false,rainBenchmark=false,nightVisionOnly=false,rainMsaa=false,rainMsaaBenchmark=false,cloudSearchOnly=false;
668 bool localBaseOnly=false,startupOnly=false,loadingPreparationOnly=false,loadingLegacy=false,fogIntegration=false,fogIntegrationBenchmark=false,fullResolution=false,glowBoundaries=false;
669 bool lowerCloudOnly=false,lowerCloudBenchmark=false,flightCloudComparison=false;
670 bool upperSearchOnly=false;
671 bool rainCloudOcclusion=false,rainCloudOcclusionBenchmark=false,clearanceOnly=false,organic=false,organicOpacity=false,organicHandoff=false;
672 bool warp=false,debug=true,benchmark=false,lowCloud=false,inspect=false,referenceNative=false,referenceClearance=false,denseFocus=false;
673 UINT onlySamples=0;std::filesystem::path referenceDirectory="outputs/direct3d11/shaders",shaderDirectory=referenceDirectory,visibilityOutput,visibilityInput,fogOutput;
674 float organicDiagnosticAltitude=-1,organicForegroundAltitude=-1;bool organicHorizon=false;
675 for(int i=1;i<argc;++i)
676 {
677 if(!strcmp(argv[i],"--profile-flight"))continue;
678 else if(!strcmp(argv[i],"--flight-cloud-comparison"))rainOnly=flightCloudComparison=true;
679 else if(!strcmp(argv[i],"--lower-cloud-only"))rainOnly=lowerCloudOnly=true;
680 else if(!strcmp(argv[i],"--lower-cloud-benchmark"))rainOnly=lowerCloudBenchmark=true;
681 else if(!strcmp(argv[i],"--startup-only"))startupOnly=true;
682 else if(!strcmp(argv[i],"--loading-preparation-only"))loadingPreparationOnly=true;
683 else if(!strcmp(argv[i],"--loading-legacy"))loadingPreparationOnly=loadingLegacy=true;
684 else if(!strcmp(argv[i],"--local-base-only"))localBaseOnly=true;
685 else if(!strcmp(argv[i],"--bolt-only"))boltOnly=true;
686 else if(!strcmp(argv[i],"--nvg-only"))nightVisionOnly=true;
687 else if(!strcmp(argv[i],"--rain-benchmark"))rainOnly=rainBenchmark=true;
688 else if(!strcmp(argv[i],"--rain-only"))rainOnly=true;
689 else if(!strcmp(argv[i],"--cloud-search-only"))cloudSearchOnly=true;
690 else if(!strcmp(argv[i],"--upper-search-only"))upperSearchOnly=true;
691 else if(!strcmp(argv[i],"--clearance-only"))clearanceOnly=true;
692 else if(!strcmp(argv[i],"--organic"))organic=true;
693 else if(!strcmp(argv[i],"--organic-opacity"))organic=organicOpacity=true;
694 else if(!strcmp(argv[i],"--organic-handoff"))organic=organicHandoff=true;
695 else if((!strcmp(argv[i],"--organic-foreground-only") || !strcmp(argv[i],"--organic-horizon-only")) && i+1<argc)
696 {
697 organicHorizon=!strcmp(argv[i],"--organic-horizon-only");
698 organic=true;organicForegroundAltitude=std::stof(argv[++i]);
699 Check(std::isfinite(organicForegroundAltitude) && organicForegroundAltitude>=0 && organicForegroundAltitude<=3000,
700 "organic foreground altitude must be between 0 and 3000 km");
701 Check(!organicHorizon || organicForegroundAltitude>=52,"horizon audit requires an orbital altitude");
702 }
703 else if(!strcmp(argv[i],"--organic-transition-only") && i+1<argc)
704 {
705 organic=true;organicDiagnosticAltitude=std::stof(argv[++i]);
706 Check(std::isfinite(organicDiagnosticAltitude) && organicDiagnosticAltitude>=0 && organicDiagnosticAltitude<=3000,
707 "organic diagnostic altitude must be between 0 and 3000 km");
708 }
709 else if(!strcmp(argv[i],"--fog-output") && i+1<argc)fogOutput=argv[++i];
710 else if(!strcmp(argv[i],"--fog-integration"))rainOnly=fogIntegration=true;
711 else if(!strcmp(argv[i],"--fog-integration-benchmark"))rainOnly=fogIntegration=fogIntegrationBenchmark=true;
712 else if(!strcmp(argv[i],"--full-resolution-comparison"))rainOnly=fullResolution=true;
713 else if(!strcmp(argv[i],"--glow-boundary-comparison"))rainOnly=fullResolution=glowBoundaries=true;
714 else if(!strcmp(argv[i],"--rain-msaa"))rainOnly=rainMsaa=true;
715 else if(!strcmp(argv[i],"--rain-msaa-benchmark"))rainOnly=rainMsaa=rainMsaaBenchmark=true;
716 else if(!strcmp(argv[i],"--rain-cloud-occlusion"))rainOnly=rainCloudOcclusion=true;
717 else if(!strcmp(argv[i],"--rain-cloud-occlusion-benchmark"))rainOnly=rainCloudOcclusion=rainCloudOcclusionBenchmark=true;
718 else if(!strcmp(argv[i],"--warp"))warp=true;
719 else if(!strcmp(argv[i],"--no-debug-layer"))debug=false;
720 else if(!strcmp(argv[i],"--benchmark"))benchmark=true;
721 else if(!strcmp(argv[i],"--low-cloud-benchmark"))benchmark=lowCloud=true;
722 else if(!strcmp(argv[i],"--visibility-benchmark") && i+1<argc)visibilityOutput=argv[++i];
723 else if(!strcmp(argv[i],"--visibility-benchmark-focus") && i+1<argc){visibilityOutput=argv[++i];denseFocus=true;}
724 else if(!strcmp(argv[i],"--visibility-cases") && i+1<argc)visibilityInput=argv[++i];
725 else if(!strcmp(argv[i],"--inspect-composite"))inspect=true;
726 else if(!strcmp(argv[i],"--samples") && i+1<argc)
727 {
728 onlySamples=unsigned(std::stoul(argv[++i]));
729 Check(onlySamples==1 || onlySamples==2 || onlySamples==4 || onlySamples==8,"sample count must be 1/2/4/8");
730 }
731 else if(!strcmp(argv[i],"--reference-native"))referenceNative=true;
732 else if(!strcmp(argv[i],"--reference-clearance"))referenceClearance=true;
733 else if(!strcmp(argv[i],"--reference-shaders") && i+1<argc)referenceDirectory=argv[++i];
734 else if(!strcmp(argv[i],"--shaders") && i+1<argc)shaderDirectory=argv[++i];
735 else throw std::runtime_error("unknown argument");
736 }
737 Device11 gpu;HR(gpu.
Create({warp ? D3D_DRIVER_TYPE_WARP : D3D_DRIVER_TYPE_HARDWARE,debug}),
"native device");std::cout<<gpu.
Status()<<std::endl;
738 if(!localBaseOnly && !loadingPreparationOnly && !boltOnly && !rainOnly && !benchmark && !upperSearchOnly && visibilityOutput.empty())
739 {
740 TestAtmosphericVehicleLighting();
741 TestCloudDiffuseLighting(gpu);
742 }
743 SetEnvironmentVariableA("RISE_VOLUMETRIC_CLOUDS","1");SetEnvironmentVariableA("RISE_CLOUD_SEED","0x52495345");
745 const auto initializeStart=GetTickCount64();
746 std::cout<<"Initializing native cloud programs from "<<shaderDirectory.string()<<"\n";
747 const auto initialize=
renderer.Initialize(gpu.
Device(),shaderDirectory);
748 if(FAILED(initialize))std::cerr<<
renderer.InitializationStatus()<<std::endl;
749 HR(initialize,
"cloud initialize");Check(
renderer.Ready(),
"cloud renderer enabled");
750 if(organic)Check(
renderer.Pass().OrganicFlightAvailable(),
"organic integration requires both matching specialized program sets");
751 std::cout<<"Native cloud program initialization: "<<GetTickCount64()-initializeStart<<" ms\n";
752 renderer.SetLightningEnabled(
false);
auto map=std::make_shared<CloudWeather::Map>();map->mips.push_back({32,16,std::vector<uint8_t>(32*16,153)});
CloudWeather::BuildMips(*map);
754 if(lowerCloudOnly)
755 {
758 }
759 if(fullResolution || lowerCloudBenchmark || flightCloudComparison)
760 {
761 Check(referenceNative,"comparison requires native reference shaders");
762 Check(!lowerCloudBenchmark || (!warp && !debug),"lower-cloud timing requires hardware and --no-debug-layer");
765 if(flightCloudComparison)TestCloudFlightPerformance(gpu,
renderer,before,onlySamples ? onlySamples : 2,fogOutput);
766 else if(fullResolution)TestCloudFullResolution(gpu,
renderer,before,fogOutput,glowBoundaries);
767 else
768 {
769 BenchmarkLowerAtmosphere(gpu,
renderer,before,
false,fogOutput);
770 BenchmarkLowerAtmosphere(gpu,
renderer,before,
true,fogOutput);
771 }
773 }
774 if(loadingPreparationOnly)
775 {
776 TestCloudLoadingPreparation(gpu,
renderer,onlySamples ? onlySamples : 4,!loadingLegacy);
777 TestCloudLoadingCancellation(gpu,shaderDirectory);
778 CheckCloudDeviceReleased(gpu,
renderer);
return 0;
779 }
780 if(startupOnly){TestCloudStartup(gpu,
renderer,organic);CheckCloudDeviceReleased(gpu,
renderer);
return 0;}
781 if(localBaseOnly){TestLocalCloudBases(gpu,
renderer,onlySamples);
if(!debug && !warp)TimeLocalCloudBases(gpu,
renderer);
renderer.Reset();
return 0;}
782 if(clearanceOnly)
783 {
785 }
786 if(organic)
787 {
788 if(organicHandoff){TestOrganicLightingHandoff(gpu,
renderer);
renderer.Reset();
return 0;}
789 if(organicForegroundAltitude>=0)
790 {
791 for(UINT samples:{1u,2u,4u,8u})if(!onlySamples || onlySamples==samples)
792 Test(gpu,
renderer,samples,shaderDirectory,
true,organicForegroundAltitude,organicHorizon);
793 renderer.Reset();DebugMessages(gpu);
return 0;
794 }
795 if(organicOpacity)
796 {
797 for(UINT samples:{1u,2u,4u,8u})
if(!onlySamples || onlySamples==samples)TestOrganicOpacity(gpu,
renderer,samples);
798 renderer.Reset();std::cout<<
"PASS: organic opacity integration "<<checks<<
" checks\n";
return 0;
799 }
800 if(organicDiagnosticAltitude>=0)
801 {
802 TestOrganicTransitions(gpu,
renderer,organicDiagnosticAltitude);
renderer.Reset();
return 0;
803 }
804 TestOrganicTransitions(gpu,
renderer);
805 for(UINT samples:{1u,2u,4u,8u})if(!onlySamples || onlySamples==samples)
806 for(
float altitude:{18.f,22.f,30.f,117.f})Test(gpu,
renderer,samples,shaderDirectory,
true,altitude);
807 renderer.Reset();DebugMessages(gpu);std::cout<<
"PASS: organic foreground/MSAA/history integration "<<checks<<
" checks\n";
return 0;
808 }
809 if(cloudSearchOnly)
810 {
812 }
813 if(upperSearchOnly){TestCloudUpperSearch(gpu,
renderer);
renderer.Reset();
return 0;}
814 if(nightVisionOnly)
815 {
816 for(UINT samples:{1u,2u,4u,8u})if(!onlySamples || onlySamples==samples)
817 {
818 TestNightVisionClouds(gpu,
renderer,samples);
819 TestCloudNightVisionColors(gpu,
renderer,samples,referenceNative ? referenceDirectory : std::filesystem::path{});
820 }
821 renderer.Reset();DebugMessages(gpu);std::cout<<
"PASS: "<<checks<<
" NVG cloud checks\n";
return 0;
822 }
823 if(!visibilityOutput.empty())
824 {
825 Check(!warp && !debug,"timing sweep requires hardware and --no-debug-layer");
826 BenchmarkVisibility(gpu,
renderer,onlySamples ? onlySamples : 4,visibilityOutput,denseFocus,visibilityInput);
827 return 0;
828 }
829 if(boltOnly)
830 {
831 TestBoltGeometry();
832 for(UINT samples:{1u,2u,4u,8u})
if(!onlySamples || onlySamples==samples)TestProceduralBolt(gpu,
renderer,shaderDirectory,samples);
833 renderer.Reset();DebugMessages(gpu);std::cout<<
"PASS: "<<checks<<
" procedural lightning checks\n";
return 0;
834 }
835 if(rainOnly)
836 {
837 if(fogIntegration)
838 {
839 Check(referenceNative,"fog integration comparison requires --reference-native and --reference-shaders");
840 Check(!fogIntegrationBenchmark || (!warp && !debug),"fog timing requires hardware and --no-debug-layer");
843 for(bool organicFog:{false,true})if(fogIntegrationBenchmark)
844 {
845 BenchmarkRainMsaa(gpu,
renderer,before,
true,organicFog);
846 BenchmarkRainCloudOcclusion(gpu,
renderer,before,
true,organicFog);
847 }
848 else for(UINT samples:{1u,2u,4u,8u})if(!onlySamples || onlySamples==samples)
849 {
850 TestRainMsaa(gpu,
renderer,before,samples,
true,organicFog);
851 TestRainCloudOcclusion(gpu,
renderer,before,samples,
true,fogOutput,organicFog);
852 }
854 }
855 else if(rainCloudOcclusion)
856 {
859 if(rainCloudOcclusionBenchmark)BenchmarkRainCloudOcclusion(gpu,
renderer,exact);
860 else for(UINT samples:{1u,2u,4u,8u})
if(!onlySamples || onlySamples==samples)TestRainCloudOcclusion(gpu,
renderer,exact,samples);
862 }
863 else if(rainMsaa)
864 {
869 if(rainMsaaBenchmark)BenchmarkRainMsaa(gpu,
renderer,exact);
870 else for(UINT samples:{1u,2u,4u,8u})
if(!onlySamples || onlySamples==samples)TestRainMsaa(gpu,
renderer,exact,samples);
872 }
873 else if(rainBenchmark)BenchmarkRainCurtains(gpu,
renderer);
874 else for(UINT samples:{1u,2u,4u,8u})
if(!onlySamples || onlySamples==samples)TestRainCurtains(gpu,
renderer,samples);
875 renderer.Reset();DebugMessages(gpu);
876 std::cout<<"PASS: "<<checks<<" spatial rain checks\n";return 0;
877 }
879 HR(baseline.
Initialize(gpu.
Device(),referenceNative ? referenceDirectory : ReferenceShaders(referenceDirectory)),
"baseline cloud initialize");baseline.
SetLightningEnabled(
false);
881
882
884 if(benchmark)
885 {
886 if(lowCloud)
887 {
888 for(UINT samples:{1u,4u})if(!onlySamples || onlySamples==samples)
889 BenchmarkComposite(gpu,
renderer,baseline,referenceClearance,
true,samples);
890 }
891 else BenchmarkComposite(gpu,
renderer,baseline,referenceClearance);
892 return 0;
893 }
894 TestBoltGeometry();
895 for(UINT samples:{1u,2u,4u,8u})
896 {
897 if(onlySamples && onlySamples!=samples)continue;
898 {TestNightVisionClouds(gpu,
renderer,samples);TestCloudNightVisionColors(gpu,
renderer,samples);}
899 TestProceduralBolt(gpu,
renderer,shaderDirectory,samples);
900 TestRainCurtains(gpu,
renderer,samples);
901 Test(gpu,
renderer,samples,shaderDirectory);TestWindshield(gpu,samples,shaderDirectory);
902 CompareComposite(gpu,
renderer,baseline,samples,inspect);
903 TestFogContinuity(gpu,
renderer,samples);
904 }
907 gpu.
Context()->ClearState();
renderer.Reset();DebugMessages(gpu);std::cout<<
"PASS: "<<checks<<
" native scene checks\n";
return 0;
908 }
909 catch(const std::exception& error){std::cerr<<"FAIL: "<<error.what()<<std::endl;return 1;}
910}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
void SetRainMsaaSharingEnabled(bool enabled)
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 SetHeadlights(const std::vector< Headlight > &lights)
void SetLocalLightning(const Vector &position, const Color &color, float radiusKm)
void SetLightningEnabled(bool value)
void UpdateWeather(const CloudWeather::MapPtr &map, double elapsed)
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &shaderDirectory={})
void SetClearAirOptimizationEnabled(bool value)
HRESULT PrepareResources(ID3D11DeviceContext *context)
bool SupportsSamples(UINT count) const
ID3D11DeviceContext * Context() const
ID3D11Device * Device() const
const std::string & Status() const
HRESULT Create(const DeviceOptions11 &options={})
HRESULT RemovalReason() const
HRESULT Initialize(ID3D11Device *device, const std::filesystem::path &shaderDirectory={})
ExteriorRain::BasicParameters< Vector, Color > Parameters
HRESULT Render(ID3D11DeviceContext *context, ID3D11RenderTargetView *scene, const SceneDepth11 &depth, const D3D11_VIEWPORT &viewport, const Matrix &view, const Matrix &projection, CloudRenderer11 *clouds=nullptr)
void Update(float elapsed, const Parameters ¶meters, const Matrix &localToWorld)
HRESULT Create(ID3D11Device *device, UINT width, UINT height, DXGI_SAMPLE_DESC samples)
ID3D11DepthStencilView * WriteView() const
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 Update(float elapsed, float rain, const Vector &acceleration, const Vector &relativeWind, const std::vector< Matrix > &transforms, float airDensity, bool wiping, float rainAir=0)
void AddGlass(int component, const Vertex *vertices, size_t count)
Point Scale(Point p, float s)
Column Boundaries(Point p, const Parameters ¶ms, uint32_t seed=DefaultSeed)
SRenderWeather Sample(const unsigned char *p)
constexpr uint8_t Pixels[262144]
bool HasShaderBytecode11(const std::filesystem::path &path)
uint32_t Color(Echo echo)
CloudWeather::Frame weather