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

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

1namespace
2{
3 // Synthetic, frozen geometry at the two captured altitudes/cloud bases.
4 // This is a controlled GPU comparison, not a replay of the game's world.
5 void BenchmarkLowerAtmosphere(Device11& gpu,CloudRenderer11& after,CloudRenderer11& before,bool organic,const std::filesystem::path& requestedOutput)
6 {
7 before.Pass().SetVisibilityOptimizationEnabled(false);
8 char selection[32]{}; const char* selected=GetEnvironmentVariableA("RISE_BENCH_SCENES",selection,32) ? selection : nullptr;
9 constexpr UINT width=3440,height=1351,samples=4,batch=12;
10 Scene scene(gpu.Device(),samples,width,height);RainMsaaFixture fixture(gpu.Device(),samples);
11 const D3D11_VIEWPORT viewport{0,0,float(width),float(height),0,1};
12 XMFLOAT4X4 view,projection;XMStoreFloat4x4(&view,XMMatrixIdentity());
13 XMStoreFloat4x4(&projection,XMMatrixPerspectiveFovRH(1.f,float(width)/height,.001f,384));
14 auto grid=std::make_unique<CloudRenderer11::RainGrid>();grid->cube=0;grid->u=grid->v=1019;
15 const auto output=requestedOutput.empty() ? std::filesystem::path("outputs/chojeir-lower-cloud-20261015/focused-images") : requestedOutput;
16 std::filesystem::create_directories(output);
17 ComPtr<ID3D11Query> disjoint,begin,end;D3D11_QUERY_DESC desc{D3D11_QUERY_TIMESTAMP_DISJOINT,0};
18 HR(gpu.Device()->CreateQuery(&desc,&disjoint),"lower benchmark disjoint");desc.Query=D3D11_QUERY_TIMESTAMP;
19 HR(gpu.Device()->CreateQuery(&desc,&begin),"lower benchmark begin");HR(gpu.Device()->CreateQuery(&desc,&end),"lower benchmark end");
20 auto* context=gpu.Context();
21 for(unsigned scenario=0;scenario<11;++scenario)
22 {
23 if(selected && !std::strchr(selected,int('0'+scenario)))continue;
24 const bool car=scenario==0 || scenario==4;
25 const float altitude=car ? .300293f : scenario==5 ? 5.f : 2.074219f;
26 CloudVolume::Parameters cloud;cloud.organic=organic;cloud.weather=after.WeatherFrame();
27 cloud.base=car ? 1.054188f : 2.657341f;cloud.top=car ? 11.384669f : 11.731112f;
28 if(scenario>=3 && scenario<=8)
29 {
30 auto local=std::make_shared<CloudBaseWeather::Grid>();local->cube=0;local->u=local->v=1019;
31 local->cells.fill({cloud.base,.6f,1,0});
32 for(unsigned y=0;y<10;++y)for(unsigned x=0;x<10;++x)local->cells[y*64+x].base=.4f;
33 local->Bounds();cloud.localBase={local,1};
34 }
35 grid->revision=scenario+1;grid->cells.fill({car ? .300293f : 2.074219f,cloud.base,(scenario==6 ? .1f : scenario==7 ? 1.f : scenario==8 ? 5.f : 27.72f),car ? 2.f : 16.f});
36 std::vector<CloudRenderer11::Headlight> lights;
37 if(scenario==4)lights.push_back({{0,cloud.radius+altitude,0},{0,0,-1},{4,4,4,1},2});
38 for(auto* current:{&before,&after}){current->SetRainGrid(grid.get());current->SetHeadlights(lights);current->SetLightningEnabled(false);current->ResetCloudHistory();}
39 for(unsigned repeat=0;repeat<8;++repeat)for(unsigned order=0;order<2;++order)
40 {
41 const bool changed=(order^(repeat&1))!=0;auto& current=changed ? after : before;
42 const auto draw=[&]()
43 {
44 fixture.Draw(gpu,scene,viewport,{.9997f,.00024f,0,0},scenario!=2 && scenario!=9);
45 if(scenario==2 || scenario==9)scene.Clear(context);
46 auto* target=scene.target.Get();context->OMSetRenderTargets(1,&target,scene.depth.WriteView());
47 if(scenario<9)
48 {
49 const D3D11_VIEWPORT cockpit{0,height*.78f,float(width),height*.22f,0,1};context->RSSetViewports(1,&cockpit);
50 context->RSSetState(fixture.pipeline.raster.Get());context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
51 context->VSSetShader(fixture.pipeline.full.Get(),nullptr,0);context->PSSetShader(fixture.pipeline.blue.Get(),nullptr,0);
52 context->OMSetDepthStencilState(fixture.pipeline.stencil.Get(),3);context->Draw(3,0);context->OMSetRenderTargets(0,nullptr,nullptr);
53 }
54 HR(current.Render(context,scene.target.Get(),scene.depth,viewport,view,projection,{0,cloud.radius+altitude,0},cloud,
55 {0,-1,0},{1,1,1,1},{.3f,.4f,.5f,1},{.125f,.375f,.25f,1},{.3f,.4f,.5f,42.16f}),"lower benchmark render");
56 };
57 for(unsigned warm=0;warm<3;++warm)draw();
58
59 context->Begin(disjoint.Get());context->End(begin.Get());for(unsigned i=0;i<batch;++i)draw();
60 context->End(end.Get());context->End(disjoint.Get());context->Flush();
61 const auto read=[&](ID3D11Query* query,void* destination,UINT bytes)
62 {
63 HRESULT hr;const auto deadline=GetTickCount64()+30000;
64 while((hr=context->GetData(query,destination,bytes,0))==S_FALSE)
65 {if(GetTickCount64()>deadline)throw std::runtime_error("lower benchmark timeout");Sleep(1);}
66 HR(hr,"lower benchmark timestamp");
67 };
68 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT frequency{};UINT64 first=0,last=0;
69 read(disjoint.Get(),&frequency,sizeof(frequency));read(begin.Get(),&first,sizeof(first));read(end.Get(),&last,sizeof(last));
70 Check(!frequency.Disjoint,"lower benchmark frequency");
71 std::cout<<"Lower atmosphere "<<(organic ? "organic" : "legacy")<<" scene "<<scenario<<" "<<(changed ? "after" : "before")
72 <<" iteration "<<repeat<<": "<<double(last-first)*1000/frequency.Frequency/batch<<" ms"<<std::endl;
73 }
74 }
75 before.SetRainGrid(nullptr);after.SetRainGrid(nullptr);before.SetHeadlights({});after.SetHeadlights({});DebugMessages(gpu);
76 }
77}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
Definition grid.h:14
char cube
Definition grid.h:45
CloudWeather::Frame weather
Definition CloudVolume.h:35
CloudBaseWeather::Frame localBase
Definition CloudVolume.h:36