1
2#include "../Rendering/Device11.h"
3#include "../Rendering/Program11.h"
4#include "../Rendering/Texture11.h"
5#include "../Rendering/Shaders/Catalog11.generated.h"
6#include "../ThirdParty/DirectXTK/ScreenGrab.h"
7#include <d3d11sdklayers.h>
8#include <wincodec.h>
9#include <DirectXMath.h>
10#include <algorithm>
11#include <array>
12#include <cmath>
13#include <filesystem>
14#include <fstream>
15#include <iostream>
16#include <limits>
17#include <stdexcept>
18
20using Microsoft::WRL::ComPtr;
21namespace {
22constexpr UINT Width=1280,Height=720;
23void Check(bool value,const char* message) {if(!value)throw std::runtime_error(message);}
24void HR(
HRESULT hr,
const char* message) {Check(SUCCEEDED(hr),message);}
25struct V4 {float x,y,z,w;};
26struct Matrix {
float m[16];};
27Matrix Identity() {
return {{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1}};}
28struct Vertex {V4 position,color,emission;float u,v;};
29const D3D11_INPUT_ELEMENT_DESC Elements[]={
30 {"POSITION",0,DXGI_FORMAT_R32G32B32A32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0},
31 {"COLOR",0,DXGI_FORMAT_R32G32B32A32_FLOAT,0,16,D3D11_INPUT_PER_VERTEX_DATA,0},
32 {"COLOR",1,DXGI_FORMAT_R32G32B32A32_FLOAT,0,32,D3D11_INPUT_PER_VERTEX_DATA,0},
33 {"TEXCOORD",0,DXGI_FORMAT_R32G32_FLOAT,0,48,D3D11_INPUT_PER_VERTEX_DATA,0}};
34std::vector<char> Bytes(const std::filesystem::path& path) {
35 std::ifstream file(path,std::ios::binary);Check(file.good(),"shader bytecode missing; run CompileShaders11.py");
36 return {std::istreambuf_iterator<char>(file),std::istreambuf_iterator<char>()};
37}
38struct Fixture {
39 Device11 gpu;Parameters11 parameters;Program11 detail,baseline;
40 ComPtr<ID3D11Texture2D>
target,staging;ComPtr<ID3D11RenderTargetView> rtv;
41 ComPtr<ID3D11Buffer> vertices;
42 Texture11 rock,sand,transition,water;
43 std::vector<ComPtr<ID3D11ShaderResourceView>> solids;
44 std::filesystem::path
output=
"outputs/terrain-surface-detail";
45 bool hasBaseline=false;
46 Fixture(bool warp,bool debug,const std::filesystem::path& shaderPath="outputs/direct3d11/shaders") {
47 HR(gpu.
Create({warp ? D3D_DRIVER_TYPE_WARP : D3D_DRIVER_TYPE_HARDWARE,debug}),
"create device");
48 std::cout<<gpu.
Status()<<
'\n';
49 D3D11_TEXTURE2D_DESC td{};td.Width=
Width;td.Height=
Height;td.MipLevels=td.ArraySize=1;
50 td.Format=DXGI_FORMAT_R8G8B8A8_UNORM;td.SampleDesc.Count=1;td.BindFlags=D3D11_BIND_RENDER_TARGET;
51 HR(gpu.
Device()->CreateTexture2D(&td,
nullptr,&target),
"target");
52 HR(gpu.
Device()->CreateRenderTargetView(
target.Get(),
nullptr,&rtv),
"RTV");
53 td.BindFlags=0;td.Usage=D3D11_USAGE_STAGING;td.CPUAccessFlags=D3D11_CPU_ACCESS_READ;
54 HR(gpu.
Device()->CreateTexture2D(&td,
nullptr,&staging),
"staging");
55 D3D11_RASTERIZER_DESC rd{};rd.FillMode=D3D11_FILL_SOLID;rd.CullMode=D3D11_CULL_NONE;rd.DepthClipEnable=TRUE;
56 ComPtr<ID3D11RasterizerState> raster;HR(gpu.
Device()->CreateRasterizerState(&rd,&raster),
"raster");gpu.
Context()->RSSetState(raster.Get());
57 D3D11_DEPTH_STENCIL_DESC ds{};ds.DepthFunc=D3D11_COMPARISON_ALWAYS;
58 ComPtr<ID3D11DepthStencilState> depth;HR(gpu.
Device()->CreateDepthStencilState(&ds,&depth),
"depth");gpu.
Context()->OMSetDepthStencilState(depth.Get(),0);
59 D3D11_VIEWPORT vp{0,0,float(Width),float(Height),0,1};gpu.
Context()->RSSetViewports(1,&vp);
60 for(
const auto& sampler:CustomUISamplers) {ComPtr<ID3D11SamplerState> state;HR(gpu.
Device()->CreateSamplerState(&sampler.description,&state),
"sampler");parameters.
Sampler(sampler.name,state.Get());}
61 Load(detail,shaderPath);
62 hasBaseline=std::filesystem::exists(output/"baseline/CustomUI-PS0-1.cso");
63 if(hasBaseline)Load(baseline,output/"baseline");
64 HR(rock.
Load(gpu.
Device(),gpu.
Context(),L
"Textures/Terrain/Landform_14.png"),
"rock");
65 HR(sand.
Load(gpu.
Device(),gpu.
Context(),L
"Textures/Terrain/Landform_27.png"),
"sand");
66 HR(transition.
Load(gpu.
Device(),gpu.
Context(),L
"Textures/Terrain/Transition_01.png"),
"transition");
67 HR(water.
Load(gpu.
Device(),gpu.
Context(),L
"Textures/Terrain/Water_Normal.png"),
"water");
68 Solid("CloudMap",0xff808080);Solid("ColorMap4",0xff807060);Solid("ColorMap3",0xff000000);
71 }
72 void Load(Program11& program,const std::filesystem::path& directory,int pass=0) {
73 auto vs=Bytes(directory/("CustomUI-VS"+std::to_string(pass)+"-1.cso")),
74 ps=Bytes(directory/("CustomUI-PS"+std::to_string(pass)+"-1.cso"));
75 HR(program.
Create(gpu.
Device(),vs.data(),vs.size(),ps.data(),ps.size(),Elements,UINT(std::size(Elements))),
"program");
76 }
77 void Solid(const char* name,uint32_t color) {
78 D3D11_TEXTURE2D_DESC d{};d.Width=d.Height=d.MipLevels=d.ArraySize=1;d.Format=DXGI_FORMAT_R8G8B8A8_UNORM;d.SampleDesc.Count=1;d.BindFlags=D3D11_BIND_SHADER_RESOURCE;
79 D3D11_SUBRESOURCE_DATA init{&color,4,0};ComPtr<ID3D11Texture2D> tex;ComPtr<ID3D11ShaderResourceView> view;
80 HR(gpu.
Device()->CreateTexture2D(&d,&init,&tex),
"solid texture");HR(gpu.
Device()->CreateShaderResourceView(tex.Get(),
nullptr,&view),
"solid SRV");
81 parameters.
Texture(name,view.Get());solids.push_back(view);
82 }
83 void Vector(
const char* name,
float x,
float y,
float z,
float w) {parameters.
Set(name,V4{x,y,z,w});}
84 void Geometry(
float u0=.32f,
float v0=.28f,
float u1=.48f,
float v1=.37f) {
85 const V4 color{.60f,.44f,.32f,0},emission{0,0,0,0};
86 const Vertex quad[]={{{-1,1,.1f,1},color,emission,u0,v0},{{1,1,.1f,1},color,emission,u1,v0},{{-1,-1,.1f,1},color,emission,u0,v1},{{1,-1,.1f,1},color,emission,u1,v1}};
87 vertices.Reset();D3D11_BUFFER_DESC vb{};vb.ByteWidth=sizeof(quad);vb.Usage=D3D11_USAGE_IMMUTABLE;vb.BindFlags=D3D11_BIND_VERTEX_BUFFER;
88 D3D11_SUBRESOURCE_DATA initial{quad,0,0};HR(gpu.
Device()->CreateBuffer(&vb,&initial,&vertices),
"geometry");
89 auto world=
Identity();world.m[0]=(u1-u0);world.m[5]=(v1-v0);world.m[10]=0;world.m[14]=-.12f;
90 parameters.
Set(
"matWorld",world);
91 }
94 Vector(
"ambient",.55f,.55f,.55f,25);
Vector(
"shiplight",0,0,0,0);
Vector(
"WeapPos",0,0,0,0);
95 Vector(
"Features",0,0,0,0);
Vector(
"clouduv",0,0,0,0);
Vector(
"Tangent",1,0,0,0);
Vector(
"Sunlight",0,1,0,0);
Vector(
"Radiosity",0,0,1,0);
96 Vector(
"TerrainDetailSun",.8f,0,.6f,1);parameters.
Set(
"LandingLightCount",
int(0));
97 Landforms(14,0,27,0,14);
98 }
99 void GroundGeometry(float eyeHeight=.0017f,float eyeX=0) {
100 const V4 color{.60f,.44f,.32f,0},emission{0,0,0,0};
101 const Vertex quad[]={
102 {{-1,1.5f,0,1},color,emission,0,1},{{1,1.5f,0,1},color,emission,1,1},
103 {{-1,-.5f,0,1},color,emission,0,0},{{1,-.5f,0,1},color,emission,1,0}};
104 vertices.Reset();D3D11_BUFFER_DESC vb{};vb.ByteWidth=sizeof(quad);vb.Usage=D3D11_USAGE_IMMUTABLE;vb.BindFlags=D3D11_BIND_VERTEX_BUFFER;
105 D3D11_SUBRESOURCE_DATA initial{quad,0,0};HR(gpu.
Device()->CreateBuffer(&vb,&initial,&vertices),
"ground geometry");
106 auto world=
Identity();world.m[12]=-eyeX;world.m[14]=-eyeHeight;parameters.
Set(
"matWorld",world);
107 using namespace DirectX;
108 const float down=XMConvertToRadians(15.f);
109 const auto view=XMMatrixLookToLH(XMVectorSet(eyeX,0,eyeHeight,1),XMVectorSet(0,cosf(down),-sinf(down),0),XMVectorSet(0,0,1,0));
110 const float verticalFov=2*atanf(tanf(XMConvertToRadians(65.f)*.5f)*float(Height)/Width);
111 const auto projection=XMMatrixPerspectiveFovLH(verticalFov,float(Width)/Height,.0001f,4.f);
112 XMFLOAT4X4 transform;XMStoreFloat4x4(&transform,view*projection);
113 Matrix wvp;memcpy(&wvp,&transform,
sizeof(wvp));parameters.
Set(
"matWorldViewProj",wvp);
114 }
115 void SmoothHeightRegression() {
116
117
118 constexpr UINT N=16;std::array<V4,N*N> pixels;
119 for(UINT y=0;y<N;++y)for(UINT x=0;x<N;++x){const float h=.1f+.8f*x/(N-1);pixels[y*N+x]={h,h,h,1};}
120 D3D11_TEXTURE2D_DESC d{};d.Width=d.Height=N;d.MipLevels=d.ArraySize=1;d.Format=DXGI_FORMAT_R32G32B32A32_FLOAT;d.SampleDesc.Count=1;d.BindFlags=D3D11_BIND_SHADER_RESOURCE;
121 D3D11_SUBRESOURCE_DATA init{pixels.data(),N*sizeof(V4),0};ComPtr<ID3D11Texture2D> tex;ComPtr<ID3D11ShaderResourceView> srv;
122 HR(gpu.
Device()->CreateTexture2D(&d,&init,&tex),
"smooth height texture");HR(gpu.
Device()->CreateShaderResourceView(tex.Get(),
nullptr,&srv),
"smooth height view");
123 unsigned maximumJump=0;
124 for(float offset:{0.f,.000031f,.000071f}) {
126 const auto image=
Render(
true,offset==0 ? L
"smooth-height-ramp.png" :
nullptr);
127 for(UINT y=2;y<
Height-2;++y)
for(UINT x=2;x<
Width-2;++x)
for(UINT shift:{0u,8u,16u}) {
128 const int value=
int((image[y*Width+x]>>shift)&255),left=
int((image[y*Width+x-1]>>shift)&255),up=
int((image[(y-1)*Width+x]>>shift)&255);
129 maximumJump=(std::max)(maximumJump,unsigned((std::max)(std::abs(value-left),std::abs(value-up))));
130 }
131 }
132 std::cout<<"Magnified smooth height maximum neighbor jump: "<<maximumJump<<" / 255\n";
133 Check(maximumJump<=2,"smooth height produces no sampling stripes across subpixel offsets");
134
135
136 pixels.fill({.5f,.5f,.5f,1});gpu.
Context()->UpdateSubresource(tex.Get(),0,
nullptr,pixels.data(),N*
sizeof(V4),0);
137 Check(
Render(
false)==
Render(
true),
"flat height stays neutral at submillimeter footprints");
Configure();
138 }
139 void Landforms(int a,int ab,int b,int bc,int c) {
140 const int flags[]={a,ab,b,bc,c};parameters.
Set(
"flags",flags);
141 const auto tex=[&](
int n){
return n==1 ? water.
View() : n==27 ? sand.
View() : rock.
View();};
142 parameters.
Texture(
"ColorMap",tex(a));parameters.
Texture(
"ColorMap2",tex(b));parameters.
Texture(
"ColorMap3",tex(c));
143 }
144 void Bind(Program11& program,
bool enabled) {
145 Vector(
"TerrainDetail",enabled ? 1.f : 0.f,0,0,0);
146 auto* context=gpu.
Context();
auto* view=rtv.Get();context->OMSetRenderTargets(1,&view,
nullptr);
147 auto* vb=vertices.Get();const UINT stride=sizeof(Vertex),offset=0;context->IASetVertexBuffers(0,1,&vb,&stride,&offset);context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
148 HR(program.
Bind(context,parameters),
"bind terrain");
149 }
150 std::vector<uint32_t>
Render(
bool enabled,
const wchar_t* name=
nullptr,Program11* program=
nullptr) {
151 Bind(program ? *program : detail,enabled);
152 const float clear[]={.55f,.55f,.55f,1};gpu.
Context()->ClearRenderTargetView(rtv.Get(),clear);
153 gpu.
Context()->Draw(4,0);gpu.
Context()->OMSetRenderTargets(0,
nullptr,
nullptr);
155 gpu.
Context()->CopyResource(staging.Get(),
target.Get());D3D11_MAPPED_SUBRESOURCE map{};HR(gpu.
Context()->Map(staging.Get(),0,D3D11_MAP_READ,0,&map),
"readback");
156 std::vector<uint32_t> result(Width*Height);
for(UINT y=0;y<
Height;++y)memcpy(result.data()+y*Width,
static_cast<char*
>(map.pData)+y*map.RowPitch,Width*4);
157 gpu.
Context()->Unmap(staging.Get(),0);
return result;
158 }
159 double Time(Program11& program,
bool enabled) {
160 Bind(program,enabled);
auto* c=gpu.
Context();
for(
int i=0;i<20;++i)c->Draw(4,0);
161 ComPtr<ID3D11Query> disjoint,start,end;D3D11_QUERY_DESC q{D3D11_QUERY_TIMESTAMP_DISJOINT,0};
162 HR(gpu.
Device()->CreateQuery(&q,&disjoint),
"timer");q.Query=D3D11_QUERY_TIMESTAMP;HR(gpu.
Device()->CreateQuery(&q,&start),
"timestamp");HR(gpu.
Device()->CreateQuery(&q,&end),
"timestamp");
163 constexpr int Count=64;c->Begin(disjoint.Get());c->End(start.Get());
for(
int i=0;i<
Count;++i)c->Draw(4,0);c->End(end.Get());c->End(disjoint.Get());c->Flush();
164 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT timing{};UINT64 first=0,last=0;
165 const ULONGLONG deadline=GetTickCount64()+10000;
166 const auto wait=[&](ID3D11Query* query,void* data,UINT bytes) {
167 HRESULT hr;
while((hr=c->GetData(query,data,bytes,0))==S_FALSE){Check(GetTickCount64()<deadline,
"GPU timer timeout");Sleep(1);}HR(hr,
"GPU query data");
168 };
169 wait(disjoint.Get(),&timing,sizeof(timing));wait(start.Get(),&first,sizeof(first));wait(end.Get(),&last,sizeof(last));
170 Check(!timing.Disjoint && timing.Frequency>0 && last>first,
"valid nonzero GPU timing");
return double(last-first)*1000/timing.Frequency/
Count;
171 }
172 void DebugClean() {
173 ComPtr<ID3D11InfoQueue> queue;
if(FAILED(gpu.
Device()->QueryInterface(IID_PPV_ARGS(&queue))))
return;
174 unsigned errors=0;for(UINT64 i=0;i<queue->GetNumStoredMessages();++i){SIZE_T size=0;queue->GetMessage(i,nullptr,&size);std::vector<char> data(size);auto* m=reinterpret_cast<D3D11_MESSAGE*>(data.data());queue->GetMessage(i,m,&size);if(m->Severity<=D3D11_MESSAGE_SEVERITY_WARNING){std::cerr<<m->pDescription<<'\n';++errors;}}Check(!errors,"debug-layer warnings/errors");
175 }
176};
177double Difference(const std::vector<uint32_t>& a,const std::vector<uint32_t>& b) {
178 double total=0;for(size_t i=0;i<a.size();++i)for(unsigned s:{0u,8u,16u})total+=std::abs(int((a[i]>>s)&255)-int((b[i]>>s)&255));return total/(a.size()*3);
179}
180}
181static void CheckSnowShader(Fixture& f,const std::filesystem::path& shaders)
182{
183 for(int pass=0;pass<=1;++pass) {
184 Program11 program;f.Load(program,shaders,pass);
185 f.Configure();f.Geometry(0,0,1,1);
186 const auto set=[&](float coverage) {
187 for(const auto* name:{"TerrainSnow00","TerrainSnow10","TerrainSnow01","TerrainSnow11"})
188 f.Vector(name,232.f/255*coverage,239.f/255*coverage,250.f/255*coverage,coverage);
189 };
190 set(0);const auto dry=f.Render(false,nullptr,&program);
191 set(.5f);const auto half=f.Render(false,nullptr,&program);
192 set(1);const auto snow=f.Render(false,nullptr,&program);
193 Check(Difference(dry,snow)>5,"snow does not tint terrain");
194 Check(Difference(dry,half)>1 && Difference(half,snow)>1,"partial snow coverage missing");
195 Check(snow==f.Render(false,nullptr,&program),"snow is cumulative or unstable");
196 f.Solid("ColorMap",0xff101010);
197 Check(snow==f.Render(false,nullptr,&program),"full snow alpha failed to suppress dirt texture");
198 f.Landforms(14,0,27,0,14);
199 set(0);Check(dry==f.Render(false,nullptr,&program),"melt did not restore original ground color");
200 f.Vector("TerrainSnow10",232.f/255,239.f/255,250.f/255,1);
201 f.Vector("TerrainSnow11",232.f/255,239.f/255,250.f/255,1);
202 const auto gradient=f.Render(false,pass==0 ? L"snow-gradient.png" : nullptr,&program);
203 double left=0,right=0;
204 for(UINT y=20;y<
Height-20;++y)
for(UINT x=20;x<
Width/8;++x) {
205 for(unsigned shift:{0u,8u,16u}) {
206 const auto delta=[&](UINT px){return std::abs(int((gradient[y*Width+px]>>shift)&255)-int((dry[y*Width+px]>>shift)&255));};
207 left+=delta(x);right+=delta(Width-1-x);
208 }
209 }
210 Check(right>left*2,"snow corner interpolation lost storm direction");
211 for(size_t i=0;i<dry.size();++i)Check((dry[i]&0xff000000)==(snow[i]&0xff000000),"snow altered terrain alpha");
212 f.Landforms(1,0,1,0,1);set(0);const auto water=f.Render(false,nullptr,&program);
213 set(1);Check(water==f.Render(false,nullptr,&program),"snow tint changed open-water shading");
214 set(0);
215 }
216 f.DebugClean();std::cout<<"PASS native near/far terrain snow, gradients, melt, alpha and water exclusions\n";
217}
218int main(
int argc,
char** argv) {
219 CoInitializeEx(nullptr,COINIT_APARTMENTTHREADED);
220 try {
221 bool warp=false,debug=true,benchmark=true;for(int i=1;i<argc;++i){warp|=!strcmp(argv[i],"--warp");debug&=strcmp(argv[i],"--no-debug-layer")!=0;benchmark&=strcmp(argv[i],"--no-benchmark")!=0;}
222 bool snowOnly=false;std::filesystem::path shaders="outputs/direct3d11/shaders";
223 for(int i=1;i<argc;++i) {snowOnly|=!strcmp(argv[i],"--snow-only");if(!strcmp(argv[i],"--shaders") && i+1<argc)shaders=argv[++i];}
224 Fixture f(warp,debug,shaders);std::filesystem::create_directories(f.output);
225 if(snowOnly){CheckSnowShader(f,shaders);return 0;}
226 f.SmoothHeightRegression();
227 const auto off=f.Render(false,L"rock-off.png"),on=f.Render(true,L"rock-on.png");
228 Check(Difference(off,on)>.5,"authored rock gains visible detail");Check(on==f.Render(true),"detail is deterministic");
229 if(f.hasBaseline)Check(off==f.Render(false,nullptr,&f.baseline),"off restores original shader pixels");
230 f.Vector("TerrainDetailSun",-.8f,0,.6f,1);Check(Difference(on,f.Render(true))>.3,"relief follows sun direction");
231 f.Configure();f.Landforms(27,0,14,0,14);f.Render(true,L"sand-on.png");
232 for(const auto& flags:std::array<std::array<int,5>,4>{{{{14,1,27,0,14}},{{14,1,27,1,14}},{{14,1,1,0,14}},{{1,1,14,1,27}}}}) {
233 f.Landforms(flags[0],flags[1],flags[2],flags[3],flags[4]);const auto a=f.Render(false),b=f.Render(true);
234 Check(Difference(a,b)>.1,"material transitions retain relief");
235 }
236 f.Render(true,L"transition-on.png");f.Landforms(1,0,1,0,1);Check(f.Render(false)==f.Render(true),"water remains identical");
237 f.Configure();
auto distantWorld=
Identity();distantWorld.m[0]=.16f;distantWorld.m[5]=.09f;distantWorld.m[10]=0;distantWorld.m[14]=-3.3f;f.parameters.Set(
"matWorld",distantWorld);
238 Check(f.Render(false)==f.Render(true),"detail fades before far-pass handoff");
239 f.Configure();f.Geometry(0,.28f,0,.37f);Check(f.Render(false)==f.Render(true),"plot boundary is unchanged and degenerate UV is finite");
240 f.Configure();f.Geometry(.739f,.3f,.761f,.6f);f.Vector("Features",1,0,0,0);Check(f.Render(false)==f.Render(true),"opaque runway masks relief");
241 f.Configure();f.Geometry(.4965f,.1f,.5035f,.4f);f.Vector("Features",3,0,0,8);Check(f.Render(false)==f.Render(true),"opaque road masks relief");
242 f.Configure();f.Vector("ambient",.02f,.025f,.03f,25);f.Vector("shiplight",1,.9f,.8f,0);f.Vector("TerrainDetailSun",0,0,-1,0);
243 Check(Difference(f.Render(false),f.Render(true,L"night-on.png"))>.1,"near lamps reveal detail at night");
244 f.Configure();f.GroundGeometry();f.Vector("TerrainDetailSun",.8f,-.2f,std::sqrt(.32f),1);
245 const auto groundOff=f.Render(false,L"ground-eye-1p7m-off.png"),groundOn=f.Render(true,L"ground-eye-1p7m-on.png");
246 Check(Difference(groundOff,groundOn)>.5,"ground-level view retains visible relief");
247 if(f.hasBaseline)Check(groundOff==f.Render(false,nullptr,&f.baseline),"disabled ground-level view matches original");
248 for(float cameraX:{.0000001f,.0000002f}){f.GroundGeometry(.0017f,cameraX);const auto shifted=f.Render(true);Check(Difference(groundOn,shifted)<1,"submillimeter camera motion has no large lighting jumps");}
249 f.DebugClean();
250 if(!benchmark){std::cout<<"PASS: terrain detail regression checks (benchmark skipped)\n";CoUninitialize();return 0;}
251 std::ofstream metrics(f.output/(warp ? "timing-warp.csv" : "timing-hardware.csv"));metrics<<"scene,layers,original_ms,off_ms,on_ms\n";
252 for(bool ground:{false,true})for(int layers:{1,3}) {
253 f.Configure();if(ground)f.GroundGeometry();if(layers==3)f.Landforms(14,1,27,1,14);
254 std::array<std::vector<double>,3> values;
255 for(int round=0;round<7;++round)for(int offset=0;offset<3;++offset){const int mode=(round+offset)%3;if(mode==0 && !f.hasBaseline)continue;values[mode].push_back(f.Time(mode==0 ? f.baseline : f.detail,mode==2));}
256 double medians[3]={std::numeric_limits<double>::quiet_NaN(),0,0};for(int m=0;m<3;++m)if(!values[m].empty()){std::sort(values[m].begin(),values[m].end());medians[m]=values[m][values[m].size()/2];}
257 metrics<<(ground ? "ground" : "overhead")<<','<<layers<<','<<medians[0]<<','<<medians[1]<<','<<medians[2]<<'\n';std::cout<<(ground ? "ground " : "overhead ")<<layers<<" layers, 1280x720 GPU ms: original="<<medians[0]<<" off="<<medians[1]<<" on="<<medians[2]<<'\n';
258 }
259 std::cout<<"PASS: terrain detail pixels, water, paving, fade, sun, night, determinism and GPU timing\n";CoUninitialize();return 0;
260 }catch(const std::exception& e){std::cerr<<"FAIL: "<<e.what()<<'\n';CoUninitialize();return 1;}
261}
SCRIPT_CONTROL SCRIPT_STATE const void int
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
ID3D11DeviceContext * Context() const
ID3D11Device * Device() const
const std::string & Status() const
HRESULT Create(const DeviceOptions11 &options={})
void Set(const std::string &name, const void *data, size_t bytes)
void Texture(const std::string &name, ID3D11ShaderResourceView *value)
void Sampler(const std::string &name, ID3D11SamplerState *value)
HRESULT Create(ID3D11Device *device, const void *vertexCode, size_t vertexSize, const void *pixelCode, size_t pixelSize, const D3D11_INPUT_ELEMENT_DESC *elements=nullptr, UINT elementCount=0, UINT bgraColorMask=0)
HRESULT Bind(ID3D11DeviceContext *context, const Parameters11 ¶meters)
ID3D11ShaderResourceView * View() const
HRESULT Load(ID3D11Device *device, ID3D11DeviceContext *context, const wchar_t *path)
Sphere Configure(bool simulator, Point center, float radius, float solarRadius)
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)
HRESULT Render(RiseDialog &hud, float elapsedTime, int dialogId, Logger &logger)
Path Geometry(const Input &, const Request &r, const ArrivalPreview &gate)
DirectX::XMFLOAT4X4 Matrix
std::function< void(std::uint64_t)> Identity
void Bind(Rendering::RenderDevice &device, Rendering::RenderTexture *texture)