Merge remote-tracking branch 'origin/graphics' into parity-base

This commit is contained in:
Ludovic Marie
2026-10-13 18:55:46 +02:00
42 changed files with 6006 additions and 486 deletions
+546
View File
@@ -0,0 +1,546 @@
{
"label": "after-4080",
"date": "2026-10-13",
"commit": "9006566b",
"host": "ludodesktop",
"offscreen": true,
"seed": "1234",
"flight_seconds": 12.0,
"scenes": {
"village": {
"from": [
-960.0,
125.0,
80.0
],
"to": [
-960.0,
125.0,
272.0
],
"pitch": 35.0
},
"forest": {
"from": [
-1100.0,
120.0,
-560.0
],
"to": [
-1100.0,
120.0,
-368.0
],
"pitch": 25.0
},
"ocean": {
"from": [
-300.0,
85.0,
-420.0
],
"to": [
-300.0,
85.0,
-228.0
],
"pitch": 10.0
},
"mountain": {
"from": [
560.0,
260.0,
860.0
],
"to": [
752.0,
260.0,
860.0
],
"pitch": 30.0
}
},
"distances": {
"8": {
"renderer": {
"backend": "Vulkan",
"drawn_sections": 133,
"gpu": "NVIDIA GeForce RTX 4080",
"present_mode": "Immediate",
"size": [
1280,
720
],
"uploaded_bytes": 941908352
},
"village": {
"avg_fps": 2409.179688612205,
"cpu": {
"avg_ms": 0.41004928978864236,
"max_ms": 18.15971565246582,
"p50_ms": 0.2718150019645691,
"p95_ms": 0.7112299799919128,
"p99_ms": 1.316559076309204
},
"frames": 28910,
"gpu": {
"avg_ms": 0.09866036293994015,
"max_ms": 0.25088000297546387,
"p50_ms": 0.08806400001049042,
"p95_ms": 0.1740799993276596,
"p99_ms": 0.19968000054359436
},
"low_1pct_fps": 160.80638022914025,
"max_ms": 18.175312042236328,
"p50_ms": 0.2760099768638611,
"p95_ms": 0.7161250114440918,
"p99_ms": 1.4078609943389893,
"phases_avg_ms": {
"prepare": 0.20953580908804606,
"render": 0.12439006986512069,
"tick": 0.05299293669455945,
"update": 0.023244019639293335
},
"seconds": 11.999935138359666,
"slow_phases_avg_ms": {
"prepare": 0.4052206484151298,
"render": 0.41893499056840766,
"tick": 5.252727109792939,
"update": 0.0936474929949076
}
},
"forest": {
"avg_fps": 1099.4635681039538,
"cpu": {
"avg_ms": 0.9003613499442573,
"max_ms": 23.31729507446289,
"p50_ms": 0.6657320261001587,
"p95_ms": 0.9898859858512878,
"p99_ms": 9.592857360839844
},
"frames": 13194,
"gpu": {
"avg_ms": 0.2639814413552015,
"max_ms": 3.0013439655303955,
"p50_ms": 0.2549760043621063,
"p95_ms": 0.3553279936313629,
"p99_ms": 0.37171199917793274
},
"low_1pct_fps": 82.87026130908886,
"max_ms": 27.990703582763672,
"p50_ms": 0.6705269813537598,
"p95_ms": 1.0082690715789795,
"p99_ms": 9.64776611328125,
"phases_avg_ms": {
"prepare": 0.571024256178027,
"render": 0.12442494783992657,
"tick": 0.1706307831885292,
"update": 0.03442592136820218
},
"seconds": 12.000397632777691,
"slow_phases_avg_ms": {
"prepare": 0.7136096191225629,
"render": 0.43175565880356415,
"tick": 10.713303016893791,
"update": 0.05390534066651581
}
},
"ocean": {
"avg_fps": 687.0806476294383,
"cpu": {
"avg_ms": 1.4490217101725757,
"max_ms": 29.75178337097168,
"p50_ms": 0.9425880312919617,
"p95_ms": 1.6511069536209106,
"p99_ms": 15.603099822998047
},
"frames": 8245,
"gpu": {
"avg_ms": 0.3711021953564546,
"max_ms": 1.5022079944610596,
"p50_ms": 0.3665919899940491,
"p95_ms": 0.43827199935913086,
"p99_ms": 0.4679679870605469
},
"low_1pct_fps": 47.486143092805435,
"max_ms": 29.770263671875,
"p50_ms": 0.947784960269928,
"p95_ms": 1.6628600358963013,
"p99_ms": 15.621638298034668,
"phases_avg_ms": {
"prepare": 0.8449565766073126,
"render": 0.1554101111230668,
"tick": 0.3840128544967872,
"update": 0.06481705411812297
},
"seconds": 12.000046906352043,
"slow_phases_avg_ms": {
"prepare": 1.2885668083845851,
"render": 0.45316039797771407,
"tick": 19.216593845781073,
"update": 0.08380924088947744
}
},
"mountain": {
"avg_fps": 343.77852072094186,
"cpu": {
"avg_ms": 1.5961282111390964,
"max_ms": 22.24184799194336,
"p50_ms": 0.8254669904708862,
"p95_ms": 11.660508155822754,
"p99_ms": 14.398658752441406
},
"frames": 4113,
"gpu": {
"avg_ms": 0.3449904050323872,
"max_ms": 2.9040639400482178,
"p50_ms": 0.3338240087032318,
"p95_ms": 0.43724799156188965,
"p99_ms": 0.5171200037002563
},
"low_1pct_fps": 29.95597087331344,
"max_ms": 33.422760009765625,
"p50_ms": 0.8299460411071777,
"p95_ms": 33.33942413330078,
"p99_ms": 33.37727355957031,
"phases_avg_ms": {
"prepare": 0.7147062004496516,
"render": 0.14707977256612884,
"tick": 0.6855548198381525,
"update": 0.04897363143349227
},
"seconds": 11.96409825539589,
"slow_phases_avg_ms": {
"prepare": 0.8949875491006034,
"render": 0.6183000469491595,
"tick": 14.63794419879005,
"update": 0.8699657806594457
}
}
},
"16": {
"renderer": {
"backend": "Vulkan",
"drawn_sections": 0,
"gpu": "NVIDIA GeForce RTX 4080",
"present_mode": "Immediate",
"size": [
1280,
720
],
"uploaded_bytes": 16462208
},
"village": {
"avg_fps": 1041.3622747953375,
"cpu": {
"avg_ms": 0.9549695556642304,
"max_ms": 26.009796142578125,
"p50_ms": 0.4810290038585663,
"p95_ms": 2.5506999492645264,
"p99_ms": 9.879941940307617
},
"frames": 12496,
"gpu": {
"avg_ms": 0.22781361336253403,
"max_ms": 1.7469439506530762,
"p50_ms": 0.18534399569034576,
"p95_ms": 0.6113280057907104,
"p99_ms": 0.809984028339386
},
"low_1pct_fps": 64.04348583959742,
"max_ms": 26.032779693603516,
"p50_ms": 0.48582199215888977,
"p95_ms": 2.5584940910339355,
"p99_ms": 9.892412185668945,
"phases_avg_ms": {
"prepare": 0.37678885421859964,
"render": 0.3450905326050295,
"tick": 0.1742891420732452,
"update": 0.0590072420405441
},
"seconds": 11.999666496902703,
"slow_phases_avg_ms": {
"prepare": 1.4649118003845214,
"render": 1.1414484503269196,
"tick": 12.881806396484375,
"update": 0.11011978423595428
}
},
"forest": {
"avg_fps": 316.2068527731055,
"cpu": {
"avg_ms": 3.154168446387541,
"max_ms": 26.147607803344727,
"p50_ms": 2.2156569957733154,
"p95_ms": 12.254712104797363,
"p99_ms": 17.7707462310791
},
"frames": 3795,
"gpu": {
"avg_ms": 0.7502970771905776,
"max_ms": 2.599936008453369,
"p50_ms": 0.7239680290222168,
"p95_ms": 1.3158400058746338,
"p99_ms": 1.3772799968719482
},
"low_1pct_fps": 49.59272936233826,
"max_ms": 26.164094924926758,
"p50_ms": 2.222438097000122,
"p95_ms": 12.270298957824707,
"p99_ms": 17.786956787109375,
"phases_avg_ms": {
"prepare": 1.5666706890613822,
"render": 0.7056146899387927,
"tick": 0.7469899302897249,
"update": 0.13521884845002838
},
"seconds": 12.001637430429458,
"slow_phases_avg_ms": {
"prepare": 1.9408628783727948,
"render": 1.194917630208166,
"tick": 16.762235842253034,
"update": 0.24904731876756014
}
},
"ocean": {
"avg_fps": 385.09978163469907,
"cpu": {
"avg_ms": 2.589322079316407,
"max_ms": 18.984909057617188,
"p50_ms": 2.0551369190216064,
"p95_ms": 8.740593910217285,
"p99_ms": 11.559625625610352
},
"frames": 4622,
"gpu": {
"avg_ms": 0.6778284030938654,
"max_ms": 2.398207902908325,
"p50_ms": 0.7833600044250488,
"p95_ms": 0.9431040287017822,
"p99_ms": 1.511423945426941
},
"low_1pct_fps": 71.97424221133898,
"max_ms": 19.0070858001709,
"p50_ms": 2.061105966567993,
"p95_ms": 8.753417015075684,
"p99_ms": 11.577004432678223,
"phases_avg_ms": {
"prepare": 1.3568510900633204,
"render": 0.7359144338432817,
"tick": 0.41578289517198963,
"update": 0.0810434000275639
},
"seconds": 12.002084188103677,
"slow_phases_avg_ms": {
"prepare": 1.6523635336693296,
"render": 1.2426407299143203,
"tick": 10.818658037388579,
"update": 0.16372418847489864
}
},
"mountain": {
"avg_fps": 219.70895893367268,
"cpu": {
"avg_ms": 3.098228604710274,
"max_ms": 23.518693923950195,
"p50_ms": 2.0422279834747314,
"p95_ms": 10.511551856994629,
"p99_ms": 16.436803817749023
},
"frames": 2634,
"gpu": {
"avg_ms": 0.9377313036310374,
"max_ms": 9.588735580444336,
"p50_ms": 0.8488960266113281,
"p95_ms": 0.9728000164031982,
"p99_ms": 3.4201600551605225
},
"low_1pct_fps": 29.957383952355947,
"max_ms": 33.38852310180664,
"p50_ms": 2.0481808185577393,
"p95_ms": 33.341556549072266,
"p99_ms": 33.377445220947266,
"phases_avg_ms": {
"prepare": 1.3405477057013806,
"render": 0.8202416233113071,
"tick": 0.8190081106798682,
"update": 0.11872799601335143
},
"seconds": 11.988587141752243,
"slow_phases_avg_ms": {
"prepare": 1.648652986243919,
"render": 1.7585702317732352,
"tick": 14.372832368921351,
"update": 1.0560209235107456
}
}
},
"32": {
"renderer": {
"backend": "Vulkan",
"drawn_sections": 212,
"gpu": "NVIDIA GeForce RTX 4080",
"present_mode": "Immediate",
"size": [
1280,
720
],
"uploaded_bytes": 255897088
},
"village": {
"avg_fps": 48.3055081533635,
"cpu": {
"avg_ms": 9.376506657416572,
"max_ms": 861.2249145507812,
"p50_ms": 3.0502548217773438,
"p95_ms": 32.94725036621094,
"p99_ms": 74.04153442382812
},
"frames": 1271,
"gpu": {
"avg_ms": 1.7700931664342303,
"max_ms": 20.69094467163086,
"p50_ms": 1.2410880327224731,
"p95_ms": 7.598080158233643,
"p99_ms": 15.925248146057129
},
"low_1pct_fps": 0.761712600806078,
"max_ms": 14330.3583984375,
"p50_ms": 3.071429967880249,
"p95_ms": 33.099002838134766,
"p99_ms": 75.7547378540039,
"phases_avg_ms": {
"prepare": 1.518610580008767,
"render": 1.6828305973582713,
"tick": 5.15484752775804,
"update": 1.020680267595335
},
"seconds": 26.31169919514656,
"slow_phases_avg_ms": {
"prepare": 0.9654910931220422,
"render": 3.5708756630237284,
"tick": 196.6683132465069,
"update": 14.971596607795128
}
},
"forest": {
"avg_fps": 27.53318156189366,
"cpu": {
"avg_ms": 40.13187835841161,
"max_ms": 1166.3994140625,
"p50_ms": 6.5535569190979,
"p95_ms": 63.877315521240234,
"p99_ms": 1108.11865234375
},
"frames": 271,
"gpu": {
"avg_ms": 2.297342118961785,
"max_ms": 22.554624557495117,
"p50_ms": 0.7065600156784058,
"p95_ms": 7.245823860168457,
"p99_ms": 9.055232048034668
},
"low_1pct_fps": 0.8848759980013957,
"max_ms": 1166.4168701171875,
"p50_ms": 6.675865173339844,
"p95_ms": 59.150550842285156,
"p99_ms": 1108.134521484375,
"phases_avg_ms": {
"prepare": 2.83869483858017,
"render": 2.5961379855321343,
"tick": 33.04425997872419,
"update": 1.6535338119387186
},
"seconds": 9.842669267654419,
"slow_phases_avg_ms": {
"prepare": 2.766425689061483,
"render": 4.919464270273845,
"tick": 1112.3431803385417,
"update": 10.057182629903158
}
},
"ocean": {
"avg_fps": 67.01857611699128,
"cpu": {
"avg_ms": 14.669945189483148,
"max_ms": 113.66764068603516,
"p50_ms": 4.473541736602783,
"p95_ms": 51.374263763427734,
"p99_ms": 94.75230407714844
},
"frames": 802,
"gpu": {
"avg_ms": 2.9074973299021734,
"max_ms": 22.526975631713867,
"p50_ms": 1.8206720352172852,
"p95_ms": 8.869888305664062,
"p99_ms": 11.596799850463867
},
"low_1pct_fps": 10.111656570136391,
"max_ms": 113.68443298339844,
"p50_ms": 4.488469123840332,
"p95_ms": 51.39033508300781,
"p99_ms": 94.76870727539062,
"phases_avg_ms": {
"prepare": 2.4291724538862556,
"render": 2.242118674918006,
"tick": 9.334139847333992,
"update": 0.6651962902814967
},
"seconds": 11.966831384181976,
"slow_phases_avg_ms": {
"prepare": 2.7512698968251548,
"render": 3.2687110900878906,
"tick": 90.47323608398438,
"update": 2.3865103986528187
}
},
"mountain": {
"avg_fps": 28.70327462003782,
"cpu": {
"avg_ms": 16.062305691622306,
"max_ms": 67.72319793701172,
"p50_ms": 10.215509414672852,
"p95_ms": 45.747154235839844,
"p99_ms": 63.64399337768555
},
"frames": 345,
"gpu": {
"avg_ms": 8.470281650363535,
"max_ms": 21.519359588623047,
"p50_ms": 8.845312118530273,
"p95_ms": 15.868927955627441,
"p99_ms": 17.557504653930664
},
"low_1pct_fps": 15.182693348952107,
"max_ms": 67.74352264404297,
"p50_ms": 33.36533737182617,
"p95_ms": 46.64082336425781,
"p99_ms": 63.65925979614258,
"phases_avg_ms": {
"prepare": 0.8729904708654984,
"render": 3.4296869785889337,
"tick": 8.941314909811826,
"update": 2.8190046198558116
},
"seconds": 12.01953451538086,
"slow_phases_avg_ms": {
"prepare": 0.8918330073356628,
"render": 4.432150959968567,
"tick": 50.667978286743164,
"update": 9.854933142662048
}
}
}
},
"load_before": [
1.86328125,
2.111328125,
3.9072265625
],
"load_after": [
8.4560546875,
5.08544921875,
4.68798828125
]
}
+546
View File
@@ -0,0 +1,546 @@
{
"label": "after-lavapipe",
"date": "2026-10-13",
"commit": "9006566b",
"host": "ludodesktop",
"offscreen": false,
"seed": "1234",
"flight_seconds": 12.0,
"scenes": {
"village": {
"from": [
-960.0,
125.0,
80.0
],
"to": [
-960.0,
125.0,
272.0
],
"pitch": 35.0
},
"forest": {
"from": [
-1100.0,
120.0,
-560.0
],
"to": [
-1100.0,
120.0,
-368.0
],
"pitch": 25.0
},
"ocean": {
"from": [
-300.0,
85.0,
-420.0
],
"to": [
-300.0,
85.0,
-228.0
],
"pitch": 10.0
},
"mountain": {
"from": [
560.0,
260.0,
860.0
],
"to": [
752.0,
260.0,
860.0
],
"pitch": 30.0
}
},
"distances": {
"8": {
"renderer": {
"backend": "Vulkan",
"drawn_sections": 156,
"gpu": "llvmpipe (LLVM 21.1.8, 256 bits)",
"present_mode": "Mailbox",
"size": [
1600,
1000
],
"uploaded_bytes": 1278284288
},
"village": {
"avg_fps": 58.3354572261441,
"cpu": {
"avg_ms": 11.363309368576322,
"max_ms": 36.24496841430664,
"p50_ms": 13.213258743286133,
"p95_ms": 19.535802841186523,
"p99_ms": 24.83148956298828
},
"frames": 700,
"gpu": {
"avg_ms": 13.518205827985492,
"max_ms": 34.97639083862305,
"p50_ms": 13.195829391479492,
"p95_ms": 18.039182662963867,
"p99_ms": 23.378856658935547
},
"low_1pct_fps": 31.312386939419746,
"max_ms": 36.36259078979492,
"p50_ms": 16.02706527709961,
"p95_ms": 21.249738693237305,
"p99_ms": 29.130090713500977,
"phases_avg_ms": {
"prepare": 0.2306461141364915,
"render": 9.720663217795746,
"tick": 1.3112367039202113,
"update": 0.10169148096282567
},
"seconds": 11.99956310081482,
"slow_phases_avg_ms": {
"prepare": 0.35282185673713684,
"render": 25.05345916748047,
"tick": 3.1022580585309436,
"update": 0.38026727948869976
}
},
"forest": {
"avg_fps": 41.90001789962103,
"cpu": {
"avg_ms": 18.045572770611635,
"max_ms": 36.546627044677734,
"p50_ms": 20.543725967407227,
"p95_ms": 30.5231990814209,
"p99_ms": 34.017364501953125
},
"frames": 504,
"gpu": {
"avg_ms": 21.35815803588383,
"max_ms": 36.23066329956055,
"p50_ms": 19.825437545776367,
"p95_ms": 29.274858474731445,
"p99_ms": 33.32203674316406
},
"low_1pct_fps": 20.022920779459263,
"max_ms": 99.08029174804688,
"p50_ms": 22.576229095458984,
"p95_ms": 32.772239685058594,
"p99_ms": 36.67753982543945,
"phases_avg_ms": {
"prepare": 0.22351377572686898,
"render": 16.234788014183916,
"tick": 1.4387834655649459,
"update": 0.14943464463281017
},
"seconds": 12.028634479522704,
"slow_phases_avg_ms": {
"prepare": 0.2705736731489499,
"render": 32.015567461649574,
"tick": 2.741411516830946,
"update": 0.3076988315830628
}
},
"ocean": {
"avg_fps": 60.413862302111134,
"cpu": {
"avg_ms": 10.874024665643429,
"max_ms": 29.430055618286133,
"p50_ms": 12.944002151489258,
"p95_ms": 17.997587203979492,
"p99_ms": 25.568126678466797
},
"frames": 725,
"gpu": {
"avg_ms": 12.736994123787715,
"max_ms": 28.143625259399414,
"p50_ms": 12.234904289245605,
"p95_ms": 15.61594295501709,
"p99_ms": 24.476089477539062
},
"low_1pct_fps": 34.82401357005238,
"max_ms": 33.36631393432617,
"p50_ms": 16.01299476623535,
"p95_ms": 18.74709701538086,
"p99_ms": 26.6020565032959,
"phases_avg_ms": {
"prepare": 0.4042872669162421,
"render": 9.401332649341946,
"tick": 0.9126873913477977,
"update": 0.15663292961387798
},
"seconds": 12.000557030677795,
"slow_phases_avg_ms": {
"prepare": 0.3962315060198307,
"render": 26.506223678588867,
"tick": 0.0020812499860767275,
"update": 0.5454612672328949
}
},
"mountain": {
"avg_fps": 37.77761368324693,
"cpu": {
"avg_ms": 11.491443304826092,
"max_ms": 34.474151611328125,
"p50_ms": 13.871685981750488,
"p95_ms": 20.351163864135742,
"p99_ms": 23.77434539794922
},
"frames": 453,
"gpu": {
"avg_ms": 14.109076927302953,
"max_ms": 35.115882873535156,
"p50_ms": 13.555350303649902,
"p95_ms": 18.336809158325195,
"p99_ms": 30.865131378173828
},
"low_1pct_fps": 27.343844611059406,
"max_ms": 39.0676155090332,
"p50_ms": 33.33863830566406,
"p95_ms": 33.36062240600586,
"p99_ms": 34.297752380371094,
"phases_avg_ms": {
"prepare": 0.22927819613457778,
"render": 9.350584785242217,
"tick": 1.7383085893987211,
"update": 0.17420387428015405
},
"seconds": 11.991228556632995,
"slow_phases_avg_ms": {
"prepare": 0.2908208012580872,
"render": 25.648976135253907,
"tick": 1.9043863375205548,
"update": 0.7624145835638046
}
}
},
"16": {
"renderer": {
"backend": "Vulkan",
"drawn_sections": 0,
"gpu": "llvmpipe (LLVM 21.1.8, 256 bits)",
"present_mode": "Mailbox",
"size": [
1600,
1000
],
"uploaded_bytes": 36807552
},
"village": {
"avg_fps": 20.701493975921895,
"cpu": {
"avg_ms": 31.808356682459515,
"max_ms": 74.47195434570312,
"p50_ms": 41.86561584472656,
"p95_ms": 56.75548553466797,
"p99_ms": 73.00084686279297
},
"frames": 249,
"gpu": {
"avg_ms": 40.500388481140135,
"max_ms": 67.22461700439453,
"p50_ms": 40.38219451904297,
"p95_ms": 50.01243209838867,
"p99_ms": 62.00723648071289
},
"low_1pct_fps": 8.83914293384798,
"max_ms": 133.2972869873047,
"p50_ms": 47.37559509277344,
"p95_ms": 61.3382682800293,
"p99_ms": 74.61792755126953,
"phases_avg_ms": {
"prepare": 0.30830518620081215,
"render": 25.584145257750667,
"tick": 5.116575629957185,
"update": 0.8002672145165592
},
"seconds": 12.028117404937744,
"slow_phases_avg_ms": {
"prepare": 0.3641819953918457,
"render": 44.77838750680288,
"tick": 6.285618623097737,
"update": 22.415442685286205
}
},
"forest": {
"avg_fps": 18.118065350089793,
"cpu": {
"avg_ms": 36.827518428137545,
"max_ms": 85.7597427368164,
"p50_ms": 49.536197662353516,
"p95_ms": 62.31198501586914,
"p99_ms": 66.591064453125
},
"frames": 218,
"gpu": {
"avg_ms": 47.82228247616269,
"max_ms": 76.9173355102539,
"p50_ms": 46.98957824707031,
"p95_ms": 57.49673843383789,
"p99_ms": 69.92066192626953
},
"low_1pct_fps": 11.528998473378772,
"max_ms": 93.62928009033203,
"p50_ms": 53.71598434448242,
"p95_ms": 66.69908905029297,
"p99_ms": 80.71000671386719,
"phases_avg_ms": {
"prepare": 0.29564340877423595,
"render": 30.678313442326466,
"tick": 4.647872053591402,
"update": 1.206680115073099
},
"seconds": 12.032189739227295,
"slow_phases_avg_ms": {
"prepare": 0.37793900569279987,
"render": 66.15962092081706,
"tick": 5.583541075388591,
"update": 1.5741689602533977
}
},
"ocean": {
"avg_fps": 8.272097120557788,
"cpu": {
"avg_ms": 96.70907358733974,
"max_ms": 208.84027099609375,
"p50_ms": 89.04510498046875,
"p95_ms": 169.3397979736328,
"p99_ms": 208.84027099609375
},
"frames": 98,
"gpu": {
"avg_ms": 57.298700176939676,
"max_ms": 66.62165832519531,
"p50_ms": 57.89077377319336,
"p95_ms": 65.73504638671875,
"p99_ms": 66.62165832519531
},
"low_1pct_fps": 4.785729156618201,
"max_ms": 208.95457458496094,
"p50_ms": 140.0601348876953,
"p95_ms": 178.57022094726562,
"p99_ms": 208.95457458496094,
"phases_avg_ms": {
"prepare": 3.3946731230434106,
"render": 34.994675042982,
"tick": 57.14290783599932,
"update": 1.177816742536973
},
"seconds": 11.847056262969971,
"slow_phases_avg_ms": {
"prepare": 7.7776899337768555,
"render": 70.36097717285156,
"tick": 128.46734619140625,
"update": 2.2351090908050537
}
},
"mountain": {
"avg_fps": 11.65883600782651,
"cpu": {
"avg_ms": 56.6912090659987,
"max_ms": 107.11215209960938,
"p50_ms": 77.04230499267578,
"p95_ms": 97.60908508300781,
"p99_ms": 104.08527374267578
},
"frames": 141,
"gpu": {
"avg_ms": 70.81221792731486,
"max_ms": 96.33728790283203,
"p50_ms": 69.16046905517578,
"p95_ms": 86.61634063720703,
"p99_ms": 92.56858825683594
},
"low_1pct_fps": 4.93309783391495,
"max_ms": 216.64273071289062,
"p50_ms": 81.59197235107422,
"p95_ms": 104.20377349853516,
"p99_ms": 188.7820281982422,
"phases_avg_ms": {
"prepare": 0.31791428133105554,
"render": 45.35119773817401,
"tick": 9.391353438086544,
"update": 1.6317692605104852
},
"seconds": 12.093831657409668,
"slow_phases_avg_ms": {
"prepare": 0.348672017455101,
"render": 86.63534545898438,
"tick": 13.065274715423584,
"update": 5.5503233671188354
}
}
},
"32": {
"renderer": {
"backend": "Vulkan",
"drawn_sections": 119,
"gpu": "llvmpipe (LLVM 21.1.8, 256 bits)",
"present_mode": "Mailbox",
"size": [
1600,
1000
],
"uploaded_bytes": 222619264
},
"village": {
"avg_fps": 5.310476400246329,
"cpu": {
"avg_ms": 111.2176975607872,
"max_ms": 224.16696166992188,
"p50_ms": 76.4469985961914,
"p95_ms": 218.82273864746094,
"p99_ms": 224.16696166992188
},
"frames": 64,
"gpu": {
"avg_ms": 121.35315322875977,
"max_ms": 171.11207580566406,
"p50_ms": 125.45780944824219,
"p95_ms": 166.71322631835938,
"p99_ms": 171.11207580566406
},
"low_1pct_fps": 3.59762228435401,
"max_ms": 277.96136474609375,
"p50_ms": 192.1078338623047,
"p95_ms": 232.86318969726562,
"p99_ms": 277.96136474609375,
"phases_avg_ms": {
"prepare": 0.524940284434706,
"render": 56.89460512250662,
"tick": 38.0364211499691,
"update": 15.762759290635586
},
"seconds": 12.051649452209473,
"slow_phases_avg_ms": {
"prepare": 0.5129500031471252,
"render": 147.3928985595703,
"tick": 62.813438415527344,
"update": 13.448556900024414
}
},
"forest": {
"avg_fps": 3.899515654388116,
"cpu": {
"avg_ms": 155.46855975211935,
"max_ms": 270.7467041015625,
"p50_ms": 83.60679626464844,
"p95_ms": 268.6576843261719,
"p99_ms": 270.7467041015625
},
"frames": 47,
"gpu": {
"avg_ms": 192.77972445280656,
"max_ms": 225.69723510742188,
"p50_ms": 189.4962615966797,
"p95_ms": 217.36190795898438,
"p99_ms": 225.69723510742188
},
"low_1pct_fps": 3.3773198460417087,
"max_ms": 296.0927734375,
"p50_ms": 259.49017333984375,
"p95_ms": 283.4007568359375,
"p99_ms": 296.0927734375,
"phases_avg_ms": {
"prepare": 0.5114446409205173,
"render": 99.58217374821926,
"tick": 43.03971359577585,
"update": 12.336258025879555
},
"seconds": 12.052778900146484,
"slow_phases_avg_ms": {
"prepare": 0.5626839995384216,
"render": 208.71124267578125,
"tick": 53.47932052612305,
"update": 7.994467258453369
}
},
"ocean": {
"avg_fps": 2.9455219461811217,
"cpu": {
"avg_ms": 287.98993862376494,
"max_ms": 464.7646484375,
"p50_ms": 286.4447326660156,
"p95_ms": 444.6121520996094,
"p99_ms": 464.7646484375
},
"frames": 34,
"gpu": {
"avg_ms": 116.96576734270369,
"max_ms": 158.26394653320312,
"p50_ms": 106.45819854736328,
"p95_ms": 158.1454620361328,
"p99_ms": 158.26394653320312
},
"low_1pct_fps": 2.151113067092828,
"max_ms": 464.8756103515625,
"p50_ms": 315.1367492675781,
"p95_ms": 456.3304138183594,
"p99_ms": 464.8756103515625,
"phases_avg_ms": {
"prepare": 4.395756518139558,
"render": 69.52432030789993,
"tick": 206.13154108384077,
"update": 7.93927874284632
},
"seconds": 11.542945739746093,
"slow_phases_avg_ms": {
"prepare": 4.144052982330322,
"render": 166.14959716796875,
"tick": 285.5132751464844,
"update": 8.958683967590332
}
},
"mountain": {
"avg_fps": 3.983176689759444,
"cpu": {
"avg_ms": 171.41208145466257,
"max_ms": 413.8367919921875,
"p50_ms": 164.3318328857422,
"p95_ms": 360.7731628417969,
"p99_ms": 413.8367919921875
},
"frames": 47,
"gpu": {
"avg_ms": 166.80018520355225,
"max_ms": 304.8785400390625,
"p50_ms": 143.19728088378906,
"p95_ms": 275.3953552246094,
"p99_ms": 304.8785400390625
},
"low_1pct_fps": 2.418344167836982,
"max_ms": 413.5060729980469,
"p50_ms": 230.7030029296875,
"p95_ms": 365.4028625488281,
"p99_ms": 413.5060729980469,
"phases_avg_ms": {
"prepare": 0.496992789684458,
"render": 94.4349257743105,
"tick": 61.33542941478973,
"update": 15.14569672117842
},
"seconds": 11.799627197265625,
"slow_phases_avg_ms": {
"prepare": 0.4748440086841583,
"render": 312.3215637207031,
"tick": 86.37409973144531,
"update": 14.667168617248535
}
}
}
},
"load_before": [
8.4560546875,
5.08544921875,
4.68798828125
],
"load_after": [
10.98291015625,
7.201171875,
5.5615234375
]
}
+392
View File
@@ -0,0 +1,392 @@
{
"label": "baseline-4080",
"date": "2026-10-13",
"commit": "27a32cc3",
"host": "ludodesktop",
"offscreen": true,
"seed": "1234",
"flight_seconds": 12.0,
"scenes": {
"village": {
"from": [
-960.0,
125.0,
80.0
],
"to": [
-960.0,
125.0,
272.0
],
"pitch": 35.0
},
"forest": {
"from": [
-1100.0,
120.0,
-560.0
],
"to": [
-1100.0,
120.0,
-368.0
],
"pitch": 25.0
},
"ocean": {
"from": [
-300.0,
85.0,
-420.0
],
"to": [
-300.0,
85.0,
-228.0
],
"pitch": 10.0
},
"mountain": {
"from": [
560.0,
260.0,
860.0
],
"to": [
752.0,
260.0,
860.0
],
"pitch": 30.0
}
},
"distances": {
"8": {
"renderer": {
"backend": "Vulkan",
"drawn_sections": 158,
"gpu": "NVIDIA GeForce RTX 4080",
"present_mode": "Immediate",
"size": [
1280,
720
],
"uploaded_bytes": 1137747200
},
"village": {
"avg_fps": 362.94072531330323,
"cpu": {
"avg_ms": 2.734311161203731,
"max_ms": 68.06377410888672,
"p50_ms": 1.4820960760116577,
"p95_ms": 7.922675609588623,
"p99_ms": 35.78989028930664
},
"frames": 4373,
"gpu": {
"avg_ms": 0.4188921034758625,
"max_ms": 2.5876479148864746,
"p50_ms": 0.4106239974498749,
"p95_ms": 0.5283839702606201,
"p99_ms": 0.5427200198173523
},
"low_1pct_fps": 21.64332698060583,
"max_ms": 68.08219146728516,
"p50_ms": 1.4894599914550781,
"p95_ms": 7.936410427093506,
"p99_ms": 36.54151153564453,
"seconds": 12.048799418210983
},
"forest": {
"avg_fps": 613.1553113846195,
"cpu": {
"avg_ms": 1.6186122214214547,
"max_ms": 216.98960876464844,
"p50_ms": 1.10076105594635,
"p95_ms": 3.0016868114471436,
"p99_ms": 10.144570350646973
},
"frames": 6746,
"gpu": {
"avg_ms": 0.395751640401594,
"max_ms": 1.99782395362854,
"p50_ms": 0.3983359932899475,
"p95_ms": 0.4833280146121979,
"p99_ms": 0.5375999808311462
},
"low_1pct_fps": 49.639170314777054,
"max_ms": 217.0211181640625,
"p50_ms": 1.109616994857788,
"p95_ms": 3.0161218643188477,
"p99_ms": 10.163111686706543,
"seconds": 11.002106439828873
},
"ocean": {
"avg_fps": 323.23791637473414,
"cpu": {
"avg_ms": 2.7230400277200597,
"max_ms": 4748.7744140625,
"p50_ms": 0.9233829975128174,
"p95_ms": 1.677724003791809,
"p99_ms": 7.7397589683532715
},
"frames": 3870,
"gpu": {
"avg_ms": 0.24116999250656182,
"max_ms": 0.954367995262146,
"p50_ms": 0.2754560112953186,
"p95_ms": 0.3389439880847931,
"p99_ms": 0.3532800078392029
},
"low_1pct_fps": 5.421154869716093,
"max_ms": 4748.80615234375,
"p50_ms": 0.9285120368003845,
"p95_ms": 1.7079449892044067,
"p99_ms": 33.33257293701172,
"seconds": 11.97260532861948
},
"mountain": {
"avg_fps": 28.19080143244723,
"cpu": {
"avg_ms": 12.358911560308298,
"max_ms": 187.3409881591797,
"p50_ms": 9.513923645019531,
"p95_ms": 25.783824920654297,
"p99_ms": 110.71585845947266
},
"frames": 338,
"gpu": {
"avg_ms": 0.46002139662497143,
"max_ms": 1.5626239776611328,
"p50_ms": 0.4546560049057007,
"p95_ms": 0.5140479803085327,
"p99_ms": 0.5959680080413818
},
"low_1pct_fps": 7.428141780247131,
"max_ms": 187.36033630371094,
"p50_ms": 33.334835052490234,
"p95_ms": 35.65903854370117,
"p99_ms": 110.73509216308594,
"seconds": 11.98972653579712
}
},
"16": {
"renderer": {
"backend": "Vulkan",
"drawn_sections": 1,
"gpu": "NVIDIA GeForce RTX 4080",
"present_mode": "Immediate",
"size": [
1280,
720
],
"uploaded_bytes": 54284928
},
"village": {
"avg_fps": 7.569165639843409,
"cpu": {
"avg_ms": 138.25648041658624,
"max_ms": 877.6473999023438,
"p50_ms": 103.97663879394531,
"p95_ms": 318.5262145996094,
"p99_ms": 877.6473999023438
},
"frames": 86,
"gpu": {
"avg_ms": 3.585262137790059,
"max_ms": 8.415231704711914,
"p50_ms": 3.299328088760376,
"p95_ms": 7.171072006225586,
"p99_ms": 8.415231704711914
},
"low_1pct_fps": 2.44461512120682,
"max_ms": 409.0623474121094,
"p50_ms": 104.01687622070312,
"p95_ms": 318.5569763183594,
"p99_ms": 409.0623474121094,
"seconds": 11.361886381149292
},
"forest": {
"avg_fps": 27.65529078792617,
"cpu": {
"avg_ms": 37.926895780927815,
"max_ms": 3484.08349609375,
"p50_ms": 3.398620128631592,
"p95_ms": 44.56385040283203,
"p99_ms": 684.4393920898438
},
"frames": 314,
"gpu": {
"avg_ms": 2.683724634467986,
"max_ms": 9.881600379943848,
"p50_ms": 1.8923519849777222,
"p95_ms": 7.221248149871826,
"p99_ms": 9.04089641571045
},
"low_1pct_fps": 0.4753349245465373,
"max_ms": 3484.115234375,
"p50_ms": 3.5420219898223877,
"p95_ms": 44.591251373291016,
"p99_ms": 159.3817901611328,
"seconds": 11.354066113710404
},
"ocean": {
"avg_fps": 59.16125632179682,
"cpu": {
"avg_ms": 16.807428855239674,
"max_ms": 106.0348129272461,
"p50_ms": 9.335607528686523,
"p95_ms": 44.57380294799805,
"p99_ms": 84.97154998779297
},
"frames": 712,
"gpu": {
"avg_ms": 1.958949391112736,
"max_ms": 8.635392189025879,
"p50_ms": 1.1182080507278442,
"p95_ms": 5.493760108947754,
"p99_ms": 7.108607769012451
},
"low_1pct_fps": 10.542641239411056,
"max_ms": 106.06544494628906,
"p50_ms": 9.364562034606934,
"p95_ms": 45.14366912841797,
"p99_ms": 84.9927749633789,
"seconds": 12.034903317928315
},
"mountain": {
"avg_fps": 26.78175419456072,
"cpu": {
"avg_ms": 20.230309660251326,
"max_ms": 128.05508422851562,
"p50_ms": 15.369550704956055,
"p95_ms": 67.15973663330078,
"p99_ms": 104.6961898803711
},
"frames": 325,
"gpu": {
"avg_ms": 7.143625645270714,
"max_ms": 21.25823974609375,
"p50_ms": 7.187456130981445,
"p95_ms": 12.228608131408691,
"p99_ms": 19.310592651367188
},
"low_1pct_fps": 7.777799947825389,
"max_ms": 155.30685424804688,
"p50_ms": 33.335182189941406,
"p95_ms": 68.94293975830078,
"p99_ms": 109.09304809570312,
"seconds": 12.135127431869506
}
},
"32": {
"renderer": {
"backend": "Vulkan",
"drawn_sections": 0,
"gpu": "NVIDIA GeForce RTX 4080",
"present_mode": "Immediate",
"size": [
1280,
720
],
"uploaded_bytes": 4829184
},
"village": {
"avg_fps": 4.1477100728464,
"cpu": {
"avg_ms": 244.17284844846142,
"max_ms": 386.7664489746094,
"p50_ms": 244.8783416748047,
"p95_ms": 363.0765380859375,
"p99_ms": 386.7664489746094
},
"frames": 49,
"gpu": {
"avg_ms": 10.357822744213806,
"max_ms": 23.010303497314453,
"p50_ms": 9.227264404296875,
"p95_ms": 19.309568405151367,
"p99_ms": 23.010303497314453
},
"low_1pct_fps": 2.5853636290905797,
"max_ms": 386.79278564453125,
"p50_ms": 230.8652801513672,
"p95_ms": 363.0941162109375,
"p99_ms": 386.79278564453125,
"seconds": 11.813747619628906
},
"forest": {
"avg_fps": 8.3624969613463,
"cpu": {
"avg_ms": 118.74922356747165,
"max_ms": 278.8187255859375,
"p50_ms": 123.03407287597656,
"p95_ms": 231.6608123779297,
"p99_ms": 260.8450622558594
},
"frames": 101,
"gpu": {
"avg_ms": 15.898816661669477,
"max_ms": 72.880126953125,
"p50_ms": 20.789247512817383,
"p95_ms": 28.441600799560547,
"p99_ms": 60.816383361816406
},
"low_1pct_fps": 3.7057290596141406,
"max_ms": 278.83917236328125,
"p50_ms": 123.19290161132812,
"p95_ms": 231.68026733398438,
"p99_ms": 260.8656921386719,
"seconds": 12.077732340812684
},
"ocean": {
"avg_fps": 2.3954947141714045,
"cpu": {
"avg_ms": 424.7621285574777,
"max_ms": 625.8532104492188,
"p50_ms": 435.64044189453125,
"p95_ms": 577.7593994140625,
"p99_ms": 625.8532104492188
},
"frames": 28,
"gpu": {
"avg_ms": 9.483117733682905,
"max_ms": 12.973055839538574,
"p50_ms": 9.90719985961914,
"p95_ms": 12.610560417175293,
"p99_ms": 12.973055839538574
},
"low_1pct_fps": 1.5977632874291703,
"max_ms": 625.8749389648438,
"p50_ms": 433.9859619140625,
"p95_ms": 577.7803955078125,
"p99_ms": 625.8749389648438,
"seconds": 11.688608551025391
},
"mountain": {
"avg_fps": 3.3756775332390268,
"cpu": {
"avg_ms": 300.512197249975,
"max_ms": 407.4363708496094,
"p50_ms": 292.483642578125,
"p95_ms": 394.8424377441406,
"p99_ms": 407.4363708496094
},
"frames": 39,
"gpu": {
"avg_ms": 9.728866460995796,
"max_ms": 18.930688858032227,
"p50_ms": 8.820735931396484,
"p95_ms": 17.399808883666992,
"p99_ms": 18.930688858032227
},
"low_1pct_fps": 2.4541792422631716,
"max_ms": 407.46820068359375,
"p50_ms": 292.4177551269531,
"p95_ms": 394.8649597167969,
"p99_ms": 407.46820068359375,
"seconds": 11.553236236572266
}
}
}
}
+392
View File
@@ -0,0 +1,392 @@
{
"label": "baseline-lavapipe",
"date": "2026-10-13",
"commit": "27a32cc3",
"host": "ludodesktop",
"offscreen": false,
"seed": "1234",
"flight_seconds": 12.0,
"scenes": {
"village": {
"from": [
-960.0,
125.0,
80.0
],
"to": [
-960.0,
125.0,
272.0
],
"pitch": 35.0
},
"forest": {
"from": [
-1100.0,
120.0,
-560.0
],
"to": [
-1100.0,
120.0,
-368.0
],
"pitch": 25.0
},
"ocean": {
"from": [
-300.0,
85.0,
-420.0
],
"to": [
-300.0,
85.0,
-228.0
],
"pitch": 10.0
},
"mountain": {
"from": [
560.0,
260.0,
860.0
],
"to": [
752.0,
260.0,
860.0
],
"pitch": 30.0
}
},
"distances": {
"8": {
"renderer": {
"backend": "Vulkan",
"drawn_sections": 146,
"gpu": "llvmpipe (LLVM 21.1.8, 256 bits)",
"present_mode": "Mailbox",
"size": [
1600,
1000
],
"uploaded_bytes": 1288851072
},
"village": {
"avg_fps": 16.38225374384963,
"cpu": {
"avg_ms": 48.17248754105975,
"max_ms": 134.31028747558594,
"p50_ms": 44.57072067260742,
"p95_ms": 97.15985870361328,
"p99_ms": 127.31073760986328
},
"frames": 199,
"gpu": {
"avg_ms": 26.732369270324707,
"max_ms": 47.3107795715332,
"p50_ms": 26.284116744995117,
"p95_ms": 35.006874084472656,
"p99_ms": 39.38005828857422
},
"low_1pct_fps": 6.569673692138871,
"max_ms": 169.97352600097656,
"p50_ms": 56.791988372802734,
"p95_ms": 109.15220642089844,
"p99_ms": 134.45559692382812,
"seconds": 12.147290788650512
},
"forest": {
"avg_fps": 19.917172468484612,
"cpu": {
"avg_ms": 31.039839970568817,
"max_ms": 106.39506530761719,
"p50_ms": 33.26064682006836,
"p95_ms": 70.09876251220703,
"p99_ms": 86.21255493164062
},
"frames": 240,
"gpu": {
"avg_ms": 37.272586759195285,
"max_ms": 77.586669921875,
"p50_ms": 34.38500213623047,
"p95_ms": 59.649635314941406,
"p99_ms": 66.52396392822266
},
"low_1pct_fps": 9.909291086862112,
"max_ms": 106.57542419433594,
"p50_ms": 46.05862808227539,
"p95_ms": 80.38935852050781,
"p99_ms": 94.94140625,
"seconds": 12.049903186798096
},
"ocean": {
"avg_fps": 27.969763129786234,
"cpu": {
"avg_ms": 25.69895526429727,
"max_ms": 930.7354125976562,
"p50_ms": 18.981081008911133,
"p95_ms": 39.42117691040039,
"p99_ms": 168.07225036621094
},
"frames": 336,
"gpu": {
"avg_ms": 18.856842384451912,
"max_ms": 57.835872650146484,
"p50_ms": 18.172868728637695,
"p95_ms": 28.62451171875,
"p99_ms": 44.414398193359375
},
"low_1pct_fps": 1.527565223414601,
"max_ms": 930.8734741210938,
"p50_ms": 26.45800018310547,
"p95_ms": 50.053672790527344,
"p99_ms": 180.92478942871094,
"seconds": 12.012972667694092
},
"mountain": {
"avg_fps": 26.5942562164059,
"cpu": {
"avg_ms": 22.482411369495093,
"max_ms": 104.89199829101562,
"p50_ms": 22.033512115478516,
"p95_ms": 46.385555267333984,
"p99_ms": 61.15697479248047
},
"frames": 320,
"gpu": {
"avg_ms": 23.762589550018312,
"max_ms": 48.10239028930664,
"p50_ms": 22.580347061157227,
"p95_ms": 35.14606475830078,
"p99_ms": 42.47938919067383
},
"low_1pct_fps": 11.197907022053611,
"max_ms": 105.07585906982422,
"p50_ms": 33.362815856933594,
"p95_ms": 53.36695098876953,
"p99_ms": 74.80219268798828,
"seconds": 12.03267342376709
}
},
"16": {
"renderer": {
"backend": "Vulkan",
"drawn_sections": 1,
"gpu": "llvmpipe (LLVM 21.1.8, 256 bits)",
"present_mode": "Mailbox",
"size": [
1600,
1000
],
"uploaded_bytes": 16106880
},
"village": {
"avg_fps": 10.754658718707336,
"cpu": {
"avg_ms": 69.22208800682655,
"max_ms": 193.21267700195312,
"p50_ms": 66.95130157470703,
"p95_ms": 154.44834899902344,
"p99_ms": 191.29208374023438
},
"frames": 130,
"gpu": {
"avg_ms": 49.041961078495945,
"max_ms": 73.83775329589844,
"p50_ms": 48.90928268432617,
"p95_ms": 60.60416793823242,
"p99_ms": 66.1044921875
},
"low_1pct_fps": 4.171866301284614,
"max_ms": 252.21458435058594,
"p50_ms": 79.8940200805664,
"p95_ms": 173.05947875976562,
"p99_ms": 227.18716430664062,
"seconds": 12.087784782409669
},
"forest": {
"avg_fps": 12.167278778001634,
"cpu": {
"avg_ms": 58.366991678873696,
"max_ms": 156.683349609375,
"p50_ms": 69.24014282226562,
"p95_ms": 110.83757019042969,
"p99_ms": 134.16554260253906
},
"frames": 147,
"gpu": {
"avg_ms": 56.45229888606716,
"max_ms": 78.26596069335938,
"p50_ms": 55.92947006225586,
"p95_ms": 63.54412841796875,
"p99_ms": 66.5202407836914
},
"low_1pct_fps": 5.722095670390665,
"max_ms": 212.99729919433594,
"p50_ms": 77.36986541748047,
"p95_ms": 122.84784698486328,
"p99_ms": 136.52499389648438,
"seconds": 12.081583950042724
},
"ocean": {
"avg_fps": 7.681804845753147,
"cpu": {
"avg_ms": 98.35419226740743,
"max_ms": 385.2493591308594,
"p50_ms": 78.85044860839844,
"p95_ms": 225.36231994628906,
"p99_ms": 385.2493591308594
},
"frames": 91,
"gpu": {
"avg_ms": 71.51263585297957,
"max_ms": 128.29212951660156,
"p50_ms": 67.92412567138672,
"p95_ms": 101.93219757080078,
"p99_ms": 128.29212951660156
},
"low_1pct_fps": 2.5948566279945817,
"max_ms": 385.37774658203125,
"p50_ms": 123.91693878173828,
"p95_ms": 225.49420166015625,
"p99_ms": 385.37774658203125,
"seconds": 11.846174411773681
},
"mountain": {
"avg_fps": 5.886844433101332,
"cpu": {
"avg_ms": 124.87309415575484,
"max_ms": 321.2157897949219,
"p50_ms": 117.2811050415039,
"p95_ms": 237.34304809570312,
"p99_ms": 321.2157897949219
},
"frames": 71,
"gpu": {
"avg_ms": 95.46965434816148,
"max_ms": 166.9488067626953,
"p50_ms": 83.54202270507812,
"p95_ms": 160.2403564453125,
"p99_ms": 166.9488067626953
},
"low_1pct_fps": 3.111272818975726,
"max_ms": 321.411865234375,
"p50_ms": 153.0963134765625,
"p95_ms": 275.37579345703125,
"p99_ms": 321.411865234375,
"seconds": 12.060790939331055
}
},
"32": {
"renderer": {
"backend": "Vulkan",
"drawn_sections": 1,
"gpu": "llvmpipe (LLVM 21.1.8, 256 bits)",
"present_mode": "Mailbox",
"size": [
1600,
1000
],
"uploaded_bytes": 19154560
},
"village": {
"avg_fps": 2.5956714101148957,
"cpu": {
"avg_ms": 345.63314671670236,
"max_ms": 474.2013854980469,
"p50_ms": 347.07415771484375,
"p95_ms": 468.0090026855469,
"p99_ms": 474.2013854980469
},
"frames": 31,
"gpu": {
"avg_ms": 85.50063645839691,
"max_ms": 134.11460876464844,
"p50_ms": 82.40946960449219,
"p95_ms": 133.71929931640625,
"p99_ms": 134.11460876464844
},
"low_1pct_fps": 2.01406006678458,
"max_ms": 496.509521484375,
"p50_ms": 390.230224609375,
"p95_ms": 493.8070373535156,
"p99_ms": 496.509521484375,
"seconds": 11.942960067749024
},
"forest": {
"avg_fps": 2.2283930626963917,
"cpu": {
"avg_ms": 354.7813931978666,
"max_ms": 611.8099975585938,
"p50_ms": 293.61376953125,
"p95_ms": 601.3502197265625,
"p99_ms": 611.8099975585938
},
"frames": 26,
"gpu": {
"avg_ms": 201.54420654296874,
"max_ms": 357.0310363769531,
"p50_ms": 172.65980529785156,
"p95_ms": 341.8655700683594,
"p99_ms": 357.0310363769531
},
"low_1pct_fps": 1.52339962842959,
"max_ms": 656.4265747070312,
"p50_ms": 407.1051330566406,
"p95_ms": 611.97119140625,
"p99_ms": 656.4265747070312,
"seconds": 11.667600494384766
},
"ocean": {
"avg_fps": 2.6137193379326398,
"cpu": {
"avg_ms": 330.783615620931,
"max_ms": 730.7304077148438,
"p50_ms": 296.65692138671875,
"p95_ms": 680.8717041015625,
"p99_ms": 730.7304077148438
},
"frames": 30,
"gpu": {
"avg_ms": 113.80178985595703,
"max_ms": 216.57342529296875,
"p50_ms": 104.23703002929688,
"p95_ms": 193.67672729492188,
"p99_ms": 216.57342529296875
},
"low_1pct_fps": 1.1784160273210693,
"max_ms": 848.5967407226562,
"p50_ms": 346.120849609375,
"p95_ms": 681.0716552734375,
"p99_ms": 848.5967407226562,
"seconds": 11.477896484375
},
"mountain": {
"avg_fps": 2.72441042065798,
"cpu": {
"avg_ms": 325.24547207740045,
"max_ms": 578.7177124023438,
"p50_ms": 295.25457763671875,
"p95_ms": 569.8099975585938,
"p99_ms": 578.7177124023438
},
"frames": 31,
"gpu": {
"avg_ms": 104.99177145957947,
"max_ms": 163.95635986328125,
"p50_ms": 99.96784210205078,
"p95_ms": 160.04824829101562,
"p99_ms": 163.95635986328125
},
"low_1pct_fps": 1.7544071931551564,
"max_ms": 569.9931030273438,
"p50_ms": 378.246337890625,
"p95_ms": 555.5369873046875,
"p99_ms": 569.9931030273438,
"seconds": 11.378608657836914
}
}
}
}
+81 -1
View File
@@ -140,10 +140,37 @@ fn serve(stream: UnixStream, sender: &mpsc::Sender<Request>) {
}
}
/// Frame durations since the last reset, summarized like the Java recorder.
/// Frame durations since the last reset, summarized like the Java recorder,
/// with the CPU part of each frame and GPU times from timestamp queries.
#[derive(Default)]
pub struct FrameStats {
millis: Vec<f32>,
cpu: Vec<f32>,
gpu: Vec<f32>,
/// Milliseconds per frame phase (`PHASES`), one entry per rendered frame.
phases: Vec<[f32; PHASES.len()]>,
}
/// The parts of a frame's CPU time: world streaming and uploads, game ticks,
/// building the frame's geometry and HUD, and the renderer's own work.
pub const PHASES: [&str; 4] = ["update", "tick", "prepare", "render"];
fn percentiles(values: &[f32]) -> serde_json::Value {
let mut sorted = values.to_vec();
sorted.sort_by(f32::total_cmp);
let n = sorted.len();
if n == 0 {
return serde_json::Value::Null;
}
let total: f64 = sorted.iter().map(|&m| f64::from(m)).sum();
let percentile = |p: f64| sorted[((n as f64 * p).ceil() as usize).clamp(1, n) - 1];
serde_json::json!({
"avg_ms": total / n as f64,
"p50_ms": percentile(0.5),
"p95_ms": percentile(0.95),
"p99_ms": percentile(0.99),
"max_ms": sorted[n - 1],
})
}
impl FrameStats {
@@ -153,8 +180,48 @@ impl FrameStats {
self.millis.push(millis);
}
}
/// The frame's own work: its duration minus waits for the GPU, the
/// display and the frame limiter.
pub fn record_cpu(&mut self, millis: f32) {
if self.cpu.len() < Self::LIMIT {
self.cpu.push(millis);
}
}
pub fn record_phases(&mut self, millis: [f32; PHASES.len()]) {
if self.phases.len() < Self::LIMIT {
self.phases.push(millis);
}
}
/// Average milliseconds per phase over the frames whose CPU time is at
/// least `min_cpu` (all frames for 0): where the slow frames go.
fn phase_average(&self, min_cpu: f32) -> serde_json::Value {
let mut sums = [0.0f64; PHASES.len()];
let mut n = 0;
for (i, phases) in self.phases.iter().enumerate() {
if self.cpu.get(i).is_some_and(|&c| c >= min_cpu) {
for (sum, m) in sums.iter_mut().zip(phases) {
*sum += f64::from(*m);
}
n += 1;
}
}
PHASES
.iter()
.zip(sums)
.map(|(name, sum)| (name.to_string(), (sum / f64::from(n.max(1))).into()))
.collect::<serde_json::Map<_, _>>()
.into()
}
pub fn record_gpu(&mut self, millis: &[f32]) {
if self.gpu.len() < Self::LIMIT {
self.gpu.extend_from_slice(millis);
}
}
pub fn reset(&mut self) {
self.millis.clear();
self.cpu.clear();
self.gpu.clear();
self.phases.clear();
}
pub fn summary(&self) -> serde_json::Value {
let mut sorted = self.millis.clone();
@@ -172,6 +239,15 @@ impl FrameStats {
.map(|&m| f64::from(m))
.sum::<f64>()
/ slowest as f64;
// Where the slowest 1% of frames by CPU time go.
let slow_phases = {
let mut cpu = self.cpu.clone();
cpu.sort_by(f32::total_cmp);
let p99 = cpu
.get(cpu.len().saturating_sub(cpu.len().div_ceil(100)))
.copied();
p99.map_or(serde_json::Value::Null, |p| self.phase_average(p))
};
serde_json::json!({
"frames": n,
"seconds": total / 1000.0,
@@ -181,6 +257,10 @@ impl FrameStats {
"p95_ms": percentile(0.95),
"p99_ms": percentile(0.99),
"max_ms": sorted[n - 1],
"cpu": percentiles(&self.cpu),
"gpu": percentiles(&self.gpu),
"phases_avg_ms": self.phase_average(0.0),
"slow_phases_avg_ms": slow_phases,
})
}
}
+85
View File
@@ -0,0 +1,85 @@
//! A fast, non-cryptographic hasher (the Fx hash used by rustc) for hot maps
//! keyed by small integers, such as chunk coordinates. Iteration order of
//! such maps carries no meaning: the default hasher's is random anyway.
use std::hash::{BuildHasherDefault, Hasher};
const SEED: u64 = 0xf135_7aea_2e62_a9c5;
#[derive(Clone, Copy, Default)]
pub struct FxHasher {
hash: u64,
}
impl FxHasher {
#[inline]
fn add(&mut self, word: u64) {
self.hash = self.hash.wrapping_add(word).wrapping_mul(SEED);
}
}
impl Hasher for FxHasher {
#[inline]
fn write(&mut self, bytes: &[u8]) {
let (words, rest) = bytes.as_chunks::<8>();
for word in words {
self.add(u64::from_le_bytes(*word));
}
if !rest.is_empty() {
let mut word = [0u8; 8];
word[..rest.len()].copy_from_slice(rest);
self.add(u64::from_le_bytes(word));
}
}
#[inline]
fn write_u8(&mut self, i: u8) {
self.add(u64::from(i));
}
#[inline]
fn write_u16(&mut self, i: u16) {
self.add(u64::from(i));
}
#[inline]
fn write_u32(&mut self, i: u32) {
self.add(u64::from(i));
}
#[inline]
fn write_u64(&mut self, i: u64) {
self.add(i);
}
#[inline]
fn write_usize(&mut self, i: usize) {
self.add(i as u64);
}
#[inline]
fn write_i32(&mut self, i: i32) {
self.add(u64::from(i as u32));
}
#[inline]
fn finish(&self) -> u64 {
// The multiply leaves the low bits weakest; hash tables use them.
self.hash.rotate_left(26)
}
}
pub type FxBuild = BuildHasherDefault<FxHasher>;
pub type FxHashMap<K, V> = std::collections::HashMap<K, V, FxBuild>;
pub type FxHashSet<K> = std::collections::HashSet<K, FxBuild>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn nearby_chunks_spread_over_buckets() {
let mut map: FxHashMap<(i32, i32), i32> = FxHashMap::default();
for x in -40..40 {
for z in -40..40 {
map.insert((x, z), x * z);
}
}
assert_eq!(map.len(), 6400);
assert_eq!(map[&(-7, 13)], -91);
let mut low = std::collections::HashSet::new();
for x in 0..64 {
low.insert(std::hash::BuildHasher::hash_one(&FxBuild::default(), (x, 0)) & 63);
}
assert!(low.len() > 32, "low bits vary: {}", low.len());
}
}
+283 -94
View File
@@ -185,6 +185,11 @@ struct Options {
no_pause: bool,
/// Control socket path (`--control`), for `horizon-ctl`.
control: Option<PathBuf>,
/// `HORIZON_SPIKES=MS`: print the timed spans of frames slower than MS.
spikes: Option<f32>,
/// Render into a texture instead of the window (`--offscreen`), so a
/// GPU the display cannot present from can still be benchmarked.
offscreen: bool,
/// Multiplayer: `--server HOST[:PORT]` joins at start; `--name` is the offline player name.
server: Option<String>,
player_name: String,
@@ -220,6 +225,10 @@ impl Options {
dimension: None,
no_pause: false,
control: None,
offscreen: false,
spikes: std::env::var("HORIZON_SPIKES")
.ok()
.and_then(|v| v.parse().ok()),
server: None,
player_name: std::env::var("HORIZON_PLAYER_NAME").unwrap_or_else(|_| "Player".into()),
dedicated: None,
@@ -240,6 +249,7 @@ impl Options {
"--creative" => o.creative = true,
"--test-terrain" => o.test_terrain = true,
"--no-pause" => o.no_pause = true,
"--offscreen" => o.offscreen = true,
"--control" => o.control = Some(horizon_client::control::default_path()),
_ => {
let value = args
@@ -788,6 +798,16 @@ struct Game<'a> {
/// Control replies waiting for a rendered frame or a benchmark deadline.
pending_screenshot: Option<std::sync::mpsc::Sender<String>>,
pending_bench: Option<(Instant, std::sync::mpsc::Sender<String>)>,
/// Recent frame times for the performance overlay.
frame_graph: horizon_client::perf_overlay::FrameGraph,
/// Meshed sections waiting for an upload budget (Horizon settings).
pending_uploads: Vec<((i32, i32, i32), horizon_client::mesher::SectionMesh)>,
/// This frame's view frustum, for culling entities and block entities.
view_frustum: Option<horizon_client::gfx::Frustum>,
/// A scripted flight from the control socket (`fly`).
flight: Option<control::Flight>,
/// The overworld's last `sky_darken` and its inputs (time, rain, thunder).
sky_darken_memo: std::cell::Cell<Option<((i64, u32, u32), i32)>>,
persist: persist::EntityMemory,
/// Connected to a server: the world comes from the network (game/remote.rs).
remote: Option<remote::Remote>,
@@ -1230,7 +1250,14 @@ impl Game<'_> {
}
fn tick_items(&mut self) {
let mut items = std::mem::take(&mut self.dropped);
items.retain_mut(|item| item.tick(&self.world, &self.res.facts, self.collision));
// ServerLevel.tick: only entities in entity-ticking chunks tick.
let ticking = self.entity_ticking_area();
items.retain_mut(|item| {
!ticking(
item.position.x.floor() as i32,
item.position.z.floor() as i32,
) || item.tick(&self.world, &self.res.facts, self.collision)
});
let Some(p) = self.player.as_ref() else {
self.dropped = items;
return;
@@ -2793,64 +2820,66 @@ impl Game<'_> {
/// What the tick runs after the local player's own update: effects, the
/// world's entities and blocks, and the network hub.
fn tick_world(&mut self, running: bool) -> Result<()> {
self.tick_effects();
self.tick_burning();
self.tick_using();
self.tick_hud();
horizon_client::spans::time("tick_effects", || self.tick_effects());
horizon_client::spans::time("tick_burning", || self.tick_burning());
horizon_client::spans::time("tick_using", || self.tick_using());
horizon_client::spans::time("tick_hud", || self.tick_hud());
// The player's digging comes in with its packets, before the level
// ticks; ServerLevel.tick then runs the scheduled and random block
// ticks before any entity, so what they drop or spawn (dispensed
// items, popped crops) moves on the tick it appears, as in vanilla.
self.tick_local_hand()?;
self.postprocess_chunks()?;
horizon_client::spans::time("tick_local_hand", || self.tick_local_hand())?;
horizon_client::spans::time("postprocess_chunks", || self.postprocess_chunks())?;
if running {
self.tick_blocks()?;
horizon_client::spans::time("tick_blocks", || self.tick_blocks())?;
}
if running {
self.tick_paintings();
self.tick_item_frames();
self.tick_armor_stands();
self.tick_boats();
self.tick_carts();
self.tick_thunder();
self.tick_lecterns();
self.tick_maps();
self.tick_bolts();
self.tick_fishing();
self.tick_tridents();
self.tick_rockets();
horizon_client::spans::time("tick_paintings", || self.tick_paintings());
horizon_client::spans::time("tick_item_frames", || self.tick_item_frames());
horizon_client::spans::time("tick_armor_stands", || self.tick_armor_stands());
horizon_client::spans::time("tick_boats", || self.tick_boats());
horizon_client::spans::time("tick_carts", || self.tick_carts());
horizon_client::spans::time("tick_thunder", || self.tick_thunder());
horizon_client::spans::time("tick_lecterns", || self.tick_lecterns());
horizon_client::spans::time("tick_maps", || self.tick_maps());
horizon_client::spans::time("tick_bolts", || self.tick_bolts());
horizon_client::spans::time("tick_fishing", || self.tick_fishing());
horizon_client::spans::time("tick_tridents", || self.tick_tridents());
horizon_client::spans::time("tick_rockets", || self.tick_rockets());
}
if running {
self.tick_items();
horizon_client::spans::time("tick_items", || self.tick_items());
}
self.spawn_loaded_entities();
horizon_client::spans::time("spawn_loaded_entities", || self.spawn_loaded_entities());
if running {
self.tick_mobs()?;
self.recheck_golem_openers();
self.tick_experience();
horizon_client::spans::time("tick_mobs", || self.tick_mobs())?;
horizon_client::spans::time("recheck_golem_openers", || self.recheck_golem_openers());
horizon_client::spans::time("tick_experience", || self.tick_experience());
}
self.tick_lan();
self.tick_hand();
self.tick_sleep();
self.tick_portal()?;
horizon_client::spans::time("tick_lan", || self.tick_lan());
horizon_client::spans::time("tick_hand", || self.tick_hand());
horizon_client::spans::time("tick_sleep", || self.tick_sleep());
horizon_client::spans::time("tick_portal", || self.tick_portal())?;
if running {
self.tick_end()?;
horizon_client::spans::time("tick_end", || self.tick_end())?;
}
if running {
self.tick_falling()?;
self.tick_tnt()?;
horizon_client::spans::time("tick_falling", || self.tick_falling())?;
horizon_client::spans::time("tick_tnt", || self.tick_tnt())?;
}
if running {
self.tick_block_entities()?;
self.tick_sculk_entities();
self.tick_sculk_blocks()?;
self.tick_brewing_stands()?;
horizon_client::spans::time("tick_block_entities", || self.tick_block_entities())?;
horizon_client::spans::time("tick_sculk_entities", || self.tick_sculk_entities());
horizon_client::spans::time("tick_sculk_blocks", || self.tick_sculk_blocks())?;
horizon_client::spans::time("tick_brewing_stands", || self.tick_brewing_stands())?;
}
if running {
// ClientLevel.tickBlockEntities (not while paused or frozen):
// chest lids, books, shulker boxes, bells, conduits, heads.
self.tick_block_entity_anims();
self.tick_particles();
horizon_client::spans::time("tick_block_entity_anims", || {
self.tick_block_entity_anims()
});
horizon_client::spans::time("tick_particles", || self.tick_particles());
}
if self.right && self.use_delay == 0 && self.screen == Screen::Playing {
self.use_with_hand()?;
@@ -2974,6 +3003,12 @@ impl Game<'_> {
hud_layout::paint(batch, &self.res.atlas, &draws);
}
fn hud(&mut self, size: [u32; 2]) -> HudBatch {
let mut batch = self.hud_layers(size);
self.frame_graph
.draw(self.settings.horizon.overlay, &mut batch, &self.res.atlas);
batch
}
fn hud_layers(&mut self, size: [u32; 2]) -> HudBatch {
let mut batch = HudBatch::new(size);
let (w, h) = (batch.width, batch.height);
if self.screen == Screen::Options {
@@ -4386,9 +4421,34 @@ impl Game<'_> {
banner: &|p| self.banner_layers_at(p),
glyph: &|c| self.res.atlas.glyph_cell(c),
};
// Block entities outside the view frustum are skipped (with a
// block of margin for models larger than their block).
let view = self.view_frustum;
// Beams and structure outlines reach far outside their block
// (BlockEntityRenderer.shouldRenderOffScreen): never culled.
let off_screen = |state: u32| {
let name = &*self.res.facts.get(BlockStateId(state)).name;
matches!(
name,
"minecraft:beacon"
| "minecraft:end_gateway"
| "minecraft:structure_block"
| "minecraft:test_instance_block"
)
};
let visible = r.block_entities().filter(|(p, state)| {
off_screen(*state)
|| view.is_none_or(|v| {
let o =
(glam::DVec3::new(f64::from(p[0]), f64::from(p[1]), f64::from(p[2]))
- camera)
.as_vec3();
v.intersects(o - glam::Vec3::ONE, o + glam::Vec3::splat(2.0))
})
});
self.res
.block_entity_render
.render(&scene, r.block_entities(), &mut out);
.render(&scene, visible, &mut out);
}
// Experience orbs (ExperienceOrbRenderer): pulsing billboards from a 4x4 icon sheet.
if let Some(r) = self
@@ -4622,11 +4682,20 @@ impl Game<'_> {
.sample(self.world.day_time, None, None);
return (15.0 - 15.0 * sky.sky_light_level).round() as i32;
}
let mut sky = self.res.environment.sample(self.world.day_time, None, None);
let (rain, thunder) = self.world.weather.levels(1.0);
// Sampled once per (time, weather): every mob asks each tick.
let key = (self.world.day_time, rain.to_bits(), thunder.to_bits());
if let Some((k, darken)) = self.sky_darken_memo.get()
&& k == key
{
return darken;
}
let mut sky = self.res.environment.sample(self.world.day_time, None, None);
horizon_client::environment::apply_weather(&mut sky, rain, thunder);
// Level.updateSkyBrightness: darkening from the sky light level.
(15.0 - 15.0 * sky.sky_light_level).round() as i32
let darken = (15.0 - 15.0 * sky.sky_light_level).round() as i32;
self.sky_darken_memo.set(Some((key, darken)));
darken
}
fn mob_hit(&self) -> Option<(usize, f64)> {
let eye = self.eye_position()?;
@@ -7214,14 +7283,39 @@ impl Game<'_> {
} else {
Vec::new()
};
let mut hud = self.hud(size);
let mut hud = horizon_client::spans::time("hud", || self.hud(size));
// Map textures changed since the last drawn frame (game/maps.rs).
hud.patches.append(&mut self.map_patches);
let title = self.title.is_some();
let (yaw, pitch) = if live {
(view_yaw, view_pitch)
} else if title {
// PanoramaRenderer: the title cube spins at 0.1 degrees per tick, pitched 10 degrees.
(-(self.started.elapsed().as_secs_f32() * 2.0) % 360.0, 10.0)
} else {
(view_yaw, view_pitch)
};
let fov_degrees = if live {
72.0
} else if title {
85.0
} else {
self.fov_degrees(alpha as f32, camera.to_array())
};
let bob = if title {
glam::Mat4::IDENTITY
} else {
self.bob_matrix(alpha as f32)
};
let distance = (self.streaming.radius * 16) as f32;
self.view_frustum = self
.renderer
.as_ref()
.map(|r| r.camera_frustum(fov_degrees, yaw, pitch, bob, distance));
let mut entities = if title {
Vec::new()
} else {
self.entity_geometry(camera, alpha)
horizon_client::spans::time("entity_geometry", || self.entity_geometry(camera, alpha))
};
let mut additive = Vec::new();
if !title {
@@ -7260,17 +7354,15 @@ impl Game<'_> {
self.end_geometry(camera, &mut entities);
}
if (!title || live) && self.dim == Dim::Overworld {
self.cloud_geometry(&sky, camera, alpha, &mut entities);
self.weather_geometry(camera, alpha, &mut entities);
horizon_client::spans::time("clouds", || {
self.cloud_geometry(&sky, camera, alpha, &mut entities)
});
if self.settings.horizon.weather {
horizon_client::spans::time("weather", || {
self.weather_geometry(camera, alpha, &mut entities)
});
}
}
// PanoramaRenderer: the title cube spins at 0.1 degrees per tick, pitched 10 degrees.
let (yaw, pitch) = if live {
(view_yaw, view_pitch)
} else if title {
(-(self.started.elapsed().as_secs_f32() * 2.0) % 360.0, 10.0)
} else {
(view_yaw, view_pitch)
};
let water_fog = {
let c = info.water_fog;
[
@@ -7286,39 +7378,42 @@ impl Game<'_> {
camera,
yaw,
pitch,
fov_degrees: if live {
72.0
} else if title {
85.0
} else {
self.fov_degrees(alpha as f32, camera.to_array())
},
bob: if title {
glam::Mat4::IDENTITY
} else {
self.bob_matrix(alpha as f32)
},
fov_degrees,
bob,
sky,
distance: (self.streaming.radius * 16) as f32,
distance,
underwater,
title: title && !live,
skybox: self.dim == Dim::Overworld,
end_sky: self.dim == Dim::End,
skybox: self.dim == Dim::Overworld && self.settings.horizon.sky,
end_sky: self.dim == Dim::End && self.settings.horizon.sky,
environment_fog: (self.dim == Dim::Nether).then_some((sky.fog_start, sky.fog_end)),
// The camera inside an opaque block sees nothing through it: disable.
cave_culling: !self
.res
.facts
.get(self.world.block(block[0], block[1], block[2]))
.solid_render,
cave_culling: self.settings.horizon.cave_culling
&& !self
.res
.facts
.get(self.world.block(block[0], block[1], block[2]))
.solid_render,
water_fog,
fog: Some(self.frame_fog(camera, &sky, biome)),
fog: Some({
let mut fog = self.frame_fog(camera, &sky, biome);
// Horizon's fog setting: no distance fog (fluids keep theirs).
if !self.settings.horizon.fog && !underwater && fog.environmental_end >= distance {
(fog.render_distance_start, fog.render_distance_end) = (1e9, 2e9);
(fog.environmental_start, fog.environmental_end) = (1e9, 2e9);
}
fog
}),
dark_disc: self.dark_disc(camera),
outline,
hud: &hud,
entities: &entities,
additive: &additive,
celestial: &celestial,
celestial: if self.settings.horizon.sky || title {
&celestial
} else {
&[]
},
hand: &hand,
hand_fov_degrees: self.hud_fov_degrees(alpha as f32, camera.to_array()),
screen: &screen,
@@ -7344,7 +7439,8 @@ impl Game<'_> {
None
},
};
self.renderer.as_mut().ok_or("renderer")?.render(&frame)
let renderer = self.renderer.as_mut().ok_or("renderer")?;
horizon_client::spans::time("renderer", || renderer.render(&frame))
}
/// `LevelExtractor` / `LevelRenderer`: the world border wall this frame.
fn border_draw(
@@ -7545,32 +7641,79 @@ impl Game<'_> {
(p.position.z.floor() as i32) >> 4,
);
}
let (uploads, unloaded) = self.streaming.update(&mut self.world);
let (uploads, unloaded) =
horizon_client::spans::time("streaming", || self.streaming.update(&mut self.world));
let dirty: Vec<_> = unloaded
.iter()
.filter(|c| self.world.modified.remove(&(c.x, c.z)))
.cloned()
.collect();
let modified: Vec<_> = dirty.iter().map(|c| self.with_entities(c)).collect();
self.unload_entities(&unloaded);
for c in &unloaded {
let modified: Vec<_> = horizon_client::spans::time("with_entities", || {
dirty.iter().map(|c| self.with_entities(c)).collect()
});
horizon_client::spans::time("unload_entities", || self.unload_entities(&unloaded));
if !unloaded.is_empty() {
let gone: horizon_client::fast_hash::FxHashSet<(i32, i32)> =
unloaded.iter().map(|c| (c.x, c.z)).collect();
self.world
.block_entities
.retain(|p, _| !(p.0 >> 4 == c.x && p.2 >> 4 == c.z));
.retain(|p, _| !gone.contains(&(p.0 >> 4, p.2 >> 4)));
self.world
.block_names
.retain(|p, _| !(p.0 >> 4 == c.x && p.2 >> 4 == c.z));
.retain(|p, _| !gone.contains(&(p.0 >> 4, p.2 >> 4)));
}
if !modified.is_empty()
&& let Err(e) = self
.save
.save(&modified, self.res.assets.registry, &self.res.biomes)
&& let Err(e) = horizon_client::spans::time("save_chunks", || {
self.save
.save_later(&modified, self.res.assets.registry, &self.res.biomes)
})
{
eprintln!("Horizon: failed to save unloaded chunks: {e}");
}
if let Some(renderer) = self.renderer.as_mut() {
for (key, mesh) in uploads {
renderer.upload(key, &mesh);
let g = &self.settings.horizon;
let budgeted = g.chunk_updates > 0 || g.upload_budget_kib > 0;
if !budgeted && self.pending_uploads.is_empty() {
horizon_client::spans::time("upload", || {
for (key, mesh) in uploads {
renderer.upload(key, &mesh);
}
});
} else {
// Horizon's chunk-update and upload budgets: the nearest
// sections go first, the rest wait for later frames; a newer
// mesh of a waiting section replaces it.
let pending = &mut self.pending_uploads;
let fresh: horizon_client::fast_hash::FxHashSet<(i32, i32, i32)> =
uploads.iter().map(|(k, _)| *k).collect();
let gone: horizon_client::fast_hash::FxHashSet<(i32, i32)> =
unloaded.iter().map(|c| (c.x, c.z)).collect();
pending.retain(|(k, _)| !fresh.contains(k) && !gone.contains(&(k.0, k.2)));
pending.extend(uploads);
let centre = self.streaming.center;
let far = |k: &(i32, i32, i32)| (k.0 - centre.0).pow(2) + (k.2 - centre.1).pow(2);
pending.sort_unstable_by_key(|(k, _)| std::cmp::Reverse(far(k)));
let (limit, budget) = if budgeted {
(
g.chunk_updates as usize,
u64::from(g.upload_budget_kib) * 1024,
)
} else {
(0, 0)
};
let (mut count, mut bytes) = (0, 0u64);
while let Some((_, mesh)) = pending.last() {
let size = ((mesh.solid.len() + mesh.translucent.len()) * 32) as u64;
if (limit > 0 && count >= limit)
|| (budget > 0 && bytes > 0 && bytes + size > budget)
{
break;
}
let (key, mesh) = pending.pop().expect("checked above");
renderer.upload(key, &mesh);
count += 1;
bytes += size;
}
}
for c in unloaded {
for sy in 0..(HEIGHT / 16) {
@@ -7600,6 +7743,7 @@ impl ApplicationHandler for Game<'_> {
let assets = &self.res.assets;
match pollster::block_on(Renderer::new(
window.clone(),
self.options.offscreen,
&assets.pixels,
assets.sprite_size,
assets.texture_layers,
@@ -8029,15 +8173,16 @@ impl ApplicationHandler for Game<'_> {
self.pause_since = None;
}
if self.title.is_none() {
self.update_world();
self.spawn_player()?;
horizon_client::spans::time("update_world", || self.update_world());
horizon_client::spans::time("spawn_player", || self.spawn_player())?;
}
let updated = Instant::now();
self.track_toggle_screens();
let steps = self.clock.advance(elapsed);
for _ in 0..steps {
let started = Instant::now();
if self.title.is_none() && !self.pause {
self.tick()?;
horizon_client::spans::time("tick", || self.tick())?;
self.tick_ambience();
self.tick_fov();
} else if self.title.is_some() {
@@ -8051,7 +8196,48 @@ impl ApplicationHandler for Game<'_> {
}
}
self.apply_mouse_look();
self.advance_flight();
let ticked = Instant::now();
let rendered = self.render()?;
if let Some(threshold) = self.options.spikes
&& let Some(r) = self.renderer.as_ref()
{
let cpu = now.elapsed().saturating_sub(r.last_wait).as_secs_f32() * 1000.0;
let spans = horizon_client::spans::take();
if cpu > threshold {
let list: Vec<String> = spans
.iter()
.filter(|(_, ms)| *ms >= 0.5)
.map(|(n, ms)| format!("{n} {ms:.1}"))
.collect();
eprintln!(
"Horizon: slow frame {cpu:.1} ms ({} ticks): {}",
steps,
list.join(", ")
);
}
}
if let Some(r) = self.renderer.as_mut() {
let cpu = now.elapsed().saturating_sub(r.last_wait);
if rendered {
let ms = |d: Duration| d.as_secs_f32() * 1000.0;
self.frame_graph.record(
ms(elapsed),
ms(cpu),
r.gpu_times.last().copied(),
);
self.frame_stats.record_cpu(ms(cpu));
let render = r.last_encode;
self.frame_stats.record_phases([
ms(updated - now),
ms(ticked - updated),
ms(ticked.elapsed().saturating_sub(r.last_wait + render)),
ms(render),
]);
}
self.frame_stats.record_gpu(&r.gpu_times);
r.gpu_times.clear();
}
self.limit_frame();
self.pause = self.pauses_game();
self.clock.end_frame(self.pause);
@@ -8132,6 +8318,7 @@ pub fn run() -> Result<()> {
return Ok(());
}
let started = Instant::now();
horizon_client::spans::enable(options.spikes.is_some());
let vanilla_root = options.resources.clone();
let early_settings = Settings::load(&std::env::current_dir()?.join("options.txt"));
options.resources = packs::startup_root(&vanilla_root, &early_settings.resource_packs);
@@ -8180,10 +8367,7 @@ pub fn run() -> Result<()> {
biomes: biomes.clone(),
light,
});
let threads = std::thread::available_parallelism()
.map_or(2, |n| n.get())
.saturating_sub(1)
.max(1);
let threads = early_settings.horizon.worker_threads();
eprintln!(
"Horizon: resources loaded in {:.1}s; {} block states, {} items, {} biomes; {} worker threads",
started.elapsed().as_secs_f32(),
@@ -8470,6 +8654,11 @@ pub fn run() -> Result<()> {
frame_stats: Default::default(),
pending_screenshot: None,
pending_bench: None,
flight: None,
view_frustum: None,
pending_uploads: Vec::new(),
frame_graph: Default::default(),
sky_darken_memo: Default::default(),
persist: Default::default(),
remote: None,
lan: None,
+58 -2
View File
@@ -29,9 +29,10 @@ const HELP: &[&str] = &[
"chat TEXT send a chat line or /command as if typed",
"type TEXT type into the open chat box (key enter tap sends)",
"chat-log [N] the newest N chat messages (default 10)",
"options [PAGE] open the options (video sound controls keybinds mouse chat accessibility language font packs)",
"options [PAGE] open the options (video sound controls keybinds mouse chat accessibility language font packs graphics graphics-advanced)",
"stats [reset] frame-time summary since the last reset",
"bench SECONDS reset stats, wait, then reply with the summary",
"fly X1 Y1 Z1 X2 Y2 Z2 SECONDS [PITCH] fly the camera along a line at constant speed, then reply with the frame summary",
"open WORLD [SEED] [creative] open or create a world from the title screen",
"save save the world",
"save-all save the world, rewriting every resident chunk",
@@ -42,7 +43,42 @@ const HELP: &[&str] = &[
"quit save and exit",
];
/// A straight camera path at constant speed, for repeatable benchmarks: the
/// player is placed on it every frame, facing along it.
pub struct Flight {
from: Vec3,
to: Vec3,
pitch: f32,
started: Instant,
seconds: f64,
reply: Sender<String>,
}
impl Game<'_> {
/// Move the camera along the running flight; reply when it ends.
pub(super) fn advance_flight(&mut self) {
let Some(flight) = &self.flight else { return };
let t = (flight.started.elapsed().as_secs_f64() / flight.seconds).min(1.0);
let (a, b) = (flight.from, flight.to);
let d = [b.x - a.x, b.y - a.y, b.z - a.z];
let at = Vec3::new(a.x + d[0] * t, a.y + d[1] * t, a.z + d[2] * t);
// Minecraft yaw: 0 faces +Z, 90 faces -X.
self.yaw = (-d[0]).atan2(d[2]).to_degrees() as f32;
self.pitch = flight.pitch;
if let Some(player) = self.player.as_mut() {
player.position = at;
player.velocity = Vec3::new(0.0, 0.0, 0.0);
player.fall_distance = 0.0;
// Stay where the flight ends (creative flight).
player.flying = true;
self.previous_position = at;
}
if t >= 1.0
&& let Some(flight) = self.flight.take()
{
let _ = flight.reply.send(self.frame_stats.summary().to_string());
}
}
pub(super) fn poll_control(&mut self, event_loop: &ActiveEventLoop) {
if let Some((deadline, reply)) = self.pending_bench.take() {
if Instant::now() >= deadline {
@@ -325,6 +361,8 @@ impl Game<'_> {
"language" => Page::Language,
"font" => Page::Font,
"packs" => Page::Packs,
"graphics" => Page::Graphics,
"graphics-advanced" => Page::GraphicsAdvanced,
other => return Err(format!("unknown options page {other}").into()),
};
if self.screen == Screen::Playing && self.title.is_none() {
@@ -357,6 +395,24 @@ impl Game<'_> {
));
Ok(None)
}
"fly" => {
self.require_world()?;
if self.flight.is_some() || self.pending_bench.is_some() {
return Err("a benchmark is already running".into());
}
let n = |i: usize| -> Result<f64> { Ok(arg(i)?.parse()?) };
let pitch = words.get(8).map_or(Ok(10.0), |p| p.parse::<f32>())?;
self.frame_stats.reset();
self.flight = Some(Flight {
from: Vec3::new(n(1)?, n(2)?, n(3)?),
to: Vec3::new(n(4)?, n(5)?, n(6)?),
pitch,
started: Instant::now(),
seconds: n(7)?.max(0.1),
reply: reply.clone(),
});
Ok(None)
}
"open" => {
if self.title.is_none() {
return Err("a world is already open".into());
@@ -523,7 +579,7 @@ impl Game<'_> {
"chunks": self.world.chunks.len(),
"mobs": self.mobs.len(),
"block_entities": self.world.block_entities.len(),
"pending_chunks": self.streaming.pending(),
"pending_chunks": self.streaming.pending() + self.pending_uploads.len(),
"generated_chunks": self.streaming.generated_total,
"meshed_sections": self.streaming.meshed_total,
"renderer": renderer,
+17 -9
View File
@@ -17,10 +17,7 @@ use horizon_core::{
random::{LegacyRandom, RandomSource},
};
use horizon_world::registry::BlockStateId;
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};
use std::{collections::HashMap, sync::Arc};
type Pos = (i32, i32, i32);
@@ -319,7 +316,16 @@ impl Game<'_> {
let Some(chunk) = self.world.chunks.get(&key).cloned() else {
continue;
};
let name = |id: u16| &*self.res.facts.get(BlockStateId(u32::from(id))).name;
if self.creaking.hearts.is_empty() {
self.creaking.hearts = self
.res
.facts
.states
.iter()
.map(|f| &*f.name == "minecraft:creaking_heart")
.collect();
}
let hearts = &self.creaking.hearts;
let _ = heart;
for (si, section) in chunk.sections.iter().enumerate() {
if section.is_uniform(0) {
@@ -327,7 +333,7 @@ impl Game<'_> {
}
for i in 0..4096 {
let id = section.get(i);
if name(id) != "minecraft:creaking_heart" {
if !hearts.get(usize::from(id)).copied().unwrap_or(false) {
continue;
}
let (lx, lz, ly) = ((i & 15) as i32, ((i >> 4) & 15) as i32, (i >> 8) as i32);
@@ -343,8 +349,8 @@ impl Game<'_> {
}
}
}
let loaded: HashSet<(i32, i32)> = self.world.chunks.keys().copied().collect();
self.creaking.scanned.retain(|k| loaded.contains(k));
let chunks = &self.world.chunks;
self.creaking.scanned.retain(|k| chunks.contains_key(k));
}
}
@@ -352,5 +358,7 @@ impl Game<'_> {
#[derive(Default)]
pub(super) struct CreakingState {
/// Chunks already scanned for heart blocks.
scanned: HashSet<(i32, i32)>,
scanned: horizon_client::fast_hash::FxHashSet<(i32, i32)>,
/// Which block states are creaking hearts, by state id.
hearts: Vec<bool>,
}
+51 -1
View File
@@ -403,6 +403,25 @@ impl Game<'_> {
self.tick_raids();
self.tick_creature_entities()
}
/// `DistanceManager.inEntityTickingRange`: chunks within the simulation
/// distance (Chebyshev, in chunks) of the player or of a guest.
pub(super) fn entity_ticking_area(&self) -> impl Fn(i32, i32) -> bool + use<> {
let d = self.settings.simulation_distance.max(2);
let mut centres: Vec<(i32, i32)> = self.streaming.extra.iter().map(|&(c, _)| c).collect();
if let Some(p) = &self.player {
centres.push((
(p.position.x.floor() as i32) >> 4,
(p.position.z.floor() as i32) >> 4,
));
}
let everywhere = centres.is_empty();
move |x, z| {
everywhere
|| centres
.iter()
.any(|&(cx, cz)| ((x >> 4) - cx).abs().max(((z >> 4) - cz).abs()) <= d)
}
}
/// The entity phase of `tick_creatures`: every mob's tick, deaths, and the
/// projectiles and effects that follow from them.
pub(super) fn tick_creature_entities(&mut self) -> Result<()> {
@@ -424,6 +443,7 @@ impl Game<'_> {
let mut mobs = std::mem::take(&mut self.mobs);
let mut dead = Vec::new();
let mut died = std::mem::take(&mut self.died);
let ticking = self.entity_ticking_area();
let level_random;
{
// The level random, lent to the mobs (brain behaviours draw from
@@ -441,6 +461,18 @@ impl Game<'_> {
keep.push(!m.hostile() || m.persistent);
continue;
}
// ServerLevel.tick: every loaded entity checks despawning, but
// only those in entity-ticking chunks (within the simulation
// distance) tick.
if !ticking(m.position.x.floor() as i32, m.position.z.floor() as i32) {
let kept = horizon_client::mobs::ai::despawn_check(m, &w);
if !kept {
died.remove(&m.id);
snapshot[i].alive = false;
}
keep.push(kept);
continue;
}
horizon_client::mobs::apply_mob_pushes(m, &mut pushes);
let from = events.len();
let kept = m.tick(&w, &mut scratch, &mut events);
@@ -2248,11 +2280,29 @@ impl Game<'_> {
pub(super) fn mob_geometry(&self, camera: glam::DVec3, alpha: f64, out: &mut Vec<Vertex>) {
let atlas = &self.res.atlas;
let lookup = |name: &str| atlas.sprites.get(name).map(|r| [r.u0, r.v0, r.u1, r.v1]);
let scale = f64::from(self.settings.entity_distance);
for mob in &self.mobs {
let d = glam::DVec3::new(mob.position.x, mob.position.y, mob.position.z) - camera;
if d.length_squared() > 128.0 * 128.0 {
// Entity.shouldRenderAtSqrDistance: 64 times the bounding box's
// mean edge, scaled by the entity distance option.
let (w, h, _) = mob.dims();
let range = (w + h + w) / 3.0 * 64.0 * scale;
if d.length_squared() >= range * range {
continue;
}
// EntityRenderer.shouldRender: the culling box, grown by 0.5
// (GuardianRenderer also draws while its beam is out).
if let Some(view) = &self.view_frustum
&& horizon_client::mobs::guardian::beam(mob, alpha as f32).is_none()
{
let lo =
d.as_vec3() - glam::Vec3::new(w as f32 / 2.0 + 0.5, 0.5, w as f32 / 2.0 + 0.5);
let hi = d.as_vec3()
+ glam::Vec3::new(w as f32 / 2.0 + 0.5, h as f32 + 0.5, w as f32 / 2.0 + 0.5);
if !view.intersects(lo, hi) {
continue;
}
}
let light = self.world.light(
mob.position.x.floor() as i32,
(mob.position.y + mob.eye_height()).floor() as i32,
@@ -376,6 +376,7 @@ impl Game<'_> {
self.set_default_game_mode(game_mode);
self.ui.difficulty = props.difficulty as u8;
self.settings.render_distance = props.view_distance.clamp(2, 32);
self.settings.simulation_distance = props.simulation_distance.clamp(2, 32);
self.streaming.radius = self.settings.render_distance;
self.settle_spawn()?;
let gate_lists = lists.clone();
+6 -1
View File
@@ -762,9 +762,14 @@ impl Game<'_> {
/// Every cart but the ridden one (which ticks with its rider).
pub(super) fn tick_carts(&mut self) {
self.push_carts();
// ServerLevel.tick: only entities in entity-ticking chunks tick.
let ticking = self.entity_ticking_area();
let mut i = 0;
while i < self.carts.len() {
if Some(self.carts[i].id) == self.riding {
let p = self.carts[i].position;
if Some(self.carts[i].id) == self.riding
|| !ticking(p.x.floor() as i32, p.z.floor() as i32)
{
i += 1;
continue;
}
+13 -2
View File
@@ -142,7 +142,10 @@ impl Game<'_> {
let s = &self.settings;
if let Some(r) = self.renderer.as_mut() {
r.gamma = s.gamma;
r.set_vsync(s.vsync);
r.set_present_mode(s.vsync, s.horizon.present_mode);
r.animated_textures = s.horizon.animated_textures;
r.set_mipmap_levels(s.mipmap_levels.max(0) as u32);
r.set_world_post(s.horizon.resolution_scale as f32 / 100.0, s.horizon.fxaa);
}
if let Some(w) = &self.window {
let want = s.fullscreen;
@@ -207,6 +210,14 @@ impl Game<'_> {
return;
}
let limit = self.framerate_limit();
horizon_client::window::end_frame(&mut self.limiter, limit, &mut self.frame_clock);
match self.settings.horizon.pacing {
horizon_client::graphics::Pacing::Precise => {
horizon_client::window::end_frame(&mut self.limiter, limit, &mut self.frame_clock)
}
horizon_client::graphics::Pacing::Efficient => {
let mut clock = horizon_client::window::SleepingClock(self.frame_clock);
horizon_client::window::end_frame(&mut self.limiter, limit, &mut clock);
}
}
}
}
+1 -1
View File
@@ -831,7 +831,7 @@ impl Game<'_> {
self.spawn_loaded_entities();
let keys: HashSet<(i32, i32)> = unloaded.iter().map(|c| (c.x, c.z)).collect();
let chunks = self.entity_chunks(&keys, true);
if let Err(e) = self.save.save_entities(chunks) {
if let Err(e) = self.save.save_entities_later(chunks) {
eprintln!("Horizon: failed to save entities: {e}");
}
}
+490 -205
View File
@@ -13,6 +13,11 @@ use std::{collections::HashMap, path::PathBuf, sync::Arc, time::Instant};
use wgpu::util::DeviceExt;
use winit::window::Window;
mod arena;
mod occlusion;
mod timing;
mod world_post;
#[repr(C)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
struct Globals {
@@ -33,10 +38,14 @@ struct Globals {
}
pub type SectionKey = (i32, i32, i32);
struct SectionGpu {
buffer: wgpu::Buffer,
/// Arena page and first vertex in it: solid quads, then translucent ones.
page: u32,
start: u64,
solid: u32,
translucent: u32,
}
/// A visible section this frame: key, squared distance, camera-relative origin.
type Visible = (SectionKey, f64, [f32; 3]);
/// Line segments the hit outline can hold.
const MAX_OUTLINE_EDGES: u64 = 256;
pub struct Frame<'a> {
@@ -120,7 +129,20 @@ struct BorderUniform {
}
pub struct Renderer {
instance: wgpu::Instance,
surface: wgpu::Surface<'static>,
/// The window's swapchain; `None` when rendering offscreen (`--offscreen`).
surface: Option<wgpu::Surface<'static>>,
/// The offscreen colour target, sized like `config`.
offscreen: Option<wgpu::Texture>,
/// Offscreen submissions still on the GPU: at most two frames run ahead.
in_flight: std::collections::VecDeque<wgpu::SubmissionIndex>,
gpu_timer: Option<timing::GpuTimer>,
/// GPU frame times (ms) read back since the caller last drained them.
pub gpu_times: Vec<f32>,
/// Time the last `render` spent blocked on the GPU or the display
/// (acquiring, presenting, offscreen pacing), excluded from CPU time.
pub last_wait: std::time::Duration,
/// CPU time of the last `render`, waits excluded.
pub last_encode: std::time::Duration,
window: Arc<Window>,
pub device: wgpu::Device,
pub queue: wgpu::Queue,
@@ -154,6 +176,12 @@ pub struct Renderer {
lightmap: wgpu::Texture,
sprite_texture: wgpu::Texture,
mip_levels: u32,
/// The mipmap levels sampled (the Mipmap Levels option), at most `mip_levels - 1`.
mipmaps: u32,
terrain_layout: wgpu::BindGroupLayout,
sprite_sampler: wgpu::Sampler,
lightmap_view: wgpu::TextureView,
lightmap_sampler: wgpu::Sampler,
animations: Vec<(SpriteAnimation, usize)>,
indices: wgpu::Buffer,
index_quads: u32,
@@ -162,13 +190,26 @@ pub struct Renderer {
outline: wgpu::Buffer,
depth: wgpu::TextureView,
sections: HashMap<SectionKey, SectionGpu>,
arena: arena::Arena,
/// `DrawIndexedIndirectArgs` for this frame's solid then translucent draws.
indirect: wgpu::Buffer,
indirect_capacity: u64,
/// Indirect draws may set `first_instance` (the section origin).
multi_draw: bool,
/// Per-frame scratch, kept to avoid allocating every frame.
visible: Vec<Visible>,
origins: Vec<[f32; 4]>,
/// `DrawIndexedIndirectArgs` words: index count, instance count, first
/// index, base vertex, first instance.
draws: Vec<[u32; 5]>,
/// The arena page of each of `draws`.
draw_pages: Vec<u32>,
/// Block-entity blocks per meshed section (world position, state id).
block_entities: HashMap<SectionKey, Vec<([i32; 3], u32)>>,
/// VisGraph face connectivity per meshed section (cave culling).
visibility: HashMap<SectionKey, u64>,
reachable: std::collections::HashSet<SectionKey>,
reachable_from: Option<SectionKey>,
visibility_dirty: bool,
occlusion: occlusion::Occlusion,
/// Resolution scale and FXAA (Horizon settings).
world_post: world_post::Post,
pub hud: HudRenderer,
/// The menus' backdrop blur, made on first use.
post: Option<crate::post::Post>,
@@ -183,6 +224,8 @@ pub struct Renderer {
pub screenshot_result: Option<std::result::Result<[u32; 2], String>>,
/// Brightness option (lightmap gamma), 0..1.
pub gamma: f32,
/// Advance animated block textures (Horizon setting; vanilla always does).
pub animated_textures: bool,
present_modes: Vec<wgpu::PresentMode>,
}
fn mip_chain(pixels: &[u8], size: u32, layers: u32) -> (Vec<u8>, u32) {
@@ -245,6 +288,7 @@ impl Renderer {
impl Renderer {
pub async fn new(
window: Arc<Window>,
offscreen: bool,
sprite_pixels: &[u8],
sprite_size: u32,
layers: u32,
@@ -254,11 +298,17 @@ impl Renderer {
) -> Result<Self> {
let instance =
wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle_from_env());
let surface = instance.create_surface(window.clone())?;
// Offscreen rendering needs no surface, so it can use a GPU the
// window's display cannot present from (a headless compositor).
let surface = if offscreen {
None
} else {
Some(instance.create_surface(window.clone())?)
};
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
compatible_surface: Some(&surface),
compatible_surface: surface.as_ref(),
force_fallback_adapter: false,
..Default::default()
})
@@ -280,34 +330,56 @@ impl Renderer {
let (device, queue) = adapter
.request_device(&wgpu::DeviceDescriptor {
label: Some("Horizon device"),
required_features: timing::GpuTimer::features(&adapter)
| (adapter.features() & wgpu::Features::INDIRECT_FIRST_INSTANCE),
required_limits: limits.clone(),
..Default::default()
})
.await?;
let size = window.inner_size();
let mut config = surface
.get_default_config(&adapter, size.width.max(1), size.height.max(1))
.ok_or("surface has no supported configuration")?;
let caps = surface.get_capabilities(&adapter);
// Vanilla blends and tints in gamma space: use a non-sRGB target.
config.format = caps
.formats
.iter()
.copied()
.find(|f| !f.is_srgb())
.unwrap_or(config.format);
config.view_formats = vec![config.format.remove_srgb_suffix()];
// Screenshots copy the presented frame back from the swapchain.
if caps.usages.contains(wgpu::TextureUsages::COPY_SRC) {
config.usage |= wgpu::TextureUsages::COPY_SRC;
}
let present_modes = caps.present_modes.clone();
config.present_mode = if caps.present_modes.contains(&wgpu::PresentMode::Mailbox) {
wgpu::PresentMode::Mailbox
let (config, present_modes) = if let Some(surface) = &surface {
let mut config = surface
.get_default_config(&adapter, size.width.max(1), size.height.max(1))
.ok_or("surface has no supported configuration")?;
let caps = surface.get_capabilities(&adapter);
// Vanilla blends and tints in gamma space: use a non-sRGB target.
config.format = caps
.formats
.iter()
.copied()
.find(|f| !f.is_srgb())
.unwrap_or(config.format);
config.view_formats = vec![config.format.remove_srgb_suffix()];
// Screenshots copy the presented frame back from the swapchain.
if caps.usages.contains(wgpu::TextureUsages::COPY_SRC) {
config.usage |= wgpu::TextureUsages::COPY_SRC;
}
config.present_mode = if caps.present_modes.contains(&wgpu::PresentMode::Mailbox) {
wgpu::PresentMode::Mailbox
} else {
wgpu::PresentMode::Fifo
};
surface.configure(&device, &config);
(config, caps.present_modes.clone())
} else {
wgpu::PresentMode::Fifo
let format = wgpu::TextureFormat::Bgra8Unorm;
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC,
format,
width: size.width.max(1),
height: size.height.max(1),
present_mode: wgpu::PresentMode::Immediate,
desired_maximum_frame_latency: 2,
alpha_mode: wgpu::CompositeAlphaMode::Opaque,
view_formats: vec![format],
color_space: wgpu::SurfaceColorSpace::default(),
};
(config, Vec::new())
};
surface.configure(&device, &config);
let offscreen = surface
.is_none()
.then(|| Self::offscreen_target(&device, &config));
let gpu_timer = timing::GpuTimer::new(&device, &queue);
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Horizon terrain"),
source: wgpu::ShaderSource::Wgsl(include_str!("terrain.wgsl").into()),
@@ -1102,9 +1174,26 @@ impl Renderer {
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
let arena = arena::Arena::new(&device, std::mem::size_of::<Vertex>() as u64, 1 << 20);
let indirect = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Section draws"),
size: 1024 * 20,
usage: wgpu::BufferUsages::INDIRECT | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
let multi_draw = device
.features()
.contains(wgpu::Features::INDIRECT_FIRST_INSTANCE);
let world_post = world_post::Post::new(&device, config.format.remove_srgb_suffix());
Ok(Self {
instance,
surface,
offscreen,
in_flight: std::collections::VecDeque::new(),
gpu_timer,
gpu_times: Vec::new(),
last_wait: std::time::Duration::ZERO,
last_encode: std::time::Duration::ZERO,
window,
device,
queue,
@@ -1135,6 +1224,11 @@ impl Renderer {
lightmap,
sprite_texture,
mip_levels,
mipmaps: mip_levels - 1,
terrain_layout: bindings,
sprite_sampler,
lightmap_view,
lightmap_sampler,
animations: animations.iter().map(|a| (a.clone(), usize::MAX)).collect(),
indices,
index_quads,
@@ -1143,11 +1237,17 @@ impl Renderer {
outline,
depth,
sections: HashMap::new(),
arena,
indirect,
indirect_capacity: 1024,
multi_draw,
visible: Vec::new(),
origins: Vec::new(),
draws: Vec::new(),
draw_pages: Vec::new(),
block_entities: HashMap::new(),
visibility: HashMap::new(),
reachable: std::collections::HashSet::new(),
reachable_from: None,
visibility_dirty: true,
occlusion: occlusion::Occlusion::new(crate::chunk::HEIGHT / 16),
world_post,
hud,
post: None,
info,
@@ -1158,6 +1258,7 @@ impl Renderer {
screenshot: None,
screenshot_result: None,
gamma: 0.5,
animated_textures: true,
present_modes,
})
}
@@ -1174,6 +1275,29 @@ impl Renderer {
usage: wgpu::BufferUsages::INDEX,
})
}
fn offscreen_target(
device: &wgpu::Device,
config: &wgpu::SurfaceConfiguration,
) -> wgpu::Texture {
device.create_texture(&wgpu::TextureDescriptor {
label: Some("Offscreen frame"),
size: wgpu::Extent3d {
width: config.width,
height: config.height,
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: config.format,
usage: config.usage,
view_formats: &config.view_formats,
})
}
/// Rendering to a texture instead of the window (`--offscreen`).
pub fn is_offscreen(&self) -> bool {
self.surface.is_none()
}
fn depth(device: &wgpu::Device, config: &wgpu::SurfaceConfiguration) -> wgpu::TextureView {
device
.create_texture(&wgpu::TextureDescriptor {
@@ -1193,6 +1317,27 @@ impl Renderer {
.create_view(&Default::default())
}
/// VSync on: tear-free presentation (Mailbox, else Fifo); off: Immediate when available.
/// VSync, unless Horizon's present-mode setting names a supported mode.
pub fn set_present_mode(&mut self, vsync: bool, mode: crate::graphics::PresentMode) {
use crate::graphics::PresentMode as P;
let wanted = match mode {
P::Auto => None,
P::Fifo => Some(wgpu::PresentMode::Fifo),
P::Mailbox => Some(wgpu::PresentMode::Mailbox),
P::Immediate => Some(wgpu::PresentMode::Immediate),
};
match wanted.filter(|m| self.present_modes.contains(m)) {
Some(m) => {
if self.config.present_mode != m
&& let Some(surface) = &self.surface
{
self.config.present_mode = m;
surface.configure(&self.device, &self.config);
}
}
None => self.set_vsync(vsync),
}
}
pub fn set_vsync(&mut self, vsync: bool) {
use crate::window::{PresentMode, vsync_present_mode};
let supported: Vec<PresentMode> = self
@@ -1211,9 +1356,11 @@ impl Renderer {
Some(PresentMode::Immediate) => wgpu::PresentMode::Immediate,
_ => wgpu::PresentMode::Fifo,
};
if self.config.present_mode != mode {
if self.config.present_mode != mode
&& let Some(surface) = &self.surface
{
self.config.present_mode = mode;
self.surface.configure(&self.device, &self.config);
surface.configure(&self.device, &self.config);
}
}
pub fn resize(&mut self, width: u32, height: u32) {
@@ -1223,16 +1370,18 @@ impl Renderer {
}
self.config.width = width;
self.config.height = height;
self.surface.configure(&self.device, &self.config);
if let Some(surface) = &self.surface {
surface.configure(&self.device, &self.config);
} else {
self.offscreen = Some(Self::offscreen_target(&self.device, &self.config));
}
self.depth = Self::depth(&self.device, &self.config);
}
pub fn section_count(&self) -> usize {
self.sections.len()
}
pub fn upload(&mut self, key: SectionKey, mesh: &SectionMesh) {
if self.visibility.insert(key, mesh.visibility) != Some(mesh.visibility) {
self.visibility_dirty = true;
}
self.occlusion.set(key, mesh.visibility);
if mesh.block_entities.is_empty() {
self.block_entities.remove(&key);
} else {
@@ -1240,8 +1389,8 @@ impl Renderer {
}
let solid = (mesh.solid.len() / 4) as u32;
let translucent = (mesh.translucent.len() / 4) as u32;
self.release_section(key);
if solid + translucent == 0 {
self.sections.remove(&key);
return;
}
let max = solid.max(translucent);
@@ -1249,27 +1398,59 @@ impl Renderer {
self.index_quads = max.next_power_of_two();
self.indices = Self::quad_indices(&self.device, self.index_quads);
}
let mut data = Vec::with_capacity(mesh.solid.len() + mesh.translucent.len());
data.extend_from_slice(&mesh.solid);
data.extend_from_slice(&mesh.translucent);
let bytes: &[u8] = bytemuck::cast_slice(&data);
self.uploaded_bytes += bytes.len() as u64;
let buffer = self
.device
.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("Section mesh"),
contents: bytes,
usage: wgpu::BufferUsages::VERTEX,
});
let vertices = (mesh.solid.len() + mesh.translucent.len()) as u64;
let (page, start) = self.arena.alloc(&self.device, &self.queue, vertices);
let stride = std::mem::size_of::<Vertex>() as u64;
for (offset, part) in [(0, &mesh.solid), (mesh.solid.len(), &mesh.translucent)] {
if !part.is_empty() {
let bytes: &[u8] = bytemuck::cast_slice(part);
self.uploaded_bytes += bytes.len() as u64;
self.queue.write_buffer(
self.arena.buffer(page),
(start + offset as u64) * stride,
bytes,
);
}
}
self.sections.insert(
key,
SectionGpu {
buffer,
page,
start,
solid,
translucent,
},
);
}
/// Draws `count` section draws from `first` with the arena and section
/// origins bound: one indirect multi-draw, or a loop without it.
/// Consecutive draws in one arena page share a vertex buffer binding,
/// keeping the list's order (translucent sections go back to front).
fn draw_sections(&self, pass: &mut wgpu::RenderPass<'_>, first: u32, count: u32) {
let (mut i, end) = (first as usize, (first + count) as usize);
while i < end {
let page = self.draw_pages[i];
let run = self.draw_pages[i..end]
.iter()
.take_while(|&&p| p == page)
.count();
pass.set_vertex_buffer(0, self.arena.buffer(page).slice(..));
if self.multi_draw {
pass.multi_draw_indexed_indirect(&self.indirect, i as u64 * 20, run as u32);
} else {
for d in &self.draws[i..i + run] {
pass.draw_indexed(0..d[0], d[3] as i32, d[4]..d[4] + 1);
}
}
i += run;
}
}
fn release_section(&mut self, key: SectionKey) {
if let Some(s) = self.sections.remove(&key) {
self.arena
.release(s.page, s.start, u64::from(s.solid + s.translucent) * 4);
}
}
/// Block-entity blocks of every meshed section (see `SectionMesh::block_entities`).
pub fn block_entities(&self) -> impl Iterator<Item = &([i32; 3], u32)> {
self.block_entities.values().flatten()
@@ -1277,76 +1458,95 @@ impl Renderer {
pub fn clear_sections(&mut self) {
self.block_entities.clear();
self.sections.clear();
self.visibility.clear();
self.visibility_dirty = true;
}
/// SectionOcclusionGraph: breadth-first from the camera section through
/// faces its VisGraph connects, never stepping back towards the camera.
fn update_reachable(&mut self, from: SectionKey, radius: i32) {
const STEPS: [(i32, i32, i32); 6] = [
(0, -1, 0),
(0, 1, 0),
(0, 0, -1),
(0, 0, 1),
(-1, 0, 0),
(1, 0, 0),
];
let opposite = |d: usize| d ^ 1;
self.reachable.clear();
let mut queue = std::collections::VecDeque::new();
// (section, entered face, directions travelled)
queue.push_back((from, None::<usize>, 0u8));
self.reachable.insert(from);
let sections = crate::chunk::HEIGHT / 16;
while let Some((key, entered, travelled)) = queue.pop_front() {
let vis = self
.visibility
.get(&key)
.copied()
.unwrap_or(crate::mesher::ALL_VISIBLE);
for (d, step) in STEPS.iter().enumerate() {
if travelled & (1 << opposite(d)) != 0 {
continue;
}
if let Some(e) = entered
&& vis & (1 << (e * 6 + d)) == 0
{
continue;
}
let next = (key.0 + step.0, key.1 + step.1, key.2 + step.2);
if next.1 < -1
|| next.1 > sections
|| (next.0 - from.0).abs() > radius
|| (next.2 - from.2).abs() > radius
{
continue;
}
if self.reachable.insert(next) {
queue.push_back((next, Some(opposite(d)), travelled | (1 << d)));
}
}
}
self.reachable_from = Some(from);
self.visibility_dirty = false;
self.arena.clear();
self.occlusion.clear();
}
pub fn remove(&mut self, key: SectionKey) {
self.block_entities.remove(&key);
self.visibility.remove(&key);
self.visibility_dirty = true;
self.sections.remove(&key);
self.occlusion.remove(key);
self.release_section(key);
}
/// Horizon's resolution scale (world pixels per window pixel) and FXAA.
pub fn set_world_post(&mut self, scale: f32, antialias: bool) {
self.world_post.scale = scale.clamp(0.25, 2.0);
self.world_post.antialias = antialias;
}
/// The Mipmap Levels option: block textures sample at most `levels`
/// reduced copies (0: none).
pub fn set_mipmap_levels(&mut self, levels: u32) {
let levels = levels.min(self.mip_levels - 1);
if levels == self.mipmaps {
return;
}
self.mipmaps = levels;
let sprite_view = self
.sprite_texture
.create_view(&wgpu::TextureViewDescriptor {
dimension: Some(wgpu::TextureViewDimension::D2Array),
mip_level_count: Some(levels + 1),
..Default::default()
});
self.group = self.device.create_bind_group(&wgpu::BindGroupDescriptor {
label: Some("Horizon terrain resources"),
layout: &self.terrain_layout,
entries: &[
wgpu::BindGroupEntry {
binding: 0,
resource: self.globals.as_entire_binding(),
},
wgpu::BindGroupEntry {
binding: 1,
resource: wgpu::BindingResource::TextureView(&sprite_view),
},
wgpu::BindGroupEntry {
binding: 2,
resource: wgpu::BindingResource::Sampler(&self.sprite_sampler),
},
wgpu::BindGroupEntry {
binding: 3,
resource: wgpu::BindingResource::TextureView(&self.lightmap_view),
},
wgpu::BindGroupEntry {
binding: 4,
resource: wgpu::BindingResource::Sampler(&self.lightmap_sampler),
},
],
});
}
pub fn view_projection(&self, frame: &Frame) -> Mat4 {
self.projection(
frame.fov_degrees,
frame.yaw,
frame.pitch,
frame.bob,
frame.distance,
)
}
/// The view frustum `render` will cull with, for culling geometry built
/// before the frame (entities, block entities) the same way.
pub fn camera_frustum(
&self,
fov_degrees: f32,
yaw: f32,
pitch: f32,
bob: Mat4,
distance: f32,
) -> Frustum {
Frustum {
planes: frustum(self.projection(fov_degrees, yaw, pitch, bob, distance)),
}
}
fn projection(&self, fov_degrees: f32, yaw: f32, pitch: f32, bob: Mat4, distance: f32) -> Mat4 {
let aspect = self.config.width as f32 / self.config.height.max(1) as f32;
let (yaw, pitch) = (frame.yaw.to_radians(), frame.pitch.to_radians());
let (yaw, pitch) = (yaw.to_radians(), pitch.to_radians());
// Minecraft yaw: 0 = +Z (south), 90 = -X (west); pitch positive looks down.
let forward = Vec3::new(
-yaw.sin() * pitch.cos(),
-pitch.sin(),
yaw.cos() * pitch.cos(),
);
let far = (frame.distance * 4.0).max(1024.0);
let bob = frame.bob;
Mat4::perspective_rh(frame.fov_degrees.to_radians(), aspect, 0.05, far)
let far = (distance * 4.0).max(1024.0);
Mat4::perspective_rh(fov_degrees.to_radians(), aspect, 0.05, far)
* bob
* Mat4::look_to_rh(Vec3::ZERO, forward, Vec3::Y)
}
@@ -1451,26 +1651,40 @@ impl Renderer {
if self.suspended {
return Ok(false);
}
let (surface_frame, reconfigure) = match self.surface.get_current_texture() {
wgpu::CurrentSurfaceTexture::Success(f) => (f, false),
wgpu::CurrentSurfaceTexture::Suboptimal(f) => (f, true),
wgpu::CurrentSurfaceTexture::Timeout | wgpu::CurrentSurfaceTexture::Occluded => {
let started = Instant::now();
let acquire = Instant::now();
let acquired = self.surface.as_ref().map(|s| s.get_current_texture());
self.last_wait = acquire.elapsed();
let (surface_frame, reconfigure) = match acquired {
None => (None, false),
Some(wgpu::CurrentSurfaceTexture::Success(f)) => (Some(f), false),
Some(wgpu::CurrentSurfaceTexture::Suboptimal(f)) => (Some(f), true),
Some(wgpu::CurrentSurfaceTexture::Timeout | wgpu::CurrentSurfaceTexture::Occluded) => {
return Ok(false);
}
wgpu::CurrentSurfaceTexture::Outdated => {
self.surface.configure(&self.device, &self.config);
Some(wgpu::CurrentSurfaceTexture::Outdated) => {
if let Some(surface) = &self.surface {
surface.configure(&self.device, &self.config);
}
return Ok(false);
}
wgpu::CurrentSurfaceTexture::Lost => {
self.surface = self.instance.create_surface(self.window.clone())?;
self.surface.configure(&self.device, &self.config);
Some(wgpu::CurrentSurfaceTexture::Lost) => {
let surface = self.instance.create_surface(self.window.clone())?;
surface.configure(&self.device, &self.config);
self.surface = Some(surface);
return Ok(false);
}
wgpu::CurrentSurfaceTexture::Validation => {
Some(wgpu::CurrentSurfaceTexture::Validation) => {
return Err("surface acquisition failed validation".into());
}
};
self.animate(frame.ticks);
let target_texture = match &surface_frame {
Some(f) => f.texture.clone(),
None => self.offscreen.clone().ok_or("no offscreen target")?,
};
if self.animated_textures {
self.animate(frame.ticks);
}
self.update_lightmap(
&frame.sky,
frame.darkness.1,
@@ -1571,7 +1785,9 @@ impl Renderer {
self.queue
.write_buffer(&self.hand_globals, 0, bytemuck::bytes_of(&hand_globals));
// Frustum culling and camera-relative origins.
let planes = frustum(view_proj);
let view = Frustum {
planes: frustum(view_proj),
};
let camera = frame.camera;
let camera_section = (
(camera.x.floor() as i32) >> 4,
@@ -1579,46 +1795,41 @@ impl Renderer {
(camera.z.floor() as i32) >> 4,
);
let culling = !frame.title && frame.cave_culling;
if culling && (self.visibility_dirty || self.reachable_from != Some(camera_section)) {
if culling {
let radius = (frame.distance / 16.0) as i32 + 2;
self.update_reachable(camera_section, radius);
self.occlusion.update(camera_section, radius);
}
let reachable = &self.reachable;
let mut visible: Vec<(SectionKey, f64, [f32; 3])> = self
.sections
.keys()
.filter(|k| !culling || reachable.contains(k))
.filter_map(|&(sx, sy, sz)| {
let origin = DVec3::new(
f64::from(sx * 16),
f64::from(crate::chunk::MIN_Y + sy * 16),
f64::from(sz * 16),
) - camera;
let center = origin + DVec3::splat(8.0);
let horizontal = (center.x * center.x + center.z * center.z).sqrt();
if horizontal > f64::from(frame.distance) + 24.0 {
return None;
}
let min = origin.as_vec3();
let max = min + Vec3::splat(16.0);
if planes.iter().any(|p| {
let v = Vec3::new(
if p.x >= 0.0 { max.x } else { min.x },
if p.y >= 0.0 { max.y } else { min.y },
if p.z >= 0.0 { max.z } else { min.z },
);
p.truncate().dot(v) + p.w < 0.0
}) {
return None;
}
Some((
(sx, sy, sz),
center.length_squared(),
origin.as_vec3().to_array(),
))
})
.collect();
visible.sort_by(|a, b| a.1.total_cmp(&b.1));
let reachable = &self.occlusion;
let mut visible = std::mem::take(&mut self.visible);
visible.clear();
visible.extend(
self.sections
.keys()
.filter(|&&k| !culling || reachable.contains(k))
.filter_map(|&(sx, sy, sz)| {
let origin = DVec3::new(
f64::from(sx * 16),
f64::from(crate::chunk::MIN_Y + sy * 16),
f64::from(sz * 16),
) - camera;
let center = origin + DVec3::splat(8.0);
let horizontal = (center.x * center.x + center.z * center.z).sqrt();
if horizontal > f64::from(frame.distance) + 24.0 {
return None;
}
let min = origin.as_vec3();
let max = min + Vec3::splat(16.0);
if !view.intersects(min, max) {
return None;
}
Some((
(sx, sy, sz),
center.length_squared(),
origin.as_vec3().to_array(),
))
}),
);
visible.sort_unstable_by(|a, b| a.1.total_cmp(&b.1));
self.drawn_sections = visible.len();
if visible.len() as u64 > self.instance_capacity {
self.instance_capacity = (visible.len() as u64).next_power_of_two();
@@ -1629,13 +1840,54 @@ impl Renderer {
mapped_at_creation: false,
});
}
let origins: Vec<[f32; 4]> = visible
.iter()
.map(|(_, _, o)| [o[0], o[1], o[2], 0.0])
.collect();
if !origins.is_empty() {
self.origins.clear();
self.origins
.extend(visible.iter().map(|(_, _, o)| [o[0], o[1], o[2], 0.0]));
if !self.origins.is_empty() {
self.queue
.write_buffer(&self.instances, 0, bytemuck::cast_slice(&origins));
.write_buffer(&self.instances, 0, bytemuck::cast_slice(&self.origins));
}
if frame.title {
visible.clear();
}
// Solid sections front to back, then translucent ones back to front,
// as one list of indirect draws over the section arena.
self.draws.clear();
self.draw_pages.clear();
let draw = |s: &SectionGpu, i: usize, translucent: bool| {
let (quads, first) = if translucent {
(s.translucent, s.start + u64::from(s.solid) * 4)
} else {
(s.solid, s.start)
};
(quads > 0).then_some(([quads * 6, 1, 0, first as u32, i as u32], s.page))
};
for (i, (key, _, _)) in visible.iter().enumerate() {
if let Some((d, page)) = draw(&self.sections[key], i, false) {
self.draws.push(d);
self.draw_pages.push(page);
}
}
let solid_draws = self.draws.len() as u32;
for (i, (key, _, _)) in visible.iter().enumerate().rev() {
if let Some((d, page)) = draw(&self.sections[key], i, true) {
self.draws.push(d);
self.draw_pages.push(page);
}
}
let translucent_draws = self.draws.len() as u32 - solid_draws;
if self.multi_draw && !self.draws.is_empty() {
if self.draws.len() as u64 > self.indirect_capacity {
self.indirect_capacity = (self.draws.len() as u64).next_power_of_two();
self.indirect = self.device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Section draws"),
size: self.indirect_capacity * 20,
usage: wgpu::BufferUsages::INDIRECT | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
}
self.queue
.write_buffer(&self.indirect, 0, bytemuck::cast_slice(&self.draws));
}
let outline_edges = frame.outline.len().min(MAX_OUTLINE_EDGES as usize);
if outline_edges > 0 {
@@ -1728,20 +1980,29 @@ impl Renderer {
self.queue
.write_buffer(&self.border_uniform, 0, bytemuck::bytes_of(&uniform));
}
let view_target = surface_frame
.texture
.create_view(&wgpu::TextureViewDescriptor {
format: Some(self.config.format.remove_srgb_suffix()),
..Default::default()
});
let view_target = target_texture.create_view(&wgpu::TextureViewDescriptor {
format: Some(self.config.format.remove_srgb_suffix()),
..Default::default()
});
let mut encoder = self
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("Horizon frame"),
});
if let Some(timer) = &mut self.gpu_timer {
timer.begin(&mut encoder);
}
// The world's targets: the screen, or the scaled target of `post`.
let scaled = self
.world_post
.prepare(&self.device, [self.config.width, self.config.height]);
let (world_view, world_depth) = match &scaled {
Some((color, depth)) => (color, depth),
None => (&view_target, &self.depth),
};
{
let attachments = [Some(wgpu::RenderPassColorAttachment {
view: &view_target,
view: world_view,
resolve_target: None,
depth_slice: None,
ops: wgpu::Operations {
@@ -1764,7 +2025,7 @@ impl Renderer {
label: Some("Horizon world"),
color_attachments: &attachments,
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth,
view: world_depth,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
store: wgpu::StoreOp::Discard,
@@ -1797,20 +2058,10 @@ impl Renderer {
pass.draw(0..3, 0..1);
}
}
if frame.title {
visible.clear();
}
pass.set_pipeline(&self.solid);
pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32);
pass.set_vertex_buffer(1, self.instances.slice(..));
for (i, (key, _, _)) in visible.iter().enumerate() {
let s = &self.sections[key];
if s.solid == 0 {
continue;
}
pass.set_vertex_buffer(0, s.buffer.slice(..));
pass.draw_indexed(0..s.solid * 6, 0, i as u32..i as u32 + 1);
}
self.draw_sections(&mut pass, 0, solid_draws);
if entity_quads > 0 {
pass.set_pipeline(&self.entity_pipeline);
pass.set_bind_group(0, &self.entity_group, &[]);
@@ -1831,19 +2082,9 @@ impl Renderer {
pass.draw(0..outline_edges as u32 * 2, 0..1);
}
pass.set_pipeline(&self.translucent);
pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32);
pass.set_vertex_buffer(1, self.instances.slice(..));
for (i, (key, _, _)) in visible.iter().enumerate().rev() {
let s = &self.sections[key];
if s.translucent == 0 {
continue;
}
pass.set_vertex_buffer(0, s.buffer.slice(..));
pass.draw_indexed(
0..s.translucent * 6,
(s.solid * 4) as i32,
i as u32..i as u32 + 1,
);
}
self.draw_sections(&mut pass, solid_draws, translucent_draws);
// LevelRenderer: the world border after translucent terrain and weather.
if let Some(b) = frame.border.as_ref().filter(|_| !frame.title) {
pass.set_pipeline(&self.border_pipeline);
@@ -1857,6 +2098,9 @@ impl Renderer {
pass.set_bind_group(0, &self.group, &[]);
}
}
if scaled.is_some() {
self.world_post.finish(&mut encoder, &view_target);
}
if hand_quads > 0 {
let attachments = [Some(wgpu::RenderPassColorAttachment {
view: &view_target,
@@ -1942,7 +2186,7 @@ impl Renderer {
&self.device,
&self.queue,
&mut encoder,
&surface_frame.texture,
&target_texture,
&view_target,
[self.config.width, self.config.height],
grade,
@@ -1956,23 +2200,46 @@ impl Renderer {
frame.hud,
[self.config.width, self.config.height],
);
if let Some(timer) = &mut self.gpu_timer {
timer.end(&mut encoder);
}
let readback = self
.screenshot
.take()
.map(|path| (path, self.copy_frame(&mut encoder, &surface_frame.texture)));
self.queue.submit([encoder.finish()]);
.map(|path| (path, self.copy_frame(&mut encoder, &target_texture)));
let submission = self.queue.submit([encoder.finish()]);
if let Some(timer) = &mut self.gpu_timer {
timer.submitted();
timer.collect(&self.device, &mut self.gpu_times);
}
if let Some((path, buffer)) = readback {
self.screenshot_result = Some(
self.write_screenshot(&path, &buffer)
.map_err(|e| e.to_string()),
);
}
self.window.pre_present_notify();
self.queue.present(surface_frame);
if reconfigure {
self.surface.configure(&self.device, &self.config);
let present = Instant::now();
if let Some(surface_frame) = surface_frame {
self.window.pre_present_notify();
self.queue.present(surface_frame);
if reconfigure && let Some(surface) = &self.surface {
surface.configure(&self.device, &self.config);
}
} else {
// No swapchain paces offscreen frames: keep two on the GPU at most.
self.in_flight.push_back(submission);
while self.in_flight.len() > 2 {
let index = self.in_flight.pop_front();
let _ = self.device.poll(wgpu::PollType::Wait {
submission_index: index,
timeout: Some(std::time::Duration::from_secs(5)),
});
}
}
self.last_wait += present.elapsed();
self.last_encode = started.elapsed().saturating_sub(self.last_wait);
let _ = self.started;
self.visible = visible;
Ok(true)
}
}
@@ -2058,6 +2325,24 @@ impl Renderer {
Ok([width, height])
}
}
/// Camera-relative clip planes (`Frustum`).
#[derive(Clone, Copy, Debug)]
pub struct Frustum {
planes: [Vec4; 6],
}
impl Frustum {
/// Whether the camera-relative box `min..max` is at least partly inside.
pub fn intersects(&self, min: Vec3, max: Vec3) -> bool {
!self.planes.iter().any(|p| {
let v = Vec3::new(
if p.x >= 0.0 { max.x } else { min.x },
if p.y >= 0.0 { max.y } else { min.y },
if p.z >= 0.0 { max.z } else { min.z },
);
p.truncate().dot(v) + p.w < 0.0
})
}
}
fn frustum(m: Mat4) -> [Vec4; 6] {
let r = |i| m.row(i);
let planes = [
+180
View File
@@ -0,0 +1,180 @@
//! One vertex buffer for every terrain section: sections own ranges of it, so
//! a frame binds it once and draws every section with indirect multi-draw.
use std::collections::BTreeMap;
/// Ranges are rounded up to this many vertices to limit fragmentation.
const GRAIN: u64 = 256;
/// Free vertex ranges: start -> length, never adjacent.
#[derive(Debug, PartialEq)]
struct FreeList(BTreeMap<u64, u64>);
impl FreeList {
fn new(capacity: u64) -> Self {
Self(BTreeMap::from([(0, capacity)]))
}
/// First fit.
fn take(&mut self, len: u64) -> Option<u64> {
let (&start, &free) = self.0.iter().find(|(_, l)| **l >= len)?;
self.0.remove(&start);
if free > len {
self.0.insert(start + len, free - len);
}
Some(start)
}
fn give(&mut self, start: u64, len: u64) {
let (mut start, mut len) = (start, len);
if let Some((&prev, &prev_len)) = self.0.range(..start).next_back()
&& prev + prev_len == start
{
self.0.remove(&prev);
start = prev;
len += prev_len;
}
if let Some(next_len) = self.0.remove(&(start + len)) {
len += next_len;
}
self.0.insert(start, len);
}
}
/// One vertex buffer of the arena; only the newest page grows.
struct Page {
buffer: wgpu::Buffer,
/// Capacity in vertices.
capacity: u64,
free: FreeList,
}
/// Terrain vertices in pages of at most `page_limit` vertices (devices cap
/// buffer sizes): a section's vertices sit in one page.
pub struct Arena {
pages: Vec<Page>,
stride: u64,
page_limit: u64,
}
impl Arena {
pub fn new(device: &wgpu::Device, stride: u64, capacity: u64) -> Self {
// 256 MiB pages, or less where the device's buffers are smaller.
let bytes = device.limits().max_buffer_size.min(256 << 20);
let page_limit = (bytes / stride) / GRAIN * GRAIN;
let capacity = capacity.next_multiple_of(GRAIN).min(page_limit);
Self {
pages: vec![Page {
buffer: Self::create(device, stride, capacity),
capacity,
free: FreeList::new(capacity),
}],
stride,
page_limit,
}
}
fn create(device: &wgpu::Device, stride: u64, capacity: u64) -> wgpu::Buffer {
device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Section vertex arena"),
size: capacity * stride,
usage: wgpu::BufferUsages::VERTEX
| wgpu::BufferUsages::COPY_DST
| wgpu::BufferUsages::COPY_SRC,
mapped_at_creation: false,
})
}
/// The rounded length a request of `vertices` occupies.
fn span(vertices: u64) -> u64 {
vertices.max(1).next_multiple_of(GRAIN)
}
pub fn buffer(&self, page: u32) -> &wgpu::Buffer {
&self.pages[page as usize].buffer
}
/// A range of `vertices`: (page, first vertex). Grows the newest page
/// (copying its contents on the GPU) or starts a new one when nothing
/// free is large enough.
pub fn alloc(
&mut self,
device: &wgpu::Device,
queue: &wgpu::Queue,
vertices: u64,
) -> (u32, u64) {
let len = Self::span(vertices).min(self.page_limit);
for (i, page) in self.pages.iter_mut().enumerate() {
if let Some(start) = page.free.take(len) {
return (i as u32, start);
}
}
let last = self.pages.len() - 1;
let current = self.pages[last].capacity;
if current < self.page_limit {
let grown = (current * 2).max(current + len).min(self.page_limit);
if grown - current >= len || grown == self.page_limit {
self.grow(device, queue, last, grown);
if let Some(start) = self.pages[last].free.take(len) {
return (last as u32, start);
}
}
}
let capacity = (1 << 20u64).max(len).min(self.page_limit);
let mut free = FreeList::new(capacity);
let start = free.take(len).expect("a new page fits one section");
self.pages.push(Page {
buffer: Self::create(device, self.stride, capacity),
capacity,
free,
});
((self.pages.len() - 1) as u32, start)
}
pub fn release(&mut self, page: u32, start: u64, vertices: u64) {
let len = Self::span(vertices).min(self.page_limit);
self.pages[page as usize].free.give(start, len);
}
fn grow(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, page: usize, capacity: u64) {
let capacity = capacity.next_multiple_of(GRAIN).min(self.page_limit);
let buffer = Self::create(device, self.stride, capacity);
let old = &mut self.pages[page];
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("Grow section arena"),
});
encoder.copy_buffer_to_buffer(&old.buffer, 0, &buffer, 0, old.capacity * self.stride);
// Writes queued for the old buffer run before this copy.
queue.submit([encoder.finish()]);
let previous = old.capacity;
old.buffer = buffer;
old.capacity = capacity;
old.free.give(previous, capacity - previous);
}
pub fn clear(&mut self) {
for page in &mut self.pages {
page.free = FreeList::new(page.capacity);
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn free_ranges_coalesce() {
let mut free = FreeList::new(4 * GRAIN);
let a = free.take(GRAIN).unwrap();
let b = free.take(2 * GRAIN).unwrap();
let c = free.take(GRAIN).unwrap();
assert_eq!((a, b, c), (0, GRAIN, 3 * GRAIN));
assert_eq!(free.take(1), None);
free.give(a, GRAIN);
free.give(c, GRAIN);
// Two holes of one grain: a two-grain request does not fit.
assert_eq!(free.take(2 * GRAIN), None);
free.give(b, 2 * GRAIN);
assert_eq!(free, FreeList::new(4 * GRAIN));
}
#[test]
fn first_fit_reuses_the_lowest_hole() {
let mut free = FreeList::new(8 * GRAIN);
let a = free.take(GRAIN).unwrap();
let _b = free.take(GRAIN).unwrap();
free.give(a, GRAIN);
assert_eq!(free.take(GRAIN), Some(a));
}
}
+196
View File
@@ -0,0 +1,196 @@
//! `SectionOcclusionGraph`: which sections the camera can see through open
//! faces. Breadth-first from the camera section through the faces each
//! section's VisGraph connects, never stepping back towards the camera.
//!
//! The search runs over dense arrays around the camera rather than hash sets,
//! so it stays cheap enough to redo whenever a section is meshed.
use super::SectionKey;
use std::collections::{HashMap, VecDeque};
const STEPS: [(i32, i32, i32); 6] = [
(0, -1, 0),
(0, 1, 0),
(0, 0, -1),
(0, 0, 1),
(-1, 0, 0),
(1, 0, 0),
];
const NONE: u8 = 6;
pub struct Occlusion {
/// VisGraph connectivity per column, one entry per section (bottom first).
columns: HashMap<(i32, i32), Box<[u64]>>,
sections: i32,
dirty: bool,
from: Option<SectionKey>,
radius: i32,
/// The searched box: lowest section y and its height in sections.
y0: i32,
height: i32,
reached: Vec<bool>,
vis: Vec<u64>,
queue: VecDeque<(u32, u8, u8)>,
}
impl Occlusion {
pub fn new(sections: i32) -> Self {
Self {
columns: HashMap::new(),
sections,
dirty: true,
from: None,
radius: 0,
y0: 0,
height: 0,
reached: Vec::new(),
vis: Vec::new(),
queue: VecDeque::new(),
}
}
pub fn set(&mut self, key: SectionKey, vis: u64) {
if !(0..self.sections).contains(&key.1) {
return;
}
let sections = self.sections as usize;
let column = self
.columns
.entry((key.0, key.2))
.or_insert_with(|| vec![crate::mesher::ALL_VISIBLE; sections].into());
let slot = &mut column[key.1 as usize];
if *slot != vis {
*slot = vis;
self.dirty = true;
}
}
pub fn remove(&mut self, key: SectionKey) {
let Some(column) = self.columns.get_mut(&(key.0, key.2)) else {
return;
};
if let Some(slot) = column.get_mut(key.1 as usize)
&& *slot != crate::mesher::ALL_VISIBLE
{
*slot = crate::mesher::ALL_VISIBLE;
self.dirty = true;
}
if column.iter().all(|&v| v == crate::mesher::ALL_VISIBLE) {
self.columns.remove(&(key.0, key.2));
}
}
pub fn clear(&mut self) {
self.columns.clear();
self.dirty = true;
}
fn index(&self, key: SectionKey) -> Option<usize> {
let from = self.from?;
let (dx, dz, dy) = (key.0 - from.0, key.2 - from.2, key.1 - self.y0);
let side = 2 * self.radius + 1;
if dx.abs() > self.radius || dz.abs() > self.radius || !(0..self.height).contains(&dy) {
return None;
}
Some((((dz + self.radius) * side + dx + self.radius) * self.height + dy) as usize)
}
fn key(&self, index: usize) -> SectionKey {
let from = self.from.expect("searched");
let side = 2 * self.radius + 1;
let i = index as i32;
let dy = i % self.height;
let column = i / self.height;
(
from.0 + column % side - self.radius,
self.y0 + dy,
from.2 + column / side - self.radius,
)
}
pub fn contains(&self, key: SectionKey) -> bool {
self.index(key).is_some_and(|i| self.reached[i])
}
/// Search again when sections changed or the camera moved to another section.
pub fn update(&mut self, from: SectionKey, radius: i32) {
if !self.dirty && self.from == Some(from) && self.radius == radius {
return;
}
self.from = Some(from);
self.radius = radius;
self.y0 = from.1.min(-1);
self.height = from.1.max(self.sections) - self.y0 + 1;
let side = (2 * radius + 1) as usize;
let size = side * side * self.height as usize;
self.reached.clear();
self.reached.resize(size, false);
self.vis.clear();
self.vis.resize(size, crate::mesher::ALL_VISIBLE);
for dz in -radius..=radius {
for dx in -radius..=radius {
let Some(column) = self.columns.get(&(from.0 + dx, from.2 + dz)) else {
continue;
};
let base = self
.index((from.0 + dx, 0, from.2 + dz))
.expect("column inside the searched box");
self.vis[base..base + column.len()].copy_from_slice(column);
}
}
let start = self.index(from).expect("camera inside the searched box");
self.reached[start] = true;
self.queue.clear();
self.queue.push_back((start as u32, NONE, 0));
while let Some((index, entered, travelled)) = self.queue.pop_front() {
let vis = self.vis[index as usize];
let key = self.key(index as usize);
for (d, step) in STEPS.iter().enumerate() {
let opposite = d ^ 1;
if travelled & (1 << opposite) != 0 {
continue;
}
if entered != NONE && vis & (1 << (usize::from(entered) * 6 + d)) == 0 {
continue;
}
let next = (key.0 + step.0, key.1 + step.1, key.2 + step.2);
if next.1 < -1 || next.1 > self.sections {
continue;
}
let Some(n) = self.index(next) else { continue };
if !self.reached[n] {
self.reached[n] = true;
self.queue
.push_back((n as u32, opposite as u8, travelled | (1 << d)));
}
}
}
self.dirty = false;
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::mesher::ALL_VISIBLE;
#[test]
fn open_space_reaches_the_whole_box() {
let mut o = Occlusion::new(4);
o.update((0, 1, 0), 2);
for x in -2..=2 {
for z in -2..=2 {
for y in -1..=4 {
assert!(o.contains((x, y, z)), "{x} {y} {z}");
}
}
}
assert!(!o.contains((3, 1, 0)));
}
#[test]
fn closed_neighbours_hide_what_is_behind_them() {
let mut o = Occlusion::new(4);
for (dx, dy, dz) in STEPS {
o.set((dx, 1 + dy, dz), 0);
}
o.update((0, 1, 0), 3);
assert!(o.contains((1, 1, 0)), "a neighbour is seen");
assert!(!o.contains((2, 1, 0)), "nothing shows through it");
o.set((1, 1, 0), ALL_VISIBLE);
o.update((0, 1, 0), 3);
assert!(o.contains((2, 1, 0)));
}
}
+125
View File
@@ -0,0 +1,125 @@
//! GPU frame time from timestamp queries, read back a few frames late so the
//! CPU never waits for it. Frames whose readback slot is still busy go untimed.
use std::sync::{
Arc,
atomic::{AtomicU8, Ordering},
};
const SLOTS: usize = 4;
const FREE: u8 = 0;
const PENDING: u8 = 1;
const MAPPED: u8 = 2;
struct Slot {
buffer: wgpu::Buffer,
state: Arc<AtomicU8>,
}
pub struct GpuTimer {
queries: wgpu::QuerySet,
resolve: wgpu::Buffer,
slots: Vec<Slot>,
/// The slot this frame writes into, when one was free at `begin`.
current: Option<usize>,
next: usize,
period_ns: f32,
}
impl GpuTimer {
/// The features timing needs; `None` when the adapter lacks them.
pub fn features(adapter: &wgpu::Adapter) -> wgpu::Features {
let wanted =
wgpu::Features::TIMESTAMP_QUERY | wgpu::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS;
if adapter.features().contains(wanted) {
wanted
} else {
wgpu::Features::empty()
}
}
pub fn new(device: &wgpu::Device, queue: &wgpu::Queue) -> Option<Self> {
if !device
.features()
.contains(wgpu::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS)
{
return None;
}
let queries = device.create_query_set(&wgpu::QuerySetDescriptor {
label: Some("Frame timestamps"),
ty: wgpu::QueryType::Timestamp,
count: 2,
});
let resolve = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Frame timestamp resolve"),
size: 16,
usage: wgpu::BufferUsages::QUERY_RESOLVE | wgpu::BufferUsages::COPY_SRC,
mapped_at_creation: false,
});
let slots = (0..SLOTS)
.map(|_| Slot {
buffer: device.create_buffer(&wgpu::BufferDescriptor {
label: Some("Frame timestamp readback"),
size: 16,
usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
}),
state: Arc::new(AtomicU8::new(FREE)),
})
.collect();
Some(Self {
queries,
resolve,
slots,
current: None,
next: 0,
period_ns: queue.get_timestamp_period(),
})
}
pub fn begin(&mut self, encoder: &mut wgpu::CommandEncoder) {
let slot = self.next;
self.current = (self.slots[slot].state.load(Ordering::Acquire) == FREE).then_some(slot);
if self.current.is_some() {
encoder.write_timestamp(&self.queries, 0);
}
}
pub fn end(&mut self, encoder: &mut wgpu::CommandEncoder) {
let Some(slot) = self.current else { return };
encoder.write_timestamp(&self.queries, 1);
encoder.resolve_query_set(&self.queries, 0..2, &self.resolve, 0);
encoder.copy_buffer_to_buffer(&self.resolve, 0, &self.slots[slot].buffer, 0, 16);
}
/// After the frame's submission: start reading its timestamps back.
pub fn submitted(&mut self) {
let Some(slot) = self.current.take() else {
return;
};
let state = self.slots[slot].state.clone();
state.store(PENDING, Ordering::Release);
self.slots[slot]
.buffer
.slice(..)
.map_async(wgpu::MapMode::Read, move |result| {
state.store(
if result.is_ok() { MAPPED } else { FREE },
Ordering::Release,
);
});
self.next = (slot + 1) % SLOTS;
}
/// GPU milliseconds of frames whose timestamps have arrived, oldest first.
pub fn collect(&mut self, device: &wgpu::Device, out: &mut Vec<f32>) {
let _ = device.poll(wgpu::PollType::Poll);
for i in 0..SLOTS {
let slot = &self.slots[(self.next + i) % SLOTS];
if slot.state.load(Ordering::Acquire) != MAPPED {
continue;
}
if let Ok(data) = slot.buffer.slice(..).get_mapped_range() {
let stamps: &[u64] = bytemuck::cast_slice(&data);
let ticks = stamps[1].saturating_sub(stamps[0]);
out.push((ticks as f64 * f64::from(self.period_ns) / 1e6) as f32);
}
slot.buffer.unmap();
slot.state.store(FREE, Ordering::Release);
}
}
}
+193
View File
@@ -0,0 +1,193 @@
//! Resolution scale and FXAA (Horizon settings): the world renders into its
//! own target at the scaled size, then one full-screen pass copies or
//! anti-aliases it onto the screen, under the hand and HUD. With neither
//! setting on, the world renders straight to the screen as before.
struct WorldTarget {
size: [u32; 2],
color: wgpu::TextureView,
depth: wgpu::TextureView,
group: wgpu::BindGroup,
}
pub struct Post {
layout: wgpu::BindGroupLayout,
sampler: wgpu::Sampler,
copy: wgpu::RenderPipeline,
fxaa: wgpu::RenderPipeline,
format: wgpu::TextureFormat,
/// World resolution relative to the window (0.5..=2.0).
pub scale: f32,
pub antialias: bool,
target: Option<WorldTarget>,
}
impl Post {
pub fn new(device: &wgpu::Device, format: wgpu::TextureFormat) -> Self {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Horizon post"),
source: wgpu::ShaderSource::Wgsl(include_str!("../world_post.wgsl").into()),
});
let layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("Horizon post bindings"),
entries: &[
wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Texture {
sample_type: wgpu::TextureSampleType::Float { filterable: true },
view_dimension: wgpu::TextureViewDimension::D2,
multisampled: false,
},
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 1,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
count: None,
},
],
});
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Horizon post"),
bind_group_layouts: &[Some(&layout)],
..Default::default()
});
let pipeline = |entry: &str| {
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("Horizon post"),
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
entry_point: Some("vs_post"),
compilation_options: Default::default(),
buffers: &[],
},
primitive: Default::default(),
depth_stencil: None,
multisample: Default::default(),
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: Some(entry),
compilation_options: Default::default(),
targets: &[Some(wgpu::ColorTargetState {
format,
blend: None,
write_mask: wgpu::ColorWrites::ALL,
})],
}),
multiview_mask: None,
cache: None,
})
};
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
label: Some("Horizon post"),
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
..Default::default()
});
Self {
copy: pipeline("fs_copy"),
fxaa: pipeline("fs_fxaa"),
layout,
sampler,
format,
scale: 1.0,
antialias: false,
target: None,
}
}
/// The world's colour and depth targets this frame, or `None` to draw
/// it straight to the screen.
pub fn prepare(
&mut self,
device: &wgpu::Device,
window: [u32; 2],
) -> Option<(wgpu::TextureView, wgpu::TextureView)> {
if self.scale == 1.0 && !self.antialias {
self.target = None;
return None;
}
let size = window.map(|v| ((v as f32 * self.scale).round() as u32).clamp(1, 8192));
if self.target.as_ref().is_none_or(|t| t.size != size) {
let extent = wgpu::Extent3d {
width: size[0],
height: size[1],
depth_or_array_layers: 1,
};
let texture = |label, format, usage| {
device
.create_texture(&wgpu::TextureDescriptor {
label: Some(label),
size: extent,
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format,
usage,
view_formats: &[],
})
.create_view(&Default::default())
};
let color = texture(
"Scaled world",
self.format,
wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
);
let depth = texture(
"Scaled world depth",
wgpu::TextureFormat::Depth32Float,
wgpu::TextureUsages::RENDER_ATTACHMENT,
);
let group = device.create_bind_group(&wgpu::BindGroupDescriptor {
label: Some("Horizon post"),
layout: &self.layout,
entries: &[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::TextureView(&color),
},
wgpu::BindGroupEntry {
binding: 1,
resource: wgpu::BindingResource::Sampler(&self.sampler),
},
],
});
self.target = Some(WorldTarget {
size,
color,
depth,
group,
});
}
self.target
.as_ref()
.map(|t| (t.color.clone(), t.depth.clone()))
}
/// Draw the scaled world onto `screen`.
pub fn finish(&self, encoder: &mut wgpu::CommandEncoder, screen: &wgpu::TextureView) {
let Some(target) = &self.target else { return };
let attachments = [Some(wgpu::RenderPassColorAttachment {
view: screen,
resolve_target: None,
depth_slice: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: wgpu::StoreOp::Store,
},
})];
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Horizon post"),
color_attachments: &attachments,
..Default::default()
});
pass.set_pipeline(if self.antialias {
&self.fxaa
} else {
&self.copy
});
pass.set_bind_group(0, &target.group, &[]);
pass.draw(0..3, 0..1);
}
}
+320
View File
@@ -0,0 +1,320 @@
//! Horizon's own graphics settings, beyond vanilla's options: kept in
//! `horizon-graphics.txt` next to `options.txt` so that file stays exactly
//! vanilla's. Every default reproduces vanilla's rendering; only choices the
//! player makes here depart from it.
use std::{fs, path::Path};
pub const FILE: &str = "horizon-graphics.txt";
/// Simple-level presets. `Custom` leaves every option as the player set it.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum Preset {
Performance,
Balanced,
Quality,
Ultra,
#[default]
Custom,
}
impl Preset {
pub const ALL: [Preset; 5] = [
Preset::Performance,
Preset::Balanced,
Preset::Quality,
Preset::Ultra,
Preset::Custom,
];
pub fn name(self) -> &'static str {
match self {
Preset::Performance => "performance",
Preset::Balanced => "balanced",
Preset::Quality => "quality",
Preset::Ultra => "ultra",
Preset::Custom => "custom",
}
}
pub fn label(self) -> &'static str {
match self {
Preset::Performance => "Performance",
Preset::Balanced => "Balanced",
Preset::Quality => "Quality",
Preset::Ultra => "Ultra",
Preset::Custom => "Custom",
}
}
fn parse(s: &str) -> Self {
Self::ALL
.into_iter()
.find(|p| p.name() == s)
.unwrap_or_default()
}
}
/// How the swapchain presents frames.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum PresentMode {
/// Follow vanilla's VSync option (Mailbox or Fifo on, Immediate off).
#[default]
Auto,
Fifo,
Mailbox,
Immediate,
}
impl PresentMode {
pub const ALL: [PresentMode; 4] = [
PresentMode::Auto,
PresentMode::Fifo,
PresentMode::Mailbox,
PresentMode::Immediate,
];
pub fn name(self) -> &'static str {
match self {
PresentMode::Auto => "auto",
PresentMode::Fifo => "fifo",
PresentMode::Mailbox => "mailbox",
PresentMode::Immediate => "immediate",
}
}
pub fn label(self) -> &'static str {
match self {
PresentMode::Auto => "Auto (VSync)",
PresentMode::Fifo => "FIFO",
PresentMode::Mailbox => "Mailbox",
PresentMode::Immediate => "Immediate",
}
}
fn parse(s: &str) -> Self {
Self::ALL
.into_iter()
.find(|p| p.name() == s)
.unwrap_or_default()
}
}
/// What the frame limiter does in the last half millisecond before a frame.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum Pacing {
/// Sleep the whole wait: no CPU spent spinning, a little less precise.
#[default]
Efficient,
/// Vanilla's `FramerateLimiter`: sleep, then spin until the deadline.
Precise,
}
/// The performance overlay drawn over the HUD.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum Overlay {
#[default]
Off,
/// Frames per second and frame time.
Fps,
/// The numbers and a graph of recent frame times.
Graph,
}
#[derive(Clone, Debug, PartialEq)]
pub struct Graphics {
pub preset: Preset,
/// Skip sections hidden behind closed ones (vanilla's occlusion graph).
pub cave_culling: bool,
/// Meshed sections uploaded per frame; 0 uploads all that are ready.
pub chunk_updates: u32,
/// Section mesh bytes uploaded per frame, in KiB; 0 is unlimited.
pub upload_budget_kib: u32,
pub sky: bool,
pub fog: bool,
pub weather: bool,
pub animated_textures: bool,
pub present_mode: PresentMode,
pub pacing: Pacing,
/// Chunk worker threads; 0 uses every core but one. Applies at the next start.
pub workers: u32,
pub overlay: Overlay,
/// World resolution as a percentage of the window's (50..=200).
pub resolution_scale: u32,
/// FXAA over the world.
pub fxaa: bool,
/// The settings level last shown: Advanced, or Simple.
pub advanced: bool,
}
impl Default for Graphics {
fn default() -> Self {
Self {
preset: Preset::Custom,
cave_culling: true,
chunk_updates: 0,
upload_budget_kib: 0,
sky: true,
fog: true,
weather: true,
animated_textures: true,
present_mode: PresentMode::Auto,
pacing: Pacing::Efficient,
workers: 0,
overlay: Overlay::Off,
resolution_scale: 100,
fxaa: false,
advanced: false,
}
}
}
fn bool_text(v: bool) -> &'static str {
if v { "true" } else { "false" }
}
impl Graphics {
pub fn load(dir: &Path) -> Self {
fs::read_to_string(dir.join(FILE))
.map(|t| Self::parse(&t))
.unwrap_or_default()
}
pub fn parse(text: &str) -> Self {
let mut g = Self::default();
for line in text.lines() {
let Some((key, value)) = line.split_once(':') else {
continue;
};
let value = value.trim();
let flag = |d: bool| match value {
"true" => true,
"false" => false,
_ => d,
};
let number = |d: u32| value.parse().unwrap_or(d);
match key.trim() {
"preset" => g.preset = Preset::parse(value),
"caveCulling" => g.cave_culling = flag(g.cave_culling),
"chunkUpdates" => g.chunk_updates = number(g.chunk_updates).min(512),
"uploadBudgetKiB" => g.upload_budget_kib = number(g.upload_budget_kib).min(65536),
"sky" => g.sky = flag(g.sky),
"fog" => g.fog = flag(g.fog),
"weather" => g.weather = flag(g.weather),
"animatedTextures" => g.animated_textures = flag(g.animated_textures),
"presentMode" => g.present_mode = PresentMode::parse(value),
"framePacing" => {
g.pacing = if value == "precise" {
Pacing::Precise
} else {
Pacing::Efficient
}
}
"workers" => g.workers = number(g.workers).min(64),
"resolutionScale" => g.resolution_scale = number(g.resolution_scale).clamp(50, 200),
"fxaa" => g.fxaa = flag(g.fxaa),
"level" => g.advanced = value == "advanced",
"overlay" => {
g.overlay = match value {
"fps" => Overlay::Fps,
"graph" => Overlay::Graph,
_ => Overlay::Off,
}
}
_ => {}
}
}
g
}
pub fn serialize(&self) -> String {
format!(
"preset:{}\ncaveCulling:{}\nchunkUpdates:{}\nuploadBudgetKiB:{}\nsky:{}\nfog:{}\nweather:{}\nanimatedTextures:{}\npresentMode:{}\nframePacing:{}\nworkers:{}\noverlay:{}\nresolutionScale:{}\nfxaa:{}\nlevel:{}\n",
self.preset.name(),
bool_text(self.cave_culling),
self.chunk_updates,
self.upload_budget_kib,
bool_text(self.sky),
bool_text(self.fog),
bool_text(self.weather),
bool_text(self.animated_textures),
self.present_mode.name(),
match self.pacing {
Pacing::Efficient => "efficient",
Pacing::Precise => "precise",
},
self.workers,
match self.overlay {
Overlay::Off => "off",
Overlay::Fps => "fps",
Overlay::Graph => "graph",
},
self.resolution_scale,
bool_text(self.fxaa),
if self.advanced { "advanced" } else { "simple" },
)
}
pub fn save(&self, dir: &Path) {
let _ = fs::write(dir.join(FILE), self.serialize());
}
/// Worker threads for chunk generation and meshing.
pub fn worker_threads(&self) -> usize {
if self.workers > 0 {
return self.workers as usize;
}
std::thread::available_parallelism()
.map_or(2, |n| n.get())
.saturating_sub(1)
.max(1)
}
}
/// A preset's values for vanilla's options and Horizon's own.
pub fn apply_preset(preset: Preset, s: &mut crate::settings::Settings) {
let (rd, sim, clouds, particles, shadows, blend, mipmaps, entity, leaves, weather_r) =
match preset {
Preset::Performance => (8, 6, "false", 2, false, 0, 0, 0.5, false, 3),
Preset::Balanced => (12, 8, "fast", 1, true, 1, 2, 0.75, true, 5),
Preset::Quality => (16, 12, "true", 0, true, 2, 4, 1.0, true, 10),
Preset::Ultra => (24, 12, "true", 0, true, 3, 4, 1.5, true, 10),
Preset::Custom => return,
};
s.render_distance = rd;
s.simulation_distance = sim;
s.clouds = clouds.into();
s.particles = particles;
s.entity_shadows = shadows;
s.biome_blend = blend;
s.mipmap_levels = mipmaps;
s.entity_distance = entity;
s.cutout_leaves = leaves;
s.weather_radius = weather_r;
s.graphics_preset = "custom".into();
let g = &mut s.horizon;
g.preset = preset;
g.cave_culling = true;
g.animated_textures = preset != Preset::Performance;
g.chunk_updates = 0;
g.upload_budget_kib = 0;
g.sky = true;
g.fog = true;
g.weather = true;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn round_trips() {
let g = Graphics {
preset: Preset::Balanced,
cave_culling: false,
chunk_updates: 12,
upload_budget_kib: 4096,
sky: false,
fog: false,
weather: false,
animated_textures: false,
present_mode: PresentMode::Mailbox,
pacing: Pacing::Precise,
workers: 6,
overlay: Overlay::Graph,
resolution_scale: 75,
fxaa: true,
advanced: true,
};
assert_eq!(Graphics::parse(&g.serialize()), g);
assert_eq!(Graphics::parse(""), Graphics::default());
assert_eq!(
Graphics::parse("workers:abc\nsky:maybe\n"),
Graphics::default()
);
}
}
+181
View File
@@ -0,0 +1,181 @@
//! The look of Horizon's graphics settings screens, in one place: sizes,
//! colours and the widgets they draw with. The screens (`graphics_ui`) only
//! lay out rows and handle input; a menu theme replaces this module.
use crate::{
hud::{HudAtlas, HudBatch},
text::Text,
ui,
};
/// What a setting costs in frame time, shown beside its description.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Cost {
None,
Low,
Medium,
High,
}
impl Cost {
pub fn label(self) -> &'static str {
match self {
Cost::None => "No cost",
Cost::Low => "Low cost",
Cost::Medium => "Medium cost",
Cost::High => "High cost",
}
}
}
pub struct Style {
/// Width of a setting's button or slider.
pub control_width: f32,
/// Space between the control and its description.
pub gap: f32,
/// Widest description column; narrower on small screens.
pub max_text_width: f32,
/// Vertical distance between setting rows.
pub row_height: f32,
pub header_height: f32,
/// Top and bottom bands holding the title and the buttons.
pub band: f32,
pub title_color: u32,
pub header_color: u32,
pub description_color: u32,
/// Colour of each `Cost`, in its order.
pub cost_colors: [u32; 4],
}
/// `hud::rgba` with full alpha, usable in constants.
const fn opaque(r: u8, g: u8, b: u8) -> u32 {
0xFF00_0000 | (b as u32) << 16 | (g as u32) << 8 | r as u32
}
pub const STYLE: Style = Style {
control_width: 150.0,
gap: 8.0,
max_text_width: 250.0,
row_height: 25.0,
header_height: 16.0,
band: 33.0,
title_color: u32::MAX,
header_color: opaque(255, 255, 85),
description_color: opaque(170, 170, 170),
cost_colors: [
opaque(120, 200, 120),
opaque(170, 220, 120),
opaque(240, 200, 90),
opaque(240, 110, 90),
],
};
impl Style {
/// Width of the description column on a screen `screen_width` wide.
pub fn text_width(&self, screen_width: f32) -> f32 {
(screen_width - self.control_width - self.gap - 24.0).clamp(120.0, self.max_text_width)
}
/// Left edge of a row's control, centring control and description.
pub fn row_x(&self, screen_width: f32) -> f32 {
let total = self.control_width + self.gap + self.text_width(screen_width);
((screen_width - total) / 2.0).floor()
}
pub fn background(
&self,
batch: &mut HudBatch,
atlas: &HudAtlas,
top: f32,
bottom: f32,
in_world: bool,
) {
let (w, h) = (batch.width, batch.height);
ui::menu_background(batch, atlas, 0.0, 0.0, w, h, in_world);
ui::list_background(batch, atlas, top, bottom, in_world);
}
pub fn frame(
&self,
batch: &mut HudBatch,
atlas: &HudAtlas,
top: f32,
bottom: f32,
in_world: bool,
) {
ui::separators(batch, atlas, top, bottom, in_world);
}
pub fn title(&self, batch: &mut HudBatch, atlas: &HudAtlas, text: &Text) {
let w = batch.width;
ui::centered_text(batch, atlas, text, 0.0, 12.0, w, self.title_color);
}
pub fn header(&self, batch: &mut HudBatch, atlas: &HudAtlas, text: &Text, x: f32, y: f32) {
batch.text_styled(atlas, text, x, y + 4.0, self.header_color, true);
}
pub fn button(
&self,
batch: &mut HudBatch,
atlas: &HudAtlas,
(x, y, w): (f32, f32, f32),
label: &Text,
hover: bool,
) {
ui::button(batch, atlas, x, y, w, 20.0, label, true, hover);
}
pub fn slider(
&self,
batch: &mut HudBatch,
atlas: &HudAtlas,
(x, y, w): (f32, f32, f32),
label: &Text,
value: f32,
hover: bool,
) {
ui::slider(batch, atlas, x, y, w, label, value, hover, true);
}
/// The cost tag and the description beside a control, wrapped to two lines.
pub fn description(
&self,
batch: &mut HudBatch,
atlas: &HudAtlas,
x: f32,
y: f32,
cost: Cost,
text: &str,
) {
let tag = Text::literal(cost.label());
batch.text_styled(atlas, &tag, x, y, self.cost_colors[cost as usize], true);
let indent = atlas.font.width_text(&tag) + 4.0;
let lines = wrap(atlas, text, self.text_width(batch.width), indent);
for (i, line) in lines.iter().take(2).enumerate() {
let lx = if i == 0 { x + indent } else { x };
batch.text_styled(
atlas,
&Text::literal(line.clone()),
lx,
y + i as f32 * 10.0,
self.description_color,
true,
);
}
}
}
/// Greedy word wrap; the first line is `indent` narrower.
fn wrap(atlas: &HudAtlas, text: &str, width: f32, indent: f32) -> Vec<String> {
let mut lines = vec![String::new()];
for word in text.split_whitespace() {
let room = if lines.len() == 1 {
width - indent
} else {
width
};
let line = lines.last().expect("one line");
let candidate = if line.is_empty() {
word.to_owned()
} else {
format!("{line} {word}")
};
if atlas.font.width(&candidate) <= room || line.is_empty() {
*lines.last_mut().expect("one line") = candidate;
} else {
lines.push(word.to_owned());
}
}
lines
}
+733
View File
@@ -0,0 +1,733 @@
//! Horizon's graphics settings screens, Simple and Advanced: which settings
//! they show, in what groups, with what description and cost, and their
//! input. How they look comes from `graphics_style`.
use crate::{
graphics::{Overlay, Pacing, PresentMode, Preset},
graphics_style::{Cost, STYLE},
hud::{HudAtlas, HudBatch},
options_ui::Opt,
settings::Settings,
text::Text,
ui,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Level {
Simple,
Advanced,
}
/// Horizon's own settings (`graphics::Graphics`).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum H {
Preset,
CaveCulling,
ChunkUpdates,
UploadBudget,
Sky,
Fog,
Weather,
AnimatedTextures,
PresentMode,
Pacing,
Workers,
Overlay,
ResolutionScale,
Antialiasing,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Item {
Vanilla(Opt),
Horizon(H),
}
pub struct Setting {
pub item: Item,
pub cost: Cost,
pub text: &'static str,
}
pub enum Row {
Header(&'static str),
Setting(Setting),
}
fn v(opt: Opt, cost: Cost, text: &'static str) -> Row {
Row::Setting(Setting {
item: Item::Vanilla(opt),
cost,
text,
})
}
fn h(opt: H, cost: Cost, text: &'static str) -> Row {
Row::Setting(Setting {
item: Item::Horizon(opt),
cost,
text,
})
}
/// The settings of a level, grouped under headers (Simple has no headers).
pub fn rows(level: Level) -> Vec<Row> {
use Cost::*;
let render = v(
Opt::RenderDistance,
High,
"How far terrain is drawn, in chunks. The biggest lever on frame time.",
);
let fov = v(
Opt::Fov,
Low,
"Field of view. Wider shows more terrain at once.",
);
let fps = v(
Opt::MaxFps,
None,
"Caps frames per second; a cap saves power and heat.",
);
let vsync = v(
Opt::Vsync,
None,
"Waits for the display's refresh: no tearing, a little latency.",
);
let gui = v(Opt::GuiScale, None, "Size of menus and the HUD.");
let preset = h(
H::Preset,
None,
"Sets the options below together. Changing one makes it Custom.",
);
match level {
Level::Simple => vec![preset, render, fov, fps, vsync, gui],
Level::Advanced => vec![
Row::Header("Rendering"),
render,
v(
Opt::SimulationDistance,
Medium,
"How far mobs, crops and machines keep working. CPU time.",
),
v(
Opt::EntityDistance,
Medium,
"How far away mobs and items are drawn, as a share of normal.",
),
h(
H::CaveCulling,
None,
"Skips terrain hidden behind closed sections. Off costs a lot.",
),
h(
H::ChunkUpdates,
Low,
"Meshed sections uploaded per frame. Lower is smoother while loading.",
),
Row::Header("Quality"),
v(
Opt::SmoothLighting,
Low,
"Soft shadows in corners. Costs chunk building time only.",
),
v(
Opt::Mipmaps,
Low,
"Smaller copies of block textures for distant terrain: less shimmer.",
),
v(
Opt::BiomeBlend,
Low,
"Blends grass and water colours across biomes when building chunks.",
),
v(
Opt::Clouds,
Medium,
"Cloud layer: off, flat (fast) or 3D (fancy).",
),
v(Opt::CloudRange, Low, "How far clouds reach, in chunks."),
h(H::Sky, Low, "Draws the sky, sun, moon and stars."),
h(
H::Fog,
None,
"Distance fog. Off shows the edge of the loaded world.",
),
h(H::Weather, Low, "Draws rain and snow."),
v(
Opt::WeatherRadius,
Low,
"How far rain and snow fall around you.",
),
v(Opt::Particles, Medium, "How many particles effects spawn."),
v(
Opt::EntityShadows,
Low,
"Round shadows under mobs and items.",
),
v(
Opt::CutoutLeaves,
Medium,
"Leaves with see-through gaps. Off draws them solid.",
),
v(
Opt::ImprovedTransparency,
Medium,
"Sorts water and glass more exactly behind each other.",
),
v(
Opt::ChunkBuilder,
Low,
"Which chunk rebuilds wait for the frame: none, nearby or yours.",
),
h(
H::AnimatedTextures,
Low,
"Animates water, lava, fire and other moving textures.",
),
Row::Header("Display"),
fov,
fps,
vsync,
h(
H::ResolutionScale,
High,
"World pixels per screen pixel. Below 100% is faster on the GPU.",
),
h(
H::Antialiasing,
Low,
"FXAA smooths jagged edges of the world; slightly softer image.",
),
h(
H::PresentMode,
None,
"How frames reach the screen. Auto follows VSync.",
),
h(
H::Pacing,
None,
"Efficient sleeps until the next frame; Precise spins, like vanilla.",
),
v(Opt::Fullscreen, None, "Fills the screen (borderless)."),
gui,
v(Opt::Gamma, None, "Brightens dark places."),
v(
Opt::InactivityFps,
None,
"Lowers the frame rate when minimised, or idle too.",
),
Row::Header("Preferences"),
v(Opt::ViewBobbing, None, "Sways the view while walking."),
v(Opt::ChunkFade, None, "Fades newly loaded chunks in."),
v(Opt::Vignette, None, "Darkens the screen's edges."),
v(Opt::Autosave, None, "Shows when the world saves."),
v(Opt::AttackIndicator, None, "Shows attack cooldown."),
Row::Header("Performance"),
h(
H::Workers,
None,
"Threads that generate, light and mesh chunks. Next start.",
),
h(
H::UploadBudget,
Low,
"Mesh data sent to the GPU per frame. Lower is smoother while loading.",
),
Row::Header("Overlay"),
h(
H::Overlay,
None,
"Frame rate and frame times over the game, with a graph.",
),
],
}
}
const UPLOAD_STEPS: [u32; 8] = [0, 256, 512, 1024, 2048, 4096, 8192, 16384];
fn on_off(on: bool) -> &'static str {
if on { "On" } else { "Off" }
}
fn labelled(caption: &str, value: impl std::fmt::Display) -> Text {
Text::literal(format!("{caption}: {value}"))
}
impl H {
fn slider(self, s: &Settings) -> Option<f32> {
let g = &s.horizon;
match self {
H::ChunkUpdates => Some(g.chunk_updates as f32 / 64.0),
H::UploadBudget => {
let i = UPLOAD_STEPS
.iter()
.position(|&b| b >= g.upload_budget_kib)
.unwrap_or(UPLOAD_STEPS.len() - 1);
Some(i as f32 / (UPLOAD_STEPS.len() - 1) as f32)
}
H::Workers => Some(g.workers as f32 / max_workers() as f32),
H::ResolutionScale => Some((g.resolution_scale as f32 - 50.0) / 150.0),
_ => None,
}
}
fn label(self, s: &Settings) -> Text {
let g = &s.horizon;
match self {
H::Preset => labelled("Preset", g.preset.label()),
H::CaveCulling => labelled("Cave Culling", on_off(g.cave_culling)),
H::ChunkUpdates => match g.chunk_updates {
0 => labelled("Chunk Updates", "Unlimited"),
n => labelled("Chunk Updates", format!("{n} per frame")),
},
H::UploadBudget => match g.upload_budget_kib {
0 => labelled("Upload Budget", "Unlimited"),
k if k >= 1024 => labelled("Upload Budget", format!("{} MiB/frame", k / 1024)),
k => labelled("Upload Budget", format!("{k} KiB/frame")),
},
H::Sky => labelled("Sky", on_off(g.sky)),
H::Fog => labelled("Fog", on_off(g.fog)),
H::Weather => labelled("Weather", on_off(g.weather)),
H::AnimatedTextures => labelled("Animated Textures", on_off(g.animated_textures)),
H::PresentMode => labelled("Present Mode", g.present_mode.label()),
H::Pacing => labelled(
"Frame Pacing",
match g.pacing {
Pacing::Efficient => "Efficient",
Pacing::Precise => "Precise",
},
),
H::Workers => match g.workers {
0 => labelled("Worker Threads", format!("Auto ({})", g.worker_threads())),
n => labelled("Worker Threads", n),
},
H::ResolutionScale => labelled("Resolution Scale", format!("{}%", g.resolution_scale)),
H::Antialiasing => labelled("Anti-aliasing", if g.fxaa { "FXAA" } else { "Off" }),
H::Overlay => labelled(
"Performance Overlay",
match g.overlay {
Overlay::Off => "Off",
Overlay::Fps => "FPS",
Overlay::Graph => "FPS and Graph",
},
),
}
}
fn set_slider(self, s: &mut Settings, v: f32) {
let g = &mut s.horizon;
match self {
H::ChunkUpdates => g.chunk_updates = (v * 64.0).round() as u32,
H::UploadBudget => {
g.upload_budget_kib =
UPLOAD_STEPS[(v * (UPLOAD_STEPS.len() - 1) as f32).round() as usize]
}
H::Workers => g.workers = (v * max_workers() as f32).round() as u32,
H::ResolutionScale => g.resolution_scale = (50.0 + (v * 30.0).round() * 5.0) as u32,
_ => {}
}
}
fn cycle(self, s: &mut Settings, back: bool) {
fn step<T: Copy + PartialEq>(all: &[T], now: T, back: bool) -> T {
let i = all.iter().position(|x| *x == now).unwrap_or(0);
let n = all.len();
all[if back { (i + n - 1) % n } else { (i + 1) % n }]
}
if self == H::Preset {
let preset = step(&Preset::ALL, s.horizon.preset, back);
crate::graphics::apply_preset(preset, s);
s.horizon.preset = preset;
return;
}
let g = &mut s.horizon;
match self {
H::CaveCulling => g.cave_culling = !g.cave_culling,
H::Sky => g.sky = !g.sky,
H::Fog => g.fog = !g.fog,
H::Weather => g.weather = !g.weather,
H::AnimatedTextures => g.animated_textures = !g.animated_textures,
H::PresentMode => g.present_mode = step(&PresentMode::ALL, g.present_mode, back),
H::Antialiasing => g.fxaa = !g.fxaa,
H::Pacing => {
g.pacing = match g.pacing {
Pacing::Efficient => Pacing::Precise,
Pacing::Precise => Pacing::Efficient,
}
}
H::Overlay => {
g.overlay = step(
&[Overlay::Off, Overlay::Fps, Overlay::Graph],
g.overlay,
back,
)
}
_ => {}
}
}
}
fn max_workers() -> u32 {
std::thread::available_parallelism().map_or(8, |n| n.get() as u32)
}
impl Item {
/// On/off settings, drawn as switches by the Horizon menus.
pub fn switch(self, s: &Settings) -> Option<bool> {
let g = &s.horizon;
Some(match self {
Item::Horizon(H::CaveCulling) => g.cave_culling,
Item::Horizon(H::Sky) => g.sky,
Item::Horizon(H::Fog) => g.fog,
Item::Horizon(H::Weather) => g.weather,
Item::Horizon(H::AnimatedTextures) => g.animated_textures,
Item::Horizon(H::Antialiasing) => g.fxaa,
Item::Vanilla(Opt::ViewBobbing) => s.view_bobbing,
Item::Vanilla(Opt::Vsync) => s.vsync,
Item::Vanilla(Opt::Fullscreen) => s.fullscreen,
Item::Vanilla(Opt::SmoothLighting) => s.smooth_lighting,
Item::Vanilla(Opt::EntityShadows) => s.entity_shadows,
Item::Vanilla(Opt::Vignette) => s.vignette,
Item::Vanilla(Opt::Autosave) => s.autosave_indicator,
Item::Vanilla(Opt::CutoutLeaves) => s.cutout_leaves,
Item::Vanilla(Opt::ImprovedTransparency) => s.improved_transparency,
_ => return None,
})
}
/// Caption and value text, split from the label ("Caption: Value").
pub fn caption_value(self, s: &Settings) -> (String, String) {
let label = self.label(s).plain();
match label.split_once(": ") {
Some((c, v)) => (c.to_owned(), v.to_owned()),
None => (label, String::new()),
}
}
pub fn slider(self, s: &Settings) -> Option<f32> {
match self {
Item::Vanilla(o) => o.slider_position(s),
Item::Horizon(h) => h.slider(s),
}
}
pub fn label(self, s: &Settings) -> Text {
match self {
// The vanilla button shows the scale alone, under its own caption.
Item::Vanilla(Opt::GuiScale) => Text::translate(
"options.generic_value",
&[
Text::translate("options.guiScale", &[]),
Opt::GuiScale.label(s),
],
),
Item::Vanilla(o) => o.label(s),
Item::Horizon(h) => h.label(s),
}
}
pub fn set_slider(self, s: &mut Settings, v: f32) {
match self {
Item::Vanilla(o) => o.set_slider(s, v),
Item::Horizon(h) => h.set_slider(s, v),
}
self.touched(s);
}
pub fn cycle(self, s: &mut Settings, back: bool) {
match self {
Item::Vanilla(o) => o.cycle(s, back),
Item::Horizon(h) => h.cycle(s, back),
}
self.touched(s);
}
/// A preset no longer describes the settings once one of them changes.
fn touched(self, s: &mut Settings) {
let presetless = matches!(
self,
Item::Horizon(H::Preset | H::Overlay | H::Pacing | H::PresentMode | H::Workers)
| Item::Vanilla(
Opt::GuiScale
| Opt::Fullscreen
| Opt::Vsync
| Opt::MaxFps
| Opt::Fov
| Opt::Gamma
| Opt::InactivityFps
| Opt::ViewBobbing
| Opt::ChunkFade
| Opt::Vignette
| Opt::Autosave
| Opt::AttackIndicator
)
);
if !presetless {
s.horizon.preset = Preset::Custom;
}
}
}
/// What the options screens must do after an interaction here.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Action {
Changed,
OpenAdvanced,
OpenSimple,
Done,
}
#[derive(Clone, Copy)]
enum Target {
Item(Item),
Button(Action),
}
struct Widget {
x: f32,
y: f32,
w: f32,
target: Target,
/// In the scrolling list (clipped to it).
list: bool,
}
#[derive(Default)]
pub struct GraphicsUi {
scroll: f32,
dragging: Option<Item>,
}
impl GraphicsUi {
pub fn reset(&mut self) {
self.scroll = 0.0;
self.dragging = None;
}
fn bounds(h: f32) -> (f32, f32) {
(STYLE.band, h - STYLE.band)
}
/// Widgets and the list's content height.
fn layout(&self, level: Level, w: f32, h: f32) -> (Vec<Widget>, Vec<(f32, &'static str)>, f32) {
let (top, _) = Self::bounds(h);
let x = STYLE.row_x(w);
let mut y = top + 4.0 - self.scroll;
let start = y;
let mut widgets = Vec::new();
let mut headers = Vec::new();
for row in rows(level) {
match row {
Row::Header(name) => {
headers.push((y, name));
y += STYLE.header_height;
}
Row::Setting(s) => {
widgets.push(Widget {
x,
y,
w: STYLE.control_width,
target: Target::Item(s.item),
list: true,
});
y += STYLE.row_height;
}
}
}
let content = y - start + 4.0;
let cx = (w / 2.0).floor();
let by = h - 27.0;
let other = match level {
Level::Simple => Action::OpenAdvanced,
Level::Advanced => Action::OpenSimple,
};
widgets.push(Widget {
x: cx - 155.0,
y: by,
w: 150.0,
target: Target::Button(other),
list: false,
});
widgets.push(Widget {
x: cx + 5.0,
y: by,
w: 150.0,
target: Target::Button(Action::Done),
list: false,
});
(widgets, headers, content)
}
fn clamp_scroll(&mut self, h: f32, content: f32) {
let (top, bottom) = Self::bounds(h);
self.scroll = self.scroll.clamp(0.0, (content - (bottom - top)).max(0.0));
}
pub fn draw(
&mut self,
level: Level,
s: &Settings,
batch: &mut HudBatch,
atlas: &HudAtlas,
cursor: (f32, f32),
in_world: bool,
) {
let (w, h) = (batch.width, batch.height);
let (_, _, content) = self.layout(level, w, h);
self.clamp_scroll(h, content);
let (widgets, headers, _) = self.layout(level, w, h);
let (top, bottom) = Self::bounds(h);
STYLE.background(batch, atlas, top, bottom, in_world);
let shown = |y: f32, height: f32| y >= top && y + height <= bottom;
let x = STYLE.row_x(w);
for (y, name) in headers {
if shown(y, STYLE.header_height) {
STYLE.header(batch, atlas, &Text::literal(name), x, y);
}
}
let descriptions: Vec<(Cost, &'static str)> = rows(level)
.into_iter()
.filter_map(|r| match r {
Row::Setting(s) => Some((s.cost, s.text)),
Row::Header(_) => None,
})
.collect();
let mut index = 0;
for wd in &widgets {
let hover = ui::hovered(cursor, wd.x, wd.y, wd.w, 20.0)
&& (!wd.list || (cursor.1 >= top && cursor.1 < bottom));
match wd.target {
Target::Item(item) => {
let (cost, text) = descriptions[index];
index += 1;
if !shown(wd.y, 20.0) {
continue;
}
let label = item.label(s);
match item.slider(s) {
Some(value) => STYLE.slider(
batch,
atlas,
(wd.x, wd.y, wd.w),
&label,
value,
hover || self.dragging == Some(item),
),
None => STYLE.button(batch, atlas, (wd.x, wd.y, wd.w), &label, hover),
}
STYLE.description(
batch,
atlas,
wd.x + wd.w + STYLE.gap,
wd.y + 1.0,
cost,
text,
);
}
Target::Button(action) => {
let label = match action {
Action::OpenAdvanced => "Advanced...",
Action::OpenSimple => "Simple...",
_ => "Done",
};
STYLE.button(
batch,
atlas,
(wd.x, wd.y, wd.w),
&Text::literal(label),
hover,
);
}
}
}
STYLE.frame(batch, atlas, top, bottom, in_world);
ui::scrollbar(
batch,
atlas,
x + STYLE.control_width + STYLE.gap + STYLE.text_width(w) + 6.0,
top,
bottom,
content,
self.scroll,
);
let title = match level {
Level::Simple => "Graphics",
Level::Advanced => "Graphics: Advanced",
};
STYLE.title(batch, atlas, &Text::literal(title));
}
/// A press (or a drag with `drag`) at `(x, y)`.
pub fn click(
&mut self,
level: Level,
s: &mut Settings,
(x, y): (f32, f32),
(w, h): (f32, f32),
drag: bool,
right: bool,
) -> Vec<Action> {
let (widgets, _, _) = self.layout(level, w, h);
let (top, bottom) = Self::bounds(h);
if drag {
if let Some(item) = self.dragging
&& let Some(wd) = widgets
.iter()
.find(|wd| matches!(wd.target, Target::Item(i) if i == item))
{
item.set_slider(s, ui::slider_value(wd.x, wd.w, x));
return vec![Action::Changed];
}
return Vec::new();
}
for wd in widgets {
if !ui::hovered((x, y), wd.x, wd.y, wd.w, 20.0) {
continue;
}
if wd.list && (y < top || y >= bottom || wd.y < top || wd.y + 20.0 > bottom) {
continue;
}
return match wd.target {
Target::Button(action) => vec![action],
Target::Item(item) => {
if item.slider(s).is_some() {
self.dragging = Some(item);
item.set_slider(s, ui::slider_value(wd.x, wd.w, x));
} else {
item.cycle(s, right);
}
vec![Action::Changed]
}
};
}
Vec::new()
}
pub fn release(&mut self) {
self.dragging = None;
}
pub fn scroll(&mut self, amount: f32) {
self.scroll -= amount * 18.0;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_advanced_setting_has_a_description() {
for level in [Level::Simple, Level::Advanced] {
for row in rows(level) {
if let Row::Setting(s) = row {
assert!(!s.text.is_empty(), "{:?}", s.item);
assert!(s.text.len() < 80, "one line: {:?}", s.item);
}
}
}
}
#[test]
fn presets_set_vanilla_and_horizon_options() {
let mut s = Settings::default();
Item::Horizon(H::Preset).cycle(&mut s, false);
assert_eq!(s.horizon.preset, Preset::Performance);
assert_eq!(s.render_distance, 8);
assert_eq!(s.clouds, "false");
// Any quality change leaves the preset.
Item::Vanilla(Opt::Clouds).cycle(&mut s, false);
assert_eq!(s.horizon.preset, Preset::Custom);
// Display preferences keep it.
Item::Horizon(H::Preset).cycle(&mut s, true);
Item::Vanilla(Opt::Vsync).cycle(&mut s, false);
assert_eq!(s.horizon.preset, Preset::Ultra);
}
#[test]
fn upload_budget_slider_steps() {
let mut s = Settings::default();
H::UploadBudget.set_slider(&mut s, 1.0);
assert_eq!(s.horizon.upload_budget_kib, 16384);
assert_eq!(H::UploadBudget.slider(&s), Some(1.0));
H::UploadBudget.set_slider(&mut s, 0.0);
assert_eq!(s.horizon.upload_budget_kib, 0);
}
}
+6
View File
@@ -40,6 +40,7 @@ pub mod enchant;
pub mod entities;
pub mod entity_nbt;
pub mod environment;
pub mod fast_hash;
pub mod fastutil_order;
pub mod first_person;
pub mod flatgen;
@@ -49,6 +50,9 @@ pub mod front;
pub mod gamerules;
pub mod gfx;
pub mod gossip;
pub mod graphics;
pub mod graphics_style;
pub mod graphics_ui;
pub mod health;
pub mod hotbar;
pub mod hud;
@@ -87,6 +91,7 @@ pub mod pack_screen;
pub mod packs;
pub mod particles;
pub mod patrol;
pub mod perf_overlay;
pub mod pose;
pub mod post;
pub mod projectiles;
@@ -109,6 +114,7 @@ pub mod skins;
pub mod snbt;
pub mod sound_engine;
pub mod sound_events;
pub mod spans;
pub mod sprint;
pub mod sprites;
pub mod stations;
+1 -1
View File
@@ -359,7 +359,7 @@ pub trait LightWorld {
fn light(&self, x: i32, y: i32, z: i32) -> Option<u8>;
fn set_light(&mut self, x: i32, y: i32, z: i32, packed: u8);
}
impl LightWorld for HashMap<(i32, i32), Arc<Chunk>> {
impl<S: std::hash::BuildHasher> LightWorld for HashMap<(i32, i32), Arc<Chunk>, S> {
fn state(&self, x: i32, y: i32, z: i32) -> Option<u16> {
if !(MIN_Y..MIN_Y + HEIGHT).contains(&y) {
return None;
+12
View File
@@ -899,6 +899,18 @@ fn species_ai_step(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
_ => {}
}
}
/// `Entity.checkDespawn` alone, for a mob outside the entity-ticking
/// chunks. Returns false when the mob is gone.
pub fn despawn_check(m: &mut Mob, w: &MobWorld) -> bool {
if m.removed {
return false;
}
if !check_despawn(m, w) {
m.removed = true;
return false;
}
true
}
/// Mob.checkDespawn, before the tick (players are the only despawn
/// reference). Returns false when the mob is discarded.
fn check_despawn(m: &mut Mob, w: &MobWorld) -> bool {
+104 -65
View File
@@ -10,6 +10,8 @@
//! of control belong in `ui_theme` so the launcher-matching look stays in one
//! place. Everything else (sliders dragging, scrolling, Done) is handled here.
use crate::{
graphics_style::Cost,
graphics_ui::{self, Item, Level},
hud::{HudAtlas, HudBatch},
options_ui::{Event, Kind, Opt, OptionsUi, Page, apply_preset},
settings::{SOUND_SOURCES, Settings},
@@ -28,6 +30,10 @@ pub enum HRow {
Page(&'static str, &'static str, Page),
/// Menu style: Horizon / Classic.
Style,
/// Graphics settings level: Simple / Advanced.
Level,
/// A graphics setting with its frame-time cost and description.
Graphics(Item, Cost, &'static str),
}
/// A sidebar section: name, description, rows.
pub struct Section {
@@ -38,53 +44,18 @@ pub struct Section {
pub const SECTIONS: &[Section] = &[
Section {
name: "Video",
blurb: "Display, quality and how the world is drawn.",
rows: |_| {
let mut r = vec![HRow::Header("Display")];
r.extend(
[
Opt::Fullscreen,
Opt::Vsync,
Opt::MaxFps,
Opt::InactivityFps,
Opt::GuiScale,
Opt::Gamma,
]
.map(HRow::Opt),
);
r.push(HRow::Header("Quality"));
r.extend(
[
Opt::Preset,
Opt::RenderDistance,
Opt::SimulationDistance,
Opt::SmoothLighting,
Opt::Clouds,
Opt::CloudRange,
Opt::Particles,
Opt::Mipmaps,
Opt::EntityShadows,
Opt::EntityDistance,
Opt::BiomeBlend,
Opt::CutoutLeaves,
Opt::ImprovedTransparency,
Opt::WeatherRadius,
Opt::ChunkBuilder,
]
.map(HRow::Opt),
);
r.push(HRow::Header("Preferences"));
r.extend(
[
Opt::Fov,
Opt::ViewBobbing,
Opt::Autosave,
Opt::Vignette,
Opt::AttackIndicator,
Opt::ChunkFade,
]
.map(HRow::Opt),
);
blurb: "Graphics, Simple or Advanced: each setting says what it costs.",
rows: |s| {
let level = if s.horizon.advanced {
Level::Advanced
} else {
Level::Simple
};
let mut r = vec![HRow::Level];
r.extend(graphics_ui::rows(level).into_iter().map(|row| match row {
graphics_ui::Row::Header(name) => HRow::Header(name),
graphics_ui::Row::Setting(g) => HRow::Graphics(g.item, g.cost, g.text),
}));
r
},
},
@@ -187,6 +158,7 @@ const NAV: u64 = id("options.nav", 0);
const DONE: u64 = id("options.done", 0);
const ROW: u64 = id("options.row", 0);
const STYLE: u64 = id("options.style", 0);
const LEVEL: u64 = id("options.level", 0);
const ROW_H: f32 = 12.0 + CONTROL + 12.0;
const HEADER_H: f32 = 40.0;
@@ -234,13 +206,19 @@ enum Target {
Nav(usize),
Done,
Row(usize),
Slider(Opt, f32),
Slider(Item, f32),
Style(usize),
Level(usize),
}
impl OptionsUi {
/// Lay out (and draw, on a real frame) the Horizon options shell.
/// Returns the sliders' tracks (option, x, width) for dragging.
fn horizon_layout(&mut self, s: &Settings, ui: &mut Ui, backdrop: f32) -> Vec<(Opt, f32, f32)> {
fn horizon_layout(
&mut self,
s: &Settings,
ui: &mut Ui,
backdrop: f32,
) -> Vec<(Item, f32, f32)> {
let (w, h) = (ui.w, ui.h);
if self.in_world {
ui.atmosphere(0.45, 1.0);
@@ -326,7 +304,7 @@ impl OptionsUi {
ui.row(x, y, &caption, &value, cw - ROW_LABEL - 16.0 - sw - 24.0);
let sx = control_x - sw - 8.0;
ui.slider(ROW + i as u64, sx, cy, sw, v);
sliders.push((opt, sx, sw));
sliders.push((Item::Vanilla(opt), sx, sw));
} else {
ui.row(x, y, &caption, "", 0.0);
let bw = ui.button_width(&value, false).max(96.0);
@@ -364,6 +342,42 @@ impl OptionsUi {
true,
);
}
HRow::Level => {
ui.row(x, y, "Settings", "", 0.0);
let labels = ["Simple", "Advanced"];
let probe = ui.segmented(LEVEL, -10_000.0, -10_000.0, &labels, 0);
let selected = usize::from(s.horizon.advanced);
ui.segmented(LEVEL, control_x - probe, y + 12.0 - 3.0, &labels, selected);
}
HRow::Graphics(item, cost, text) => {
let (caption, value) = item.caption_value(s);
let cost = (cost as u8, cost.label());
let cy = y + ROW_H / 2.0;
let id = ROW + i as u64;
if let Some(on) = item.switch(s) {
ui.described_row(x, y, &caption, "", 0.0, cost, text, cw - 60.0);
ui.switch(id, control_x, cy, on);
} else if let Some(v) = item.slider(s) {
let sw = 220.0_f32.min(cw - ROW_LABEL - 200.0).max(80.0);
let value_w = cw - ROW_LABEL - 16.0 - sw - 24.0;
let text_w = cw - sw - 24.0;
ui.described_row(x, y, &caption, &value, value_w, cost, text, text_w);
let sx = control_x - sw - 8.0;
ui.slider(id, sx, cy, sw, v);
sliders.push((item, sx, sw));
} else {
let bw = ui.button_width(&value, false).max(96.0);
let text_w = cw - bw - 24.0;
ui.described_row(x, y, &caption, "", 0.0, cost, text, text_w);
ui.button(
id,
[control_x - bw, y + 12.0, bw, CONTROL],
&value,
Button::Secondary,
true,
);
}
}
HRow::Style => {
ui.row(x, y, "Menu style", "", 0.0);
let labels = ["Horizon", "Classic"];
@@ -434,13 +448,21 @@ impl OptionsUi {
if hit == STYLE || hit == STYLE + 1 {
return Some(Target::Style((hit - STYLE) as usize));
}
if hit == LEVEL || hit == LEVEL + 1 {
return Some(Target::Level((hit - LEVEL) as usize));
}
let i = hit.checked_sub(ROW)? as usize;
let rows = (SECTIONS[section].rows)(s);
if let Some(HRow::Opt(opt)) = rows.get(i)
&& let Some(&(_, sx, sw)) = sliders.iter().find(|(o, ..)| o == opt)
let item = match rows.get(i) {
Some(HRow::Opt(opt)) => Some(Item::Vanilla(*opt)),
Some(HRow::Graphics(item, ..)) => Some(*item),
_ => None,
};
if let Some(item) = item
&& let Some(&(_, sx, sw)) = sliders.iter().find(|(o, ..)| *o == item)
{
let v = t::slider_value(&ui, sx, sw, x);
return Some(Target::Slider(*opt, v));
return Some(Target::Slider(item, v));
}
(i < rows.len()).then_some(Target::Row(i))
}
@@ -456,15 +478,12 @@ impl OptionsUi {
) -> Vec<Event> {
let mut events = Vec::new();
if drag {
if let Some(opt) = self.dragging {
if let Some(item) = self.hdragging {
let mut batch = t::scratch_batch();
let mut ui = Ui::dry(atlas, &mut batch, (x, y));
let sliders = self.horizon_layout(s, &mut ui, 1.0);
if let Some(&(_, sx, sw)) = sliders.iter().find(|(o, ..)| *o == opt) {
opt.set_slider(s, t::slider_value(&ui, sx, sw, x));
if opt == Opt::Preset {
apply_preset(s);
}
if let Some(&(_, sx, sw)) = sliders.iter().find(|(o, ..)| *o == item) {
set_item_slider(item, s, t::slider_value(&ui, sx, sw, x));
events.push(Event::Changed);
}
}
@@ -486,12 +505,14 @@ impl OptionsUi {
t::save_preferences(&dir);
}
}
Some(Target::Slider(opt, v)) => {
self.dragging = Some(opt);
opt.set_slider(s, v);
if opt == Opt::Preset {
apply_preset(s);
}
Some(Target::Level(i)) => {
s.horizon.advanced = i == 1;
self.hscroll = 0.0;
events.push(Event::Changed);
}
Some(Target::Slider(item, v)) => {
self.hdragging = Some(item);
set_item_slider(item, s, v);
events.push(Event::Changed);
}
Some(Target::Row(i)) => {
@@ -504,6 +525,10 @@ impl OptionsUi {
}
events.push(Event::Changed);
}
Some(HRow::Graphics(item, ..)) => {
item.cycle(s, right);
events.push(Event::Changed);
}
Some(HRow::Page(_, _, page)) => self.open_page(*page),
_ => {}
}
@@ -516,3 +541,17 @@ impl OptionsUi {
self.hscroll -= amount * 40.0;
}
}
/// A slider moved: vanilla options keep their preset handling, Horizon's own
/// settings go through `graphics_ui`.
fn set_item_slider(item: Item, s: &mut Settings, v: f32) {
match item {
Item::Vanilla(opt) => {
opt.set_slider(s, v);
if opt == Opt::Preset {
apply_preset(s);
}
}
Item::Horizon(_) => item.set_slider(s, v),
}
}
+78 -1
View File
@@ -190,6 +190,13 @@ impl Opt {
_ => Kind::Cycle,
}
}
/// A slider's position (0..1), or `None` for a cycle button.
pub fn slider_position(self, s: &Settings) -> Option<f32> {
match self.kind(s) {
Kind::Slider(v) => Some(v),
Kind::Cycle => None,
}
}
/// The widget message (OptionInstance.toString / CycleButton full name).
pub fn label(self, s: &Settings) -> Text {
let c = self.caption();
@@ -532,6 +539,9 @@ pub enum Page {
Language,
Font,
Packs,
/// Horizon's graphics settings (`graphics_ui`).
Graphics,
GraphicsAdvanced,
}
#[derive(Clone, Debug, PartialEq)]
enum Act {
@@ -596,6 +606,8 @@ pub struct OptionsUi {
pub section: usize,
pub(crate) section_shown: Option<usize>,
pub(crate) hscroll: f32,
/// The slider being dragged on the Horizon options shell.
pub(crate) hdragging: Option<crate::graphics_ui::Item>,
/// Key Binds: the mapping waiting for a key.
pub selected_key: Option<&'static str>,
pub languages: Vec<LanguageInfo>,
@@ -611,6 +623,7 @@ pub struct OptionsUi {
pub in_world: bool,
/// Scroll the selected language into the middle on the next layout.
center_language: bool,
pub graphics: crate::graphics_ui::GraphicsUi,
}
impl Default for OptionsUi {
fn default() -> Self {
@@ -623,6 +636,7 @@ impl Default for OptionsUi {
section: 0,
section_shown: None,
hscroll: 0.0,
hdragging: None,
selected_key: None,
languages: Vec::new(),
language_choice: None,
@@ -633,6 +647,7 @@ impl Default for OptionsUi {
pack_focus: std::time::Instant::now(),
in_world: false,
center_language: false,
graphics: Default::default(),
}
}
}
@@ -716,6 +731,17 @@ impl OptionsUi {
if page == Page::Packs {
self.pack_screen = None;
}
if matches!(page, Page::Graphics | Page::GraphicsAdvanced) {
self.graphics.reset();
}
}
/// The graphics screen level of `page`, if it is one.
fn graphics_level(page: Page) -> Option<crate::graphics_ui::Level> {
match page {
Page::Graphics => Some(crate::graphics_ui::Level::Simple),
Page::GraphicsAdvanced => Some(crate::graphics_ui::Level::Advanced),
_ => None,
}
}
fn title(page: Page) -> &'static str {
match page {
@@ -730,12 +756,30 @@ impl OptionsUi {
Page::Language => "options.language.title",
Page::Font => "options.font.title",
Page::Packs => "resourcePack.title",
Page::Graphics | Page::GraphicsAdvanced => "options.videoTitle",
}
}
fn list_rows(&self, s: &Settings) -> Vec<Row> {
match self.page() {
Page::Video => {
let mut rows = vec![Row::Header("options.video.display.header")];
// Horizon's graphics screens, Simple and Advanced.
let mut rows = vec![Row::Buttons(
button(
0.0,
0.0,
150.0,
Text::literal("Horizon Graphics..."),
Act::Push(Page::Graphics),
),
Some(button(
0.0,
0.0,
150.0,
Text::literal("Advanced Graphics..."),
Act::Push(Page::GraphicsAdvanced),
)),
)];
rows.push(Row::Header("options.video.display.header"));
rows.extend(pairs(&[
Opt::MaxFps,
Opt::Vsync,
@@ -1191,6 +1235,11 @@ impl OptionsUi {
self.draw_horizon(s, batch, atlas, cursor);
return;
}
if let Some(level) = Self::graphics_level(self.page()) {
self.graphics
.draw(level, s, batch, atlas, cursor, self.in_world);
return;
}
if self.page() == Page::Packs {
ui::menu_background(batch, atlas, 0.0, 0.0, w, h, self.in_world);
let blink = self.pack_focus.elapsed().as_millis() as u64;
@@ -1343,6 +1392,28 @@ impl OptionsUi {
if crate::ui_theme::horizon() && self.page() == Page::Main {
return self.click_horizon(s, atlas, x, y, drag, right);
}
if let Some(level) = Self::graphics_level(self.page()) {
use crate::graphics_ui::Action;
let mut events = Vec::new();
for action in self.graphics.click(level, s, (x, y), size, drag, right) {
match action {
Action::Changed => events.push(Event::Changed),
Action::OpenAdvanced => self.push(Page::GraphicsAdvanced),
Action::OpenSimple => {
if self.stack.len() >= 2
&& self.stack[self.stack.len() - 2] == Page::Graphics
{
events.extend(self.back(s));
} else {
self.stack.pop();
self.push(Page::Graphics);
}
}
Action::Done => events.extend(self.back(s)),
}
}
return events;
}
if self.page() == Page::Packs {
let mut events = Vec::new();
if drag || right {
@@ -1440,6 +1511,8 @@ impl OptionsUi {
}
pub fn release(&mut self) {
self.dragging = None;
self.hdragging = None;
self.graphics.release();
}
pub fn scroll(&mut self, amount: f32) {
self.scroll -= amount * 18.0;
@@ -1450,6 +1523,10 @@ impl OptionsUi {
self.scroll_horizon(amount);
return;
}
if Self::graphics_level(self.page()).is_some() {
self.graphics.scroll(amount);
return;
}
match &mut self.pack_screen {
Some(p) if self.stack.last() == Some(&Page::Packs) => {
p.scroll(cursor.0 as f64, cursor.1 as f64, amount as f64)
+110
View File
@@ -0,0 +1,110 @@
//! The performance overlay (Horizon's Overlay setting): frames per second,
//! frame, CPU and GPU times, and a graph of recent frame times.
use crate::{
graphics::Overlay,
hud::{HudAtlas, HudBatch, rgba},
text::Text,
};
use std::collections::VecDeque;
const HISTORY: usize = 160;
#[derive(Default)]
pub struct FrameGraph {
/// Frame, CPU and GPU milliseconds of recent frames, oldest first.
frames: VecDeque<(f32, f32, f32)>,
}
impl FrameGraph {
pub fn record(&mut self, frame_ms: f32, cpu_ms: f32, gpu_ms: Option<f32>) {
let gpu = gpu_ms.unwrap_or_else(|| self.frames.back().map_or(0.0, |f| f.2));
if self.frames.len() == HISTORY {
self.frames.pop_front();
}
self.frames.push_back((frame_ms, cpu_ms, gpu));
}
pub fn draw(&self, mode: Overlay, batch: &mut HudBatch, atlas: &HudAtlas) {
if mode == Overlay::Off || self.frames.is_empty() {
return;
}
let n = self.frames.len() as f32;
let avg = |f: fn(&(f32, f32, f32)) -> f32| self.frames.iter().map(f).sum::<f32>() / n;
let (frame, cpu, gpu) = (avg(|f| f.0), avg(|f| f.1), avg(|f| f.2));
let worst = self.frames.iter().map(|f| f.0).fold(0.0f32, f32::max);
let lines = [
format!("{:.0} fps", 1000.0 / frame.max(0.001)),
format!("frame {frame:.1} ms max {worst:.1}"),
format!("cpu {cpu:.1} gpu {gpu:.1} ms"),
];
let width = 120.0f32.max(
lines
.iter()
.map(|l| atlas.font.width(l))
.fold(0.0, f32::max)
+ 6.0,
);
let x = batch.width - width - 2.0;
let graph = if mode == Overlay::Graph { 42.0 } else { 0.0 };
batch.fill(
atlas,
x,
2.0,
width,
4.0 + lines.len() as f32 * 10.0 + graph,
rgba(0, 0, 0, 144),
);
for (i, line) in lines.iter().enumerate() {
let color = if i == 0 {
rgba(255, 255, 255, 255)
} else {
rgba(200, 200, 200, 255)
};
batch.text_styled(
atlas,
&Text::literal(line.clone()),
x + 3.0,
4.0 + i as f32 * 10.0,
color,
true,
);
}
if mode != Overlay::Graph {
return;
}
// Bars of frame time on a 0..33 ms scale; lines at 60 and 30 fps.
let (gy, gh) = (4.0 + lines.len() as f32 * 10.0 + 2.0, 36.0);
let scale = gh / 33.3;
let bar = (width - 6.0) / HISTORY as f32;
for (i, &(ms, cpu, _)) in self.frames.iter().enumerate() {
let height = (ms * scale).min(gh);
let bx = x + 3.0 + i as f32 * bar;
let color = if ms > 33.3 {
rgba(240, 90, 80, 255)
} else if ms > 16.7 {
rgba(240, 200, 90, 255)
} else {
rgba(110, 210, 120, 255)
};
batch.fill(atlas, bx, gy + gh - height, bar.max(1.0), height, color);
let cpu_height = (cpu * scale).min(height);
batch.fill(
atlas,
bx,
gy + gh - cpu_height,
bar.max(1.0),
cpu_height,
rgba(80, 140, 230, 200),
);
}
for target in [16.7, 33.3] {
let ly = gy + gh - target * scale;
batch.fill(
atlas,
x + 3.0,
ly,
width - 6.0,
1.0,
rgba(255, 255, 255, 90),
);
}
}
}
+291 -74
View File
@@ -38,7 +38,11 @@ use std::{
collections::{BTreeMap, HashMap},
fs,
path::{Path, PathBuf},
sync::{Arc, Mutex, OnceLock},
sync::{
Arc, Condvar, Mutex, OnceLock,
atomic::{AtomicU64, Ordering},
mpsc,
},
};
pub const VERSION_NAME: &str = "26.3";
@@ -1108,12 +1112,159 @@ pub fn load_light(tag: &Tag, chunk: &mut Chunk, sky_light: bool) {
}
type RegionCache = Mutex<HashMap<(i32, i32), Option<Arc<Mutex<RegionFile>>>>>;
/// Rewrite every region file in `folder` touched by `records`, keeping its
/// other chunks. `None` deletes a chunk.
fn write_region_records(
root: &Path,
cache: &RegionCache,
folder: &str,
records: Vec<((i32, i32), Option<Arc<NamedTag>>)>,
) -> Result<()> {
let mut by_region: BTreeMap<(i32, i32), Vec<((i32, i32), Option<Arc<NamedTag>>)>> =
BTreeMap::new();
for (key, tag) in records {
by_region
.entry((key.0 >> 5, key.1 >> 5))
.or_default()
.push((key, tag));
}
if by_region.is_empty() {
return Ok(());
}
let staging = root.join(folder).join(".staging");
fs::create_dir_all(&staging)?;
let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map_or(0, |d| d.as_secs() as u32);
for ((rx, rz), list) in by_region {
let path = region_path(root, folder, rx, rz);
let mut records: BTreeMap<(i32, i32), ChunkRecord> = BTreeMap::new();
let only_deletes = list.iter().all(|(_, tag)| tag.is_none());
if let Ok(mut existing) = RegionFile::open(&path) {
let positions: Vec<ChunkPos> = existing.chunks().map(|(p, _)| p).collect();
if only_deletes
&& !positions
.iter()
.any(|p| list.iter().any(|(k, _)| *k == (p.x, p.z)))
{
continue;
}
for p in positions {
if let Ok(Some(r)) = existing.read(p) {
records.insert((p.x, p.z), r);
}
}
} else if only_deletes {
continue;
}
// Deleting chunks the region doesn't hold changes nothing: leave
// the file alone (unloading empty entity chunks asks for that).
let mut changed = false;
for (key, tag) in list {
match tag {
Some(tag) => {
changed = true;
records.insert(
key,
ChunkRecord::from_nbt(
&tag,
Compression::Zlib,
timestamp,
Limits::default(),
)?,
);
}
None => {
changed |= records.remove(&key).is_some();
}
}
}
if !changed {
continue;
}
if records.is_empty() {
let _ = fs::remove_file(&path);
} else {
let temporary = staging.join(format!("r.{rx}.{rz}.mca"));
let _ = fs::remove_file(&temporary);
let mut writer = RegionWriter::create(&temporary)?;
for ((x, z), r) in &records {
writer.write(ChunkPos::new(*x, *z), r)?;
}
writer.finish()?;
fs::rename(&temporary, &path)?;
}
cache
.lock()
.map_err(|_| "region cache poisoned")?
.remove(&(rx, rz));
}
let _ = fs::remove_dir(&staging);
Ok(())
}
fn region_path(root: &Path, folder: &str, rx: i32, rz: i32) -> PathBuf {
root.join(format!("{folder}/r.{rx}.{rz}.mca"))
}
/// A record waiting for the writer thread.
#[derive(Clone)]
enum Record {
Tag(Arc<NamedTag>),
/// A chunk to encode on the writer thread.
Chunk(Arc<Chunk>, Arc<Encoding>),
Delete,
}
/// What encoding a chunk needs, captured when it is queued.
struct Encoding {
registry: &'static BlockRegistry,
biomes: Arc<Biomes>,
tables: Option<Arc<SaveTables>>,
sky_light: bool,
}
impl Record {
fn tag(&self) -> Option<Arc<NamedTag>> {
match self {
Record::Tag(t) => Some(t.clone()),
Record::Chunk(c, e) => Some(Arc::new(encode_with(
c,
e.registry,
&e.biomes,
e.tables.as_deref(),
e.sky_light,
))),
Record::Delete => None,
}
}
}
/// Chunk and entity records waiting for the writer thread, by (entities?,
/// x, z): reads see them before the region files do.
type PendingWrites = Mutex<HashMap<(bool, i32, i32), (u64, Record)>>;
type WriteBatch = (bool, Vec<((i32, i32), Record, u64)>);
/// The background thread that encodes chunks and rewrites region files, in
/// submission order.
struct Writer {
send: mpsc::Sender<WriteBatch>,
thread: std::thread::JoinHandle<()>,
}
/// Writes still queued or running, with a condition to wait for none.
#[derive(Default)]
struct Outstanding {
count: Mutex<usize>,
done: Condvar,
}
/// One dimension folder (`dimensions/minecraft/<name>`). Region files are
/// read lazily by worker threads.
pub struct SaveDir {
pub root: PathBuf,
regions: RegionCache,
entity_regions: RegionCache,
regions: Arc<RegionCache>,
entity_regions: Arc<RegionCache>,
pending: Arc<PendingWrites>,
sequence: AtomicU64,
writer: Mutex<Option<Writer>>,
outstanding: Arc<Outstanding>,
/// Set by `Persistent` before the first load.
pub tables: OnceLock<Arc<SaveTables>>,
/// False in dimensions without skylight (no SkyLight layers are written).
@@ -1124,16 +1275,29 @@ impl SaveDir {
let sky_light = !root.ends_with("the_nether") && !root.ends_with("DIM-1");
Self {
root,
regions: Mutex::new(HashMap::new()),
entity_regions: Mutex::new(HashMap::new()),
regions: Default::default(),
entity_regions: Default::default(),
pending: Default::default(),
sequence: AtomicU64::new(0),
writer: Mutex::new(None),
outstanding: Default::default(),
tables: OnceLock::new(),
sky_light,
}
}
fn region_path(&self, folder: &str, rx: i32, rz: i32) -> PathBuf {
self.root.join(format!("{folder}/r.{rx}.{rz}.mca"))
region_path(&self.root, folder, rx, rz)
}
fn read_record(&self, folder: &str, x: i32, z: i32) -> Option<NamedTag> {
let pending = self
.pending
.lock()
.ok()?
.get(&(folder != "region", x, z))
.map(|(_, r)| r.clone());
if let Some(record) = pending {
return record.tag().map(|t| (*t).clone());
}
let key = (x >> 5, z >> 5);
let cache = if folder == "region" {
&self.regions
@@ -1172,83 +1336,98 @@ impl SaveDir {
}
out
}
/// Rewrite every region file in `folder` touched by `records`, keeping
/// its other chunks. `None` deletes a chunk.
/// Queue `records` for the writer thread; with `wait`, return once
/// they and every earlier write are on disk.
fn write_records(
&self,
folder: &str,
records: Vec<((i32, i32), Option<NamedTag>)>,
wait: bool,
) -> Result<()> {
let mut by_region: BTreeMap<(i32, i32), Vec<((i32, i32), Option<NamedTag>)>> =
BTreeMap::new();
for (key, tag) in records {
by_region
.entry((key.0 >> 5, key.1 >> 5))
.or_default()
.push((key, tag));
}
if by_region.is_empty() {
return Ok(());
}
let staging = self.root.join(folder).join(".staging");
fs::create_dir_all(&staging)?;
let timestamp = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map_or(0, |d| d.as_secs() as u32);
let cache = if folder == "region" {
&self.regions
} else {
&self.entity_regions
};
for ((rx, rz), list) in by_region {
let path = self.region_path(folder, rx, rz);
let mut records: BTreeMap<(i32, i32), ChunkRecord> = BTreeMap::new();
if let Ok(mut existing) = RegionFile::open(&path) {
let positions: Vec<ChunkPos> = existing.chunks().map(|(p, _)| p).collect();
for p in positions {
if let Ok(Some(r)) = existing.read(p) {
records.insert((p.x, p.z), r);
}
let records = records
.into_iter()
.map(|(k, t)| (k, t.map_or(Record::Delete, |t| Record::Tag(Arc::new(t)))))
.collect();
self.queue(folder != "region", records, wait)
}
fn queue(&self, entities: bool, records: Vec<((i32, i32), Record)>, wait: bool) -> Result<()> {
if !records.is_empty() {
let mut batch = Vec::with_capacity(records.len());
{
let mut pending = self.pending.lock().map_err(|_| "pending writes poisoned")?;
for (key, record) in records {
let seq = self.sequence.fetch_add(1, Ordering::Relaxed);
pending.insert((entities, key.0, key.1), (seq, record.clone()));
batch.push((key, record, seq));
}
}
for (key, tag) in list {
match tag {
Some(tag) => {
records.insert(
key,
ChunkRecord::from_nbt(
&tag,
Compression::Zlib,
timestamp,
Limits::default(),
)?,
);
}
None => {
records.remove(&key);
}
}
}
if records.is_empty() {
let _ = fs::remove_file(&path);
} else {
let temporary = staging.join(format!("r.{rx}.{rz}.mca"));
let _ = fs::remove_file(&temporary);
let mut writer = RegionWriter::create(&temporary)?;
for ((x, z), r) in &records {
writer.write(ChunkPos::new(*x, *z), r)?;
}
writer.finish()?;
fs::rename(&temporary, &path)?;
}
cache
*self
.outstanding
.count
.lock()
.map_err(|_| "region cache poisoned")?
.remove(&(rx, rz));
.map_err(|_| "writer poisoned")? += 1;
let mut writer = self.writer.lock().map_err(|_| "writer poisoned")?;
let writer = writer.get_or_insert_with(|| self.start_writer());
if writer.send.send((entities, batch)).is_err() {
return Err("the region writer stopped".into());
}
}
if wait {
self.flush();
}
let _ = fs::remove_dir(&staging);
Ok(())
}
fn start_writer(&self) -> Writer {
let (send, receive) = mpsc::channel::<WriteBatch>();
let root = self.root.clone();
let (regions, entity_regions) = (self.regions.clone(), self.entity_regions.clone());
let pending = self.pending.clone();
let outstanding = self.outstanding.clone();
let thread = std::thread::Builder::new()
.name("horizon-region-writer".into())
.spawn(move || {
for (entities, batch) in receive {
let (folder, cache) = if entities {
("entities", &entity_regions)
} else {
("region", &regions)
};
let records = batch.iter().map(|(k, r, _)| (*k, r.tag())).collect();
if let Err(e) = write_region_records(&root, cache, folder, records) {
eprintln!("Horizon: failed to write {folder} files: {e}");
}
// Readers find the files (and a fresh region cache) from here on.
if let Ok(mut pending) = pending.lock() {
for (k, _, seq) in &batch {
if pending
.get(&(entities, k.0, k.1))
.is_some_and(|p| p.0 == *seq)
{
pending.remove(&(entities, k.0, k.1));
}
}
}
if let Ok(mut count) = outstanding.count.lock() {
*count -= 1;
outstanding.done.notify_all();
}
}
})
.expect("spawn region writer");
Writer { send, thread }
}
/// Wait until every queued write is on disk.
pub fn flush(&self) {
let Ok(mut count) = self.outstanding.count.lock() else {
return;
};
while *count > 0 {
count = match self.outstanding.done.wait(count) {
Ok(c) => c,
Err(_) => return,
};
}
}
/// Rewrite every region touched by `chunks`, keeping their other chunks.
pub fn save(
&self,
@@ -1266,11 +1445,39 @@ impl SaveDir {
)
})
.collect();
self.write_records("region", records)?;
self.write_records("region", records, true)?;
Ok(chunks.len())
}
/// `save` on the writer thread: returns before the files are written;
/// loads see the chunks meanwhile.
pub fn save_later(
&self,
chunks: &[Arc<Chunk>],
registry: &'static BlockRegistry,
biomes: &Arc<Biomes>,
) -> Result<usize> {
let encoding = Arc::new(Encoding {
registry,
biomes: biomes.clone(),
tables: self.tables.get().cloned(),
sky_light: self.sky_light,
});
let records = chunks
.iter()
.map(|c| ((c.x, c.z), Record::Chunk(c.clone(), encoding.clone())))
.collect();
self.queue(false, records, false)?;
Ok(chunks.len())
}
/// Write the entity chunks (`EntityStorage`): an empty list deletes it.
pub fn save_entities(&self, chunks: Vec<((i32, i32), Vec<Tag>)>) -> Result<()> {
self.write_entities(chunks, true)
}
/// `save_entities` on the writer thread.
pub fn save_entities_later(&self, chunks: Vec<((i32, i32), Vec<Tag>)>) -> Result<()> {
self.write_entities(chunks, false)
}
fn write_entities(&self, chunks: Vec<((i32, i32), Vec<Tag>)>, wait: bool) -> Result<()> {
let records = chunks
.into_iter()
.map(|((x, z), entities)| {
@@ -1285,7 +1492,17 @@ impl SaveDir {
((x, z), tag)
})
.collect();
self.write_records("entities", records)
self.write_records("entities", records, wait)
}
}
impl Drop for SaveDir {
/// Finish queued writes before the world is let go.
fn drop(&mut self) {
if let Some(writer) = self.writer.get_mut().ok().and_then(Option::take) {
drop(writer.send);
let _ = writer.thread.join();
}
}
}
+19 -2
View File
@@ -175,6 +175,8 @@ pub struct Settings {
pub toggle_use: bool,
/// Taps of the sprint key counted as double taps (sprintWindow).
pub sprint_window: i32,
/// Horizon's own graphics settings (`horizon-graphics.txt`, not options.txt).
pub horizon: crate::graphics::Graphics,
}
impl Default for Settings {
fn default() -> Self {
@@ -243,6 +245,7 @@ impl Default for Settings {
toggle_attack: false,
toggle_use: false,
sprint_window: 7,
horizon: Default::default(),
}
}
}
@@ -273,10 +276,20 @@ fn put_s(f: &mut OptionsFile, key: &str, v: &str) {
}
impl Settings {
pub fn load(path: &Path) -> Self {
let horizon = path
.parent()
.map(crate::graphics::Graphics::load)
.unwrap_or_default();
let Ok(bytes) = fs::read(path) else {
return Self::default();
return Self {
horizon,
..Self::default()
};
};
Self::parse(&String::from_utf8_lossy(&bytes))
Self {
horizon,
..Self::parse(&String::from_utf8_lossy(&bytes))
}
}
pub fn parse(text: &str) -> Self {
Self::from_file(OptionsFile::parse(text))
@@ -332,6 +345,7 @@ impl Settings {
toggle_attack: f.bool("toggleAttack"),
toggle_use: f.bool("toggleUse"),
sprint_window: f.int("sprintWindow"),
horizon: Default::default(),
auto_jump: f.bool("autoJump"),
language: f.string("lang"),
force_unicode: f.bool("forceUnicodeFont"),
@@ -461,6 +475,9 @@ impl Settings {
}
pub fn save(&self, path: &Path) {
let _ = fs::write(path, self.serialize());
if let Some(dir) = path.parent() {
self.horizon.save(dir);
}
}
/// Volume of a sound source (master excluded).
pub fn volume(&self, source: &str) -> f32 {
+43
View File
@@ -0,0 +1,43 @@
//! Named timings within a frame, for finding what makes a frame slow:
//! `HORIZON_SPIKES=MS` prints the spans of every frame whose CPU time
//! exceeds MS milliseconds. Costs one clock read per span when enabled and
//! a relaxed load otherwise.
use std::{
cell::RefCell,
sync::atomic::{AtomicBool, Ordering},
time::Instant,
};
static ENABLED: AtomicBool = AtomicBool::new(false);
thread_local! {
static SPANS: RefCell<Vec<(&'static str, f32)>> = const { RefCell::new(Vec::new()) };
}
pub fn enable(on: bool) {
ENABLED.store(on, Ordering::Relaxed);
}
/// Run `f`, recording its duration under `name` when spans are enabled.
#[inline]
pub fn time<T>(name: &'static str, f: impl FnOnce() -> T) -> T {
if !ENABLED.load(Ordering::Relaxed) {
return f();
}
let started = Instant::now();
let out = f();
let ms = started.elapsed().as_secs_f32() * 1000.0;
SPANS.with(|s| s.borrow_mut().push((name, ms)));
out
}
/// The frame's spans, summed by name, slowest first; clears them.
pub fn take() -> Vec<(&'static str, f32)> {
let spans = SPANS.with(|s| std::mem::take(&mut *s.borrow_mut()));
let mut sums: Vec<(&'static str, f32)> = Vec::new();
for (name, ms) in spans {
match sums.iter_mut().find(|(n, _)| *n == name) {
Some(entry) => entry.1 += ms,
None => sums.push((name, ms)),
}
}
sums.sort_by(|a, b| b.1.total_cmp(&a.1));
sums
}
+28 -21
View File
@@ -2,6 +2,7 @@
//! around the player, closest first. The game thread owns the world and only
//! hands immutable `Arc` snapshots to workers; results carry a sequence number
//! so stale work is dropped.
use crate::fast_hash::{FxHashMap, FxHashSet};
use crate::{
chunk::{Chunk, SECTIONS},
light::{LightTables, light_chunk},
@@ -10,7 +11,7 @@ use crate::{
};
use horizon_core::biome::BiomeZoom;
use std::{
collections::{BinaryHeap, HashMap, HashSet},
collections::{BinaryHeap, HashSet},
sync::{
Arc, Condvar, Mutex,
atomic::{AtomicBool, Ordering},
@@ -98,19 +99,19 @@ pub struct Streaming {
results: mpsc::Receiver<Done>,
threads: Vec<thread::JoinHandle<()>>,
order: u64,
generating: HashSet<(i32, i32)>,
generating: FxHashSet<(i32, i32)>,
/// Proto chunks: `None` while checked out to a decoration job.
protos: HashMap<(i32, i32), Option<Proto>>,
decorated: HashSet<(i32, i32)>,
protos: FxHashMap<(i32, i32), Option<Proto>>,
decorated: FxHashSet<(i32, i32)>,
decorating: usize,
finishing: HashSet<(i32, i32)>,
finishing: FxHashSet<(i32, i32)>,
decorates: bool,
lighting: HashMap<(i32, i32), u64>,
meshing: HashMap<(i32, i32, i32), u64>,
lighting: FxHashMap<(i32, i32), u64>,
meshing: FxHashMap<(i32, i32, i32), u64>,
/// Chunks whose light is current.
lit: HashSet<(i32, i32)>,
lit: FxHashSet<(i32, i32)>,
/// Columns whose sections have been meshed at least once.
meshed: HashSet<(i32, i32)>,
meshed: FxHashSet<(i32, i32)>,
sequence: u64,
pub center: (i32, i32),
pub radius: i32,
@@ -133,7 +134,7 @@ pub struct Streaming {
light_log: Vec<(u64, (i32, i32, i32))>,
light_edit_sequence: u64,
/// Edit sequence at each in-flight light job's snapshot.
light_snapshots: HashMap<(i32, i32), u64>,
light_snapshots: FxHashMap<(i32, i32), u64>,
pub generated_total: u64,
pub meshed_total: u64,
/// Chunks come from a server (`insert_remote`/`forget`): nothing is
@@ -234,16 +235,16 @@ impl Streaming {
results,
threads,
order: 0,
generating: HashSet::new(),
protos: HashMap::new(),
decorated: HashSet::new(),
generating: Default::default(),
protos: Default::default(),
decorated: Default::default(),
decorating: 0,
finishing: HashSet::new(),
finishing: Default::default(),
decorates: generator.decorates(),
lighting: HashMap::new(),
meshing: HashMap::new(),
lit: HashSet::new(),
meshed: HashSet::new(),
lighting: Default::default(),
meshing: Default::default(),
lit: Default::default(),
meshed: Default::default(),
sequence: 0,
center: (0, 0),
radius: 8,
@@ -258,7 +259,7 @@ impl Streaming {
light_tables,
light_log: Vec::new(),
light_edit_sequence: 0,
light_snapshots: HashMap::new(),
light_snapshots: Default::default(),
generated_total: 0,
meshed_total: 0,
remote: false,
@@ -631,13 +632,19 @@ impl Streaming {
}
// Meshing once the column and its neighbours are lit.
let dirty: Vec<_> = world.dirty_sections.iter().copied().collect();
let mut columns: HashMap<(i32, i32), Option<Box<Region>>> = HashMap::new();
let mut columns: FxHashMap<(i32, i32), Option<Box<Region>>> = FxHashMap::default();
let mut ready_columns: FxHashMap<(i32, i32), bool> = FxHashMap::default();
for (x, sy, z) in dirty {
if !world.chunks.contains_key(&(x, z)) || !self.in_main_range(x, z, 0) {
world.dirty_sections.remove(&(x, sy, z));
continue;
}
let ready = (-1..=1).all(|dz| (-1..=1).all(|dx| self.lit.contains(&(x + dx, z + dz))));
// Once per column: the 3x3 lit check would otherwise repeat for
// each of its sections every frame.
let lit = &self.lit;
let ready = *ready_columns.entry((x, z)).or_insert_with(|| {
(-1..=1).all(|dz| (-1..=1).all(|dx| lit.contains(&(x + dx, z + dz))))
});
if !ready || self.lighting.contains_key(&(x, z)) {
continue;
}
+48
View File
@@ -1027,6 +1027,54 @@ impl<'a> Ui<'a> {
);
h
}
/// A settings row with, under its label, a one-line description led by
/// the setting's frame-time cost (`cost` 0 none .. 3 high, coloured from
/// faint to the danger colour). Same height as [`Ui::row`].
#[allow(clippy::too_many_arguments)]
pub fn described_row(
&mut self,
x: f32,
y: f32,
label: &str,
value: &str,
value_w: f32,
cost: (u8, &str),
description: &str,
description_w: f32,
) -> f32 {
let h = 12.0 + CONTROL + 12.0;
let top = y + 8.0;
self.text(Face::Regular, BODY, x, top, color::TEXT, label);
let value = self.fit(Face::Regular, BODY, value, value_w);
self.text(
Face::Regular,
BODY,
x + ROW_LABEL + 16.0,
top,
color::MUTED,
&value,
);
let dy = top + (BODY * 1.45).round();
let tint = [0.0, 0.2, 0.55, 1.0][usize::from(cost.0.min(3))];
let cost_color = color::mix(color::FAINT, color::DANGER, tint);
self.text(Face::Medium, SMALL, x, dy, cost_color, cost.1);
let used = self.measure(Face::Medium, SMALL, cost.1);
let rest = self.fit(
Face::Regular,
SMALL,
description,
(description_w - used - 8.0).max(0.0),
);
self.text(
Face::Regular,
SMALL,
x + used + 8.0,
dy,
color::FAINT,
&rest,
);
h
}
/// A slider in the launcher's language: a 4px track in the border colour
/// filled with the accent, a white 14px knob. Dragging is the screen's
/// job (see [`slider_value`]).
+17
View File
@@ -174,6 +174,23 @@ impl LimiterClock for SystemClock {
}
}
/// The real clock without busy waiting: where vanilla spins on
/// `Thread.onSpinWait` for the last half millisecond, this sleeps in short
/// steps, so a capped frame rate leaves the core idle.
#[derive(Clone, Copy, Debug, Default)]
pub struct SleepingClock(pub SystemClock);
impl LimiterClock for SleepingClock {
fn nanos(&mut self) -> i64 {
self.0.nanos()
}
fn park(&mut self, nanos: i64) {
self.0.park(nanos);
}
fn spin(&mut self) {
std::thread::sleep(std::time::Duration::from_micros(50));
}
}
/// `Minecraft.runTick`'s frame-limiter step: only limits below 260
/// (the "unlimited" setting) pace frames.
pub fn end_frame(
+6 -6
View File
@@ -9,15 +9,15 @@ use std::{
};
pub struct World {
pub chunks: HashMap<(i32, i32), Arc<Chunk>>,
pub chunks: crate::fast_hash::FxHashMap<(i32, i32), Arc<Chunk>>,
pub random: LegacyRandom,
pub revision: u64,
pub health_rules: crate::health::HealthRules,
pub air: BlockStateId,
/// Sections whose geometry changed and need remeshing.
pub dirty_sections: HashSet<(i32, i32, i32)>,
pub dirty_sections: crate::fast_hash::FxHashSet<(i32, i32, i32)>,
/// Chunks whose light must be recomputed.
pub dirty_light: HashSet<(i32, i32)>,
pub dirty_light: crate::fast_hash::FxHashSet<(i32, i32)>,
/// Edits on lit chunks (position, old state, new state), relit
/// incrementally by streaming.
pub light_edits: Vec<((i32, i32, i32), u16, u16)>,
@@ -108,13 +108,13 @@ impl Weather {
impl World {
pub fn new(air: BlockStateId, seed: i64) -> Self {
Self {
chunks: HashMap::new(),
chunks: Default::default(),
random: LegacyRandom::new(seed),
revision: 0,
health_rules: crate::health::HealthRules::default(),
air,
dirty_sections: HashSet::new(),
dirty_light: HashSet::new(),
dirty_sections: Default::default(),
dirty_light: Default::default(),
light_edits: Vec::new(),
loaded_entities: Vec::new(),
modified: HashSet::new(),
+55
View File
@@ -0,0 +1,55 @@
// Horizon's world post pass: the world, rendered at the resolution scale,
// copied (bilinear) or anti-aliased with FXAA onto the screen before the
// hand and HUD. Only used when a non-vanilla setting asks for it.
@group(0) @binding(0) var world: texture_2d<f32>;
@group(0) @binding(1) var world_sampler: sampler;
struct PostOut {
@builtin(position) clip: vec4<f32>,
@location(0) uv: vec2<f32>,
};
@vertex fn vs_post(@builtin(vertex_index) i: u32) -> PostOut {
let p = vec2<f32>(f32((i << 1u) & 2u), f32(i & 2u));
var out: PostOut;
out.clip = vec4(p * 2.0 - 1.0, 0.0, 1.0);
out.uv = vec2(p.x, 1.0 - p.y);
return out;
}
@fragment fn fs_copy(in: PostOut) -> @location(0) vec4<f32> {
return vec4(textureSampleLevel(world, world_sampler, in.uv, 0.0).rgb, 1.0);
}
fn luma(c: vec3<f32>) -> f32 {
return dot(c, vec3(0.299, 0.587, 0.114));
}
// FXAA 3.11 (console quality): blend along the local edge direction.
@fragment fn fs_fxaa(in: PostOut) -> @location(0) vec4<f32> {
let texel = 1.0 / vec2<f32>(textureDimensions(world));
let rgb_m = textureSampleLevel(world, world_sampler, in.uv, 0.0).rgb;
let nw = luma(textureSampleLevel(world, world_sampler, in.uv + vec2(-0.5, -0.5) * texel, 0.0).rgb);
let ne = luma(textureSampleLevel(world, world_sampler, in.uv + vec2(0.5, -0.5) * texel, 0.0).rgb);
let sw = luma(textureSampleLevel(world, world_sampler, in.uv + vec2(-0.5, 0.5) * texel, 0.0).rgb);
let se = luma(textureSampleLevel(world, world_sampler, in.uv + vec2(0.5, 0.5) * texel, 0.0).rgb);
let m = luma(rgb_m);
let lo = min(m, min(min(nw, ne), min(sw, se)));
let hi = max(m, max(max(nw, ne), max(sw, se)));
if hi - lo < max(0.0312, hi * 0.125) {
return vec4(rgb_m, 1.0);
}
var dir = vec2(-((nw + ne) - (sw + se)), (nw + sw) - (ne + se));
let reduce = max((nw + ne + sw + se) * 0.25 * 0.125, 1.0 / 128.0);
let scale = 1.0 / (min(abs(dir.x), abs(dir.y)) + reduce);
dir = clamp(dir * scale, vec2(-8.0), vec2(8.0)) * texel;
let a = 0.5 * (textureSampleLevel(world, world_sampler, in.uv + dir * (1.0 / 3.0 - 0.5), 0.0).rgb
+ textureSampleLevel(world, world_sampler, in.uv + dir * (2.0 / 3.0 - 0.5), 0.0).rgb);
let b = a * 0.5 + 0.25 * (textureSampleLevel(world, world_sampler, in.uv - dir * 0.5, 0.0).rgb
+ textureSampleLevel(world, world_sampler, in.uv + dir * 0.5, 0.0).rgb);
let lb = luma(b);
if lb < lo || lb > hi {
return vec4(a, 1.0);
}
return vec4(b, 1.0);
}
+1
View File
@@ -6,6 +6,7 @@ To play, use [the launcher](../launcher/README.md). These pages are for develope
- [Build from source](../README.md#build-from-source): your own copy of the game, resource preparation, `cargo run`.
- [Native client](native-client.md): options, controls, the dedicated server, `horizon-ctl` scripting, packaging, architecture.
- [Graphics](graphics.md): the Simple and Advanced graphics settings, the graphics benchmark and what it measured.
- [Launcher](../launcher/README.md): installs, updates and starts builds; its CLI and MCP server; releasing it.
- Menus: the title, world list, create world, multiplayer, options and pause screens share the launcher's design tokens and fonts (`crates/horizon-theme`), drawn by `ui_theme` over a live frozen backdrop (`game/backdrop.rs`, blurred and graded by `post.rs`). Options → Interface → Menu style switches to vanilla's screens (Classic, kept in `horizon.txt`; `HORIZON_MENU_STYLE=horizon|classic` overrides it, and scripted runs default to Classic). [Title](media/menu-title.png) ([webm](media/menu-title.webm)), [worlds](media/menu-worlds.png), [options](media/menu-options.png), [pause](media/menu-pause.png).
+96
View File
@@ -0,0 +1,96 @@
# Graphics: settings and performance
## Settings
In the Horizon menu style, the Options screen's **Video** section holds the graphics settings, with a Simple / Advanced switch at the top (remembered between sessions):
- **Simple**: a preset (Performance, Balanced, Quality, Ultra or Custom), render distance, FOV, max framerate, VSync and GUI scale.
- **Advanced**: every setting, grouped under Rendering, Quality, Display, Preferences, Performance and Overlay.
In the Classic style, Video Settings starts with two buttons opening the same settings as vanilla-looking screens.
Every row has a one-line description and its cost in frame time (none, low, medium, high), and applies at once, except worker threads, which apply at the next start. A preset sets the quality settings together; changing one of them turns it into Custom. Display preferences (FOV, framerate, VSync, GUI scale, fullscreen, present mode, pacing) leave the preset as it is.
![Simple](media/settings-simple.png)
![Advanced](media/settings-advanced.png)
| Group | Setting | Stored in |
| --- | --- | --- |
| Rendering | render distance, simulation distance, entity distance | `options.txt` (vanilla keys) |
| | cave culling, chunk updates per frame | `horizon-graphics.txt` |
| Quality | smooth lighting, mipmap levels, biome blend, clouds, cloud distance, weather radius, particles, entity shadows, cutout leaves | `options.txt` |
| | sky, fog, weather, animated textures | `horizon-graphics.txt` |
| Display | FOV, max framerate, VSync, fullscreen, GUI scale | `options.txt` |
| | resolution scale, anti-aliasing (FXAA), present mode, frame pacing | `horizon-graphics.txt` |
| Performance | worker threads, upload budget per frame | `horizon-graphics.txt` |
| Overlay | performance overlay: FPS, frame/CPU/GPU times, frame-time graph | `horizon-graphics.txt` |
`options.txt` keeps exactly vanilla's keys and values, so the options harness still compares it with vanilla; Horizon's settings live in `horizon-graphics.txt` beside it. Their defaults render as vanilla does: cave culling on, no upload budgets, sky, fog and weather on, 100% resolution, no FXAA, the present mode following VSync. Frame pacing defaults to Efficient: the limiter sleeps through the last half millisecond where vanilla spins, which changes timing, not pixels.
Which settings each level shows, their descriptions and costs are in `crates/horizon-client/src/graphics_ui.rs` (`rows`); the Horizon shell draws them in `options_horizon.rs` with `ui_theme::described_row`, and the Classic screens use `graphics_style.rs`.
Not implemented: distant-terrain LOD, anisotropic filtering (wgpu needs linear magnification for it, which blurs close blocks), MSAA (FXAA instead) and exclusive fullscreen (fullscreen is borderless).
## Benchmark
`tools/graphics_bench.py` opens a fresh creative world (seed 1234) on a virtual screen and flies the camera along four fixed 192-block paths, over a village, a forest, the ocean and a mountain, at render distances 8, 16 and 32, one game per distance. Each flight takes 12 seconds and reports average FPS, 1% lows, frame-time percentiles, CPU time per frame (frame time minus waits for the GPU, the display and the limiter), the split of that CPU time (world update, ticks, frame preparation, renderer) for all frames and for the slowest 1%, and GPU time per frame from timestamp queries.
```sh
cargo build --release -p horizon-client --bins
python3 tools/graphics_bench.py --label mine # lavapipe on vscreen: CPU-side numbers
python3 tools/graphics_bench.py --label mine-gpu --offscreen # the desktop's RTX 4080
python3 tools/graphics_bench.py --compare baseline-4080 mine-gpu # markdown table
```
vscreen is a headless compositor whose frames are software-rendered (lavapipe), so its frame times measure the CPU, rasterisation included. `--offscreen` (`horizon-client --offscreen`) renders into a texture on the most powerful GPU instead of the window, which measures the RTX 4080 under the same compositor. `--distances`, `--scenes` and `--build` pick a subset or another build. Results go to `benchmarks/graphics/<label>.json`, with the load average before and after: the desktop is shared, and other sessions' builds move the numbers.
Two tools find where a slow frame goes: `HORIZON_SPIKES=MS` prints the timed spans (ticks by system, streaming, uploads, saving, renderer) of every frame slower than MS milliseconds, and a frame-pointer build (`RUSTFLAGS="-C force-frame-pointers=yes"`) profiles with `perf record --call-graph fp`.
## Results
Baseline `27a32cc3` (main) against `9006566b`, the same full run (render distances 8, 16 then 32 in one fresh world), on ludodesktop.
RTX 4080, `--offscreen` (`benchmarks/graphics/baseline-4080.json`, `after-4080.json`):
| RD | scene | avg FPS | 1% low FPS | p99 ms | CPU ms/frame | GPU ms/frame |
| --- | --- | --- | --- | --- | --- | --- |
| 8 | village | 363 → 2409 | 21.6 → 160.8 | 37 → 1 | 2.7 → 0.4 | 0.42 → 0.10 |
| 8 | forest | 613 → 1099 | 49.6 → 82.9 | 10 → 10 | 1.6 → 0.9 | 0.40 → 0.26 |
| 8 | ocean | 323 → 687 | 5.4 → 47.5 | 33 → 16 | 2.7 → 1.4 | 0.24 → 0.37 |
| 8 | mountain | 28 → 344 | 7.4 → 30.0 | 111 → 33 | 12.4 → 1.6 | 0.46 → 0.34 |
| 16 | village | 8 → 1041 | 2.4 → 64.0 | 409 → 10 | 138.3 → 1.0 | 3.59 → 0.23 |
| 16 | forest | 28 → 316 | 0.5 → 49.6 | 159 → 18 | 37.9 → 3.2 | 2.68 → 0.75 |
| 16 | ocean | 59 → 385 | 10.5 → 72.0 | 85 → 12 | 16.8 → 2.6 | 1.96 → 0.68 |
| 16 | mountain | 27 → 220 | 7.8 → 30.0 | 109 → 33 | 20.2 → 3.1 | 7.14 → 0.94 |
| 32 | village | 4 → 48 | 2.6 → 0.8 | 387 → 76 | 244.2 → 9.4 | 10.36 → 1.77 |
| 32 | forest | 8 → 28 | 3.7 → 0.9 | 261 → 1108 | 118.7 → 40.1 | 15.90 → 2.30 |
| 32 | ocean | 2 → 67 | 1.6 → 10.1 | 626 → 95 | 424.8 → 14.7 | 9.48 → 2.91 |
| 32 | mountain | 3 → 29 | 2.5 → 15.2 | 407 → 64 | 300.5 → 16.1 | 9.73 → 8.47 |
lavapipe on vscreen, CPU-rendered (`baseline-lavapipe.json`, `after-lavapipe.json`); at 16 and 32 chunks most of the frame is software rasterisation, which no change here touches:
| RD | scene | avg FPS | 1% low FPS | p99 ms | CPU ms/frame | GPU ms/frame |
| --- | --- | --- | --- | --- | --- | --- |
| 8 | village | 16 → 58 | 6.6 → 31.3 | 134 → 29 | 48.2 → 11.4 | 26.73 → 13.52 |
| 8 | forest | 20 → 42 | 9.9 → 20.0 | 95 → 37 | 31.0 → 18.0 | 37.27 → 21.36 |
| 8 | ocean | 28 → 60 | 1.5 → 34.8 | 181 → 27 | 25.7 → 10.9 | 18.86 → 12.74 |
| 8 | mountain | 27 → 38 | 11.2 → 27.3 | 75 → 34 | 22.5 → 11.5 | 23.76 → 14.11 |
| 16 | village | 11 → 21 | 4.2 → 8.8 | 227 → 75 | 69.2 → 31.8 | 49.04 → 40.50 |
| 16 | forest | 12 → 18 | 5.7 → 11.5 | 137 → 81 | 58.4 → 36.8 | 56.45 → 47.82 |
| 16 | ocean | 8 → 8 | 2.6 → 4.8 | 385 → 209 | 98.4 → 96.7 | 71.51 → 57.30 |
| 16 | mountain | 6 → 12 | 3.1 → 4.9 | 321 → 189 | 124.9 → 56.7 | 95.47 → 70.81 |
| 32 | village | 3 → 5 | 2.0 → 3.6 | 497 → 278 | 345.6 → 111.2 | 85.50 → 121.35 |
| 32 | forest | 2 → 4 | 1.5 → 3.4 | 656 → 296 | 354.8 → 155.5 | 201.54 → 192.78 |
| 32 | ocean | 3 → 3 | 1.2 → 2.2 | 849 → 465 | 330.8 → 288.0 | 113.80 → 116.97 |
| 32 | mountain | 3 → 4 | 1.8 → 2.4 | 570 → 414 | 325.2 → 171.4 | 104.99 → 166.80 |
Render distance 32 still has long stalls in the forest and village flights: the slowest frames are game ticks (mob AI bursts as chunks load, and thousands of dropped items piling up in some chunks, which the sequential run accumulates), not rendering. Results swing between runs on the shared desktop; the probe runs during the work saw RD 32 forest from 15 to 335 FPS depending on what the world had accumulated.
## What changed
The baseline was CPU-bound everywhere: on the RTX 4080 the GPU spent 0.2 to 16 ms per frame, the CPU 2 to 425.
- **Ticking**: mobs, minecarts and dropped items outside the entity-ticking chunks (the simulation distance, as `DistanceManager.inEntityTickingRange`) only check despawning, as in `ServerLevel.tick`; every loaded one used to tick, so render distance 32 ticked seven times as many as vanilla. Villager POI searches skip sections whose palette holds no POI block. Sky darkening is sampled once per time and weather instead of once per mob, and the world's chunk map uses a fast hash.
- **Stalls**: chunks and entity chunks unloaded while moving are encoded and written by a background region writer (loads see queued records first, saves wait for the queue); deleting entity chunks a region doesn't hold no longer rewrites the region file; unloading drops block entities in one pass instead of one per chunk.
- **Rendering**: terrain sections share one vertex arena drawn with one indirect multi-draw per pass, instead of a buffer and draw call each; the cave-culling search runs on dense arrays; mobs are culled by the view frustum and vanilla's per-entity render distance, block entities by the frustum; per-frame scratch buffers are reused.
- **Streaming**: its bookkeeping uses the fast hash, and a column's readiness for meshing is checked once per frame rather than once per dirty section.
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 988 KiB

+4
View File
@@ -83,6 +83,10 @@ $C bench 10 # avg/1%-low FPS and p50/p95/p99/max frame tim
$C quit # save and exit
```
`fly X1 Y1 Z1 X2 Y2 Z2 SECONDS [PITCH]` moves the camera along a line at
constant speed and replies with the same summary as `bench`, plus CPU and GPU
time per frame; [the graphics benchmark](graphics.md#benchmark) is built on it.
Other commands: `status`, `key KEY down|up|tap`, `mouse left|right|middle
down|up|click`, `turn`, `tp X Y Z`, `hotbar N`, `give ITEM [COUNT]`,
`render-distance N`, `time TICKS`, `resume`, `stats [reset]`, `open WORLD [SEED]
+197
View File
@@ -0,0 +1,197 @@
#!/usr/bin/env python3
"""Repeatable graphics benchmark for the native client.
Opens a fresh seeded creative world on a virtual screen (vscreen) and flies the
camera along fixed straight paths over a village, a forest, the ocean and a
mountain, at render distances 8, 16 and 32. Each flight replies with frame
times (average FPS, 1% lows, percentiles), the CPU part of each frame and the
GPU time from timestamp queries.
python3 tools/graphics_bench.py --label baseline
python3 tools/graphics_bench.py --label baseline --offscreen # the discrete GPU
`--offscreen` renders into a texture instead of the window, so the desktop's
GPU can be measured even though the headless compositor (vscreen) only
presents software-rendered (lavapipe) frames. Without it, frame times on
vscreen are lavapipe's: use them for CPU-side numbers.
"""
import argparse
import datetime
import json
import os
import shutil
import subprocess
import sys
import time
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
SEED = "1234"
WORLD = "GraphicsBench"
# (name, from xyz, to xyz, pitch): straight flights at a constant speed over
# fixed scenery of seed 1234. Each path is 192 blocks long.
SCENES = [
("village", (-960.0, 125.0, 80.0), (-960.0, 125.0, 272.0), 35.0),
("forest", (-1100.0, 120.0, -560.0), (-1100.0, 120.0, -368.0), 25.0),
("ocean", (-300.0, 85.0, -420.0), (-300.0, 85.0, -228.0), 10.0),
("mountain", (560.0, 260.0, 860.0), (752.0, 260.0, 860.0), 30.0),
]
OPTIONS = """version:4790
enableVsync:false
maxFps:260
renderDistance:{distance}
simulationDistance:12
fov:0.0
guiScale:0
"""
def vscreen_env():
out = subprocess.run(["vscreen", "env"], cwd=ROOT, capture_output=True, text=True, check=True)
env = dict(os.environ)
for part in out.stdout.replace(";", " ").split():
if "=" in part and not part.startswith("export"):
k, v = part.split("=", 1)
env[k] = v
env.pop("DISPLAY", None)
# Benchmark games never play sound on the machine's speakers.
env["HORIZON_NO_AUDIO"] = "1"
return env
class Game:
def __init__(self, ctl, socket, env, cwd):
self.ctl, self.socket, self.env, self.cwd = ctl, socket, env, cwd
def run(self, *words, check=True):
out = subprocess.run(
[str(self.ctl), "--socket", str(self.socket), *map(str, words)],
cwd=self.cwd, env=self.env, capture_output=True, text=True,
)
line = out.stdout.strip().splitlines()[-1] if out.stdout.strip() else "{}"
reply = json.loads(line) if line.startswith("{") else {"error": out.stderr.strip()}
if check and "error" in reply:
raise RuntimeError(f"{' '.join(map(str, words))}: {reply} {out.stderr.strip()}")
return reply
def run_distance(args, ctl, env, cwd, distance):
(cwd / "options.txt").write_text(OPTIONS.format(distance=distance))
socket = cwd / "control.sock"
game = Game(ctl, socket, env, cwd)
launch = [
"launch", "--world", WORLD, "--seed", SEED, "--creative",
"--render-distance", distance, "--resources", args.resources,
"--no-pause", "--weather", "clear", "--time", "6000",
]
if args.offscreen:
launch.append("--offscreen")
game.run(*launch)
results = {}
try:
game.run("wait-ready", 300)
status = game.run("status")
results["renderer"] = status.get("renderer")
for name, start, end, pitch in SCENES:
if args.scenes and name not in args.scenes.split(","):
continue
game.run("tp", *start)
game.run("look", 0, pitch)
game.run("time", 6000)
game.run("wait-ready", 300)
time.sleep(args.settle)
summary = game.run("fly", *start, *end, args.seconds, pitch)
results[name] = summary
print(
f" rd {distance:>2} {name:<9} {summary.get('avg_fps', 0):7.1f} fps"
f" 1% low {summary.get('low_1pct_fps', 0):7.1f}"
f" p99 {summary.get('p99_ms', 0):6.2f} ms"
f" cpu {((summary.get('cpu') or {}).get('avg_ms') or 0):6.2f} ms"
f" gpu {((summary.get('gpu') or {}).get('avg_ms') or 0):6.2f} ms"
+ " [" + " ".join(f"{k} {v:.2f}" for k, v in (summary.get("phases_avg_ms") or {}).items()) + "]"
+ " slow [" + " ".join(f"{k} {v:.1f}" for k, v in (summary.get("slow_phases_avg_ms") or {}).items()) + "]",
flush=True,
)
finally:
game.run("quit", check=False)
for _ in range(100):
if not socket.exists():
break
time.sleep(0.2)
# Keep each game's log (a crash or a slow-frame report) per run.
log = socket.with_suffix(".log")
if log.exists():
shutil.copy(log, cwd / f"{args.label}-rd{distance}.log")
return results
def compare(before, after):
"""A markdown table of two saved runs (labels under benchmarks/graphics)."""
load = lambda label: json.loads((ROOT / "benchmarks/graphics" / f"{label}.json").read_text())
a, b = load(before), load(after)
print(f"| RD | scene | avg FPS | 1% low FPS | p99 ms | CPU ms/frame | GPU ms/frame |")
print("| --- | --- | --- | --- | --- | --- | --- |")
cell = lambda x, y, f: f"{f(x)} → {f(y)}"
for rd, scenes in a["distances"].items():
for name, old in scenes.items():
new = b["distances"].get(rd, {}).get(name)
if name == "renderer" or not new:
continue
ms = lambda v, k: (v.get(k) or {}).get("avg_ms") or 0
print(f"| {rd} | {name} | {cell(old['avg_fps'], new['avg_fps'], lambda v: f'{v:.0f}')} "
f"| {cell(old['low_1pct_fps'], new['low_1pct_fps'], lambda v: f'{v:.1f}')} "
f"| {cell(old['p99_ms'], new['p99_ms'], lambda v: f'{v:.0f}')} "
f"| {cell(ms(old, 'cpu'), ms(new, 'cpu'), lambda v: f'{v:.1f}')} "
f"| {cell(ms(old, 'gpu'), ms(new, 'gpu'), lambda v: f'{v:.2f}')} |")
def main():
p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
p.add_argument("--label", default="run")
p.add_argument("--distances", default="8,16,32")
p.add_argument("--scenes", help="comma-separated subset of " + ",".join(s[0] for s in SCENES))
p.add_argument("--seconds", type=float, default=12.0, help="flight duration per scene")
p.add_argument("--settle", type=float, default=2.0, help="seconds to wait before each flight")
p.add_argument("--offscreen", action="store_true", help="render offscreen on the discrete GPU")
p.add_argument("--resources", default=str(ROOT / ".local/horizon-client/26.3"))
p.add_argument("--build", default=str(ROOT / "target/release"))
p.add_argument("--out", help="JSON file (default benchmarks/graphics/<label>.json)")
p.add_argument("--compare", nargs=2, metavar=("BEFORE", "AFTER"),
help="print a markdown table comparing two saved runs, and exit")
args = p.parse_args()
if args.compare:
compare(*args.compare)
return
ctl = Path(args.build).resolve() / "horizon-ctl"
if not ctl.exists():
sys.exit(f"{ctl} missing: cargo build --release -p horizon-client --bins")
cwd = ROOT / ".local/graphics-bench"
shutil.rmtree(cwd / "saves" / WORLD, ignore_errors=True)
cwd.mkdir(parents=True, exist_ok=True)
env = vscreen_env()
subprocess.run(["vscreen", "up"], cwd=ROOT, check=True, capture_output=True)
commit = subprocess.run(["git", "rev-parse", "--short", "HEAD"], cwd=ROOT,
capture_output=True, text=True).stdout.strip()
report = {
"label": args.label,
"date": datetime.date.today().isoformat(),
"commit": commit,
"host": os.uname().nodename,
"offscreen": args.offscreen,
"seed": SEED,
"flight_seconds": args.seconds,
"scenes": {n: {"from": a, "to": b, "pitch": c} for n, a, b, c in SCENES},
"distances": {},
"load_before": os.getloadavg(),
}
for d in [int(x) for x in args.distances.split(",")]:
report["distances"][str(d)] = run_distance(args, ctl, env, cwd, d)
report["load_after"] = os.getloadavg()
out = Path(args.out) if args.out else ROOT / "benchmarks/graphics" / f"{args.label}.json"
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(json.dumps(report, indent=2) + "\n")
print(out)
if __name__ == "__main__":
main()