Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ python -m pytest -q tools/test_hdr_backends.py # display.hdr across
python -m pytest -q tools/test_macos_app.py # the macOS app's Info.plist, entitlements, signature
python -m pytest -q tools/test_hud_assets.py # the high-res HUD's assets: their sources, credit, the classic buttons' cut-out letters
python -m pytest -q tools/test_astc.py # the DXT textures as ASTC: the transcoding, the encoder's bounds, the disk cache
python -m pytest -q tools/test_texture_alpha.py # a texture's least alpha, which an alpha test is dropped by, against the decoder's alphas
python -m pytest -q tools/test_ios_app.py # the iOS app's Info.plist, entitlements, the guest's code section
build/macos/halo_replay <recording> --shots <dir> # a recorded render stream replayed (ninja macos_replay;
# HALO_RENDER_RECORD: port/macos/README.md)
Expand Down
29 changes: 16 additions & 13 deletions port/android/host/host_render_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1621,29 +1621,32 @@ void host_render_stream_frame_displayed(uint64_t input, uint64_t finished, uint6
if (latched)
{
/* (taken a refresh or more after the one it was started for: a
miss. The margin is widened for a frame that started at its time and
whose work was done by the margin before that refresh (or not
known): the display wants its frames sooner than the margin gives.
A frame whose work ran past it took longer than any of the last
ones, which its cost, now counted, gives the frames after it) */
miss. The margin is widened for a frame that started at its time:
one whose work was done by the margin before that refresh (or not
known), as the display wants its frames sooner than the margin gives;
and one whose work ran past it, which took longer than any of the
last ones. Its cost, now counted, gives the frames after it that
much, and no more: where the frames' costs keep rising past the last
ones' by a little (a firefight growing), each new longest frame would
miss its refresh without the wider margin, one in two hundred of a
Raspberry Pi 5's) */
if (render.targets[frame % 8].frame == frame && render.targets[frame % 8].target && period &&
latched < render.targets[frame % 8].target + 4 * period)
{
if (latched > render.targets[frame % 8].target + period / 2)
{
render.pacing_statistics.missed++;
if (render.targets[frame % 8].waited && (!finished || finished + render.targets[frame % 8].margin <=
if (!render.targets[frame % 8].waited || (finished && finished + render.targets[frame % 8].margin >
render.targets[frame % 8].target + FRAME_PACING_MARGIN_STEP_NS / 4))
{
/* (once for the margin it started with: the frames started
before a miss widened it, already on their way, miss too) */
if (!render.margin_fixed && render.targets[frame % 8].margin >=
(render.costs.margin ? render.costs.margin : FRAME_PACING_MARGIN_NS))
frame_pacing_margin_missed(&render.costs, period);
render.pacing_statistics.overran++;
}
else
/* (once for the margin it started with: the frames started
before a miss widened it, already on their way, miss too) */
if (render.targets[frame % 8].waited && !render.margin_fixed && render.targets[frame % 8].margin >=
(render.costs.margin ? render.costs.margin : FRAME_PACING_MARGIN_NS))
{
render.pacing_statistics.overran++;
frame_pacing_margin_missed(&render.costs, period);
}
}
else
Expand Down
7 changes: 7 additions & 0 deletions port/android/tests/frame_pacing_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ static void margin_check(void)
/* (and the budget is the costs' most and the margin) */
costs.nanoseconds[3] = 4000000ull;
margin_expect("the budget", frame_pacing_budget(&costs, period), 4000000ull + period / 2);
/* (a frame that took more than a refresh, the game's work and the
renderer's overlapping, is given its time: up to the refreshes a frame
can be started before its own; one that took longer than those is not) */
costs.nanoseconds[4] = period * 7 / 4;
margin_expect("a frame of more than a refresh", frame_pacing_budget(&costs, period), period * 7 / 4 + period / 2);
costs.nanoseconds[5] = period * (FRAME_PACING_QUEUED + 1) + 1;
margin_expect("a frame too long to pace", frame_pacing_budget(&costs, period), period * 7 / 4 + period / 2);
}

int main(void)
Expand Down
12 changes: 9 additions & 3 deletions port/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2235,9 +2235,12 @@ Windows and Android) paces the game by the display instead (`vulkan/xgpu_vulkan_
waiting, one drawn into.
- And not before the time it takes ahead of the refresh it is for: the
most a frame took of the last 128, from its input read to its work done
on the GPU, and a margin. A frame that started at its time and was done
that margin early, but still missed its refresh, widens the margin by
1 ms (a display that takes its frames sooner than the margin gives); 120
on the GPU, and a margin. A frame may take up to two refreshes so (the
game writes it while the renderer draws the one before, and it starts
that much before its own refresh); one that took longer is not counted.
A frame that started at its time but still missed its refresh widens the
margin by 1 ms (a display that takes its frames sooner than the margin
gives, or a frame that took a little longer than any of the last); 120
frames in time narrow it by 0.1 ms, down to 0.25 ms over the margin
that last missed, which itself comes down 0.1 ms a minute. The margin
starts at 1.5 ms.
Expand Down Expand Up @@ -7679,6 +7682,9 @@ Other changes:
| `sound/sound_manager.c`, `interface/hud.c`, `game/game_engine.c` | The music's and the other sounds' volumes; the HUD's and the scoreboard's settings are read again when Settings changes them. |
| `rasterizer/xbox/rasterizer_xbox_shadows.c` | With larger shadow maps (`display.shadow_resolution`), the blur's taps stay half a texel apart, and more passes widen it to cover the same part of the map as on the Xbox. |
| `rasterizer/xbox/rasterizer_xbox_shadows.c`, `render/render_objects.c`, `rasterizer/rasterizer.h` | The shadow atlas: a frame's shadow casters (up to 9, with maps up to 512) are drawn into regions of an atlas first, the blur's passes run once over all of them (one quad a region, the guard bands between them black, as a map's border reads), the last into a map of each region's own, and then each object's receivers are drawn sampling its map. A frame's N shadows take 6 + N passes at 512 rather than 7N; they look the same. More casters, 1024 maps and the debugging options draw them one at a time as before. |
| `rasterizer/xbox/rasterizer_xbox_shadows.c` | Where a pass costs by the area it covers (a tile-based GPU: `HALO_VULKAN_CLEAR_ALONE`), each region's cell of the shadow atlas is emptied as its turn comes, and the rest of the atlas left as it was, which nothing samples. The pixels drawn are the same. |
| `rasterizer/xbox/rasterizer_xbox_environment.c`, `rasterizer/xbox/rasterizer_xbox_shadows.c` | A dynamic light's and a shadow's draws over the level say what part of the view they can change (`port/linux/game/draw_bounds.c`: the light's radius, the shadow's volume, and how far past them the textures' borders are still sampled), and the front end scissors them to it where the pixels shaded are the cost (`HALO_VULKAN_DRAW_BOUNDS`). The same pixels are lit and shadowed. |
| `rasterizer/xbox/rasterizer_xbox_models.c`, `rasterizer/xbox/rasterizer_xbox_active_camouflage.c` | A model's bounding sphere is given to the front end while the model is drawn (`halo_model_bounds`): with the enhanced dynamic lights a model none of them reaches is given no point lights and drawn by the shader without the lights' loop, and with `HALO_VULKAN_CUTOUT_PREPASS=1` a large alpha-tested model's depth is drawn first (`HALO_VULKAN_DRAW_BOUNDS`). A camouflaged model has no sphere: its radius is 0, not what the stack held. |
| `rasterizer/rasterizer.c` | The 128 KB of vertices of the debug display of a model's vertices are static, not on the stack: the compiler inlines the function in `render_model`, and the Windows build probed the stack a page at a time for every model drawn. |
| `render/render.c` | The 3D view of each window is tone mapped (`display.hdr`) and antialiased (`display.anti_aliasing`) before the HUD is drawn. The projectiles' lights' glows are drawn after the transparent geometry (`display.dynamic_lights`). |
| `render/render.c` | `render_initialize` reads the structure culling tests from `display.structure_culling`. |
Expand Down
155 changes: 155 additions & 0 deletions port/linux/game/draw_bounds.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
DRAW_BOUNDS.C

The part of a view that a pass over the level can change.

A dynamic light and an object's shadow are drawn onto the level as the
level's own surfaces, whole: every surface the light's sphere or the
shadow's volume touches (structure_render.c). A surface of the level is
often many times the size of the light or the shadow on it, and what the
pass draws beyond them changes nothing: the light's distance attenuation
and the shadow's map are sampled by their border there, which adds no light
and takes none away. Those pixels are still shaded and blended, and in a
fight, where every plasma bolt is a light and every body casts a shadow,
they were a quarter of a Raspberry Pi 5's frame.

So the pass says what it is bounded by (the light's reach as a cube, the
shadow's volume as a box) and its draws are scissored to the box's place in
the view (halo_draw_bounds, port/linux/src/d3d8_device.c): the pixels drawn
are the same ones, only fewer are shaded. A box that reaches behind the
eye bounds nothing, and its pass is drawn whole as before.
*/

#include "cseries.h"
#include "math/real_math.h"
#include "draw_bounds.h"
#include "rasterizer/rasterizer.h"
#include "render/render_cameras.h"

/* ---------- constants */

enum
{
NUMBER_OF_BOX_CORNERS = 8
};

enum
{
/* (the rasterizer's files' own, each: rasterizer_xbox.c) */
_rasterizer_target_render_primary = 0
};

/* how near the eye's plane a corner of a box may be for its place in the
view to bound anything (the projection's w, world units) */
#define DRAW_BOUNDS_NEAREST_CORNER 0.001f

/* ---------- public code */

void draw_bounds_box(
real_point3d const *centre,
real_vector3d const *forward,
real_vector3d const *left,
real_vector3d const *up,
real const low[3],
real const high[3])
{
real const width = (real)(global_window_parameters.camera.viewport_bounds.x1 -
global_window_parameters.camera.viewport_bounds.x0);
real const height = (real)(global_window_parameters.camera.viewport_bounds.y1 -
global_window_parameters.camera.viewport_bounds.y0);
float rectangle[4];
short corner;

/* (the window's view of the world alone, not a mirror's: the others
are drawn through projections of their own) */
if (global_window_parameters.rasterizer_target != _rasterizer_target_render_primary ||
global_window_parameters.camera.mirrored)
{
halo_draw_bounds(NULL);
return;
}

rectangle[0] = width;
rectangle[1] = height;
rectangle[2] = 0.0f;
rectangle[3] = 0.0f;
for (corner = 0; corner < NUMBER_OF_BOX_CORNERS; corner++)
{
real const along_forward = (corner & 1) ? high[0] : low[0];
real const along_left = (corner & 2) ? high[1] : low[1];
real const along_up = (corner & 4) ? high[2] : low[2];
real_point3d point;
real_point3d view_point;
real w;
real x;
real y;

point.x = centre->x + forward->i*along_forward + left->i*along_left + up->i*along_up;
point.y = centre->y + forward->j*along_forward + left->j*along_left + up->j*along_up;
point.z = centre->z + forward->k*along_forward + left->k*along_left + up->k*along_up;
matrix4x3_transform_point(
&global_window_parameters.frustum.world_to_view,
&point,
&view_point);
w =
global_window_parameters.frustum.projection_matrix[0][3] * view_point.x +
global_window_parameters.frustum.projection_matrix[1][3] * view_point.y +
global_window_parameters.frustum.projection_matrix[2][3] * view_point.z +
global_window_parameters.frustum.projection_matrix[3][3];
if (!(w > DRAW_BOUNDS_NEAREST_CORNER))
{
halo_draw_bounds(NULL);
return;
}

/* (the viewport's pixels from its left and top, by their edges; as
rasterizer_project_billboard has a point's, by their middles) */
x = ((
global_window_parameters.frustum.projection_matrix[0][0] * view_point.x +
global_window_parameters.frustum.projection_matrix[1][0] * view_point.y +
global_window_parameters.frustum.projection_matrix[2][0] * view_point.z +
global_window_parameters.frustum.projection_matrix[3][0]) / w + 1.0f) * width * 0.5f;
y = (1.0f - (
global_window_parameters.frustum.projection_matrix[0][1] * view_point.x +
global_window_parameters.frustum.projection_matrix[1][1] * view_point.y +
global_window_parameters.frustum.projection_matrix[2][1] * view_point.z +
global_window_parameters.frustum.projection_matrix[3][1]) / w) * height * 0.5f;
rectangle[0] = MIN(rectangle[0], x);
rectangle[1] = MIN(rectangle[1], y);
rectangle[2] = MAX(rectangle[2], x);
rectangle[3] = MAX(rectangle[3], y);
}

/* (the part of it in the viewport and a pixel around it, which the
front end's own placing of the pixels may still bring in: none, if the
right is not past the left or the bottom past the top) */
rectangle[0] = MAX(rectangle[0], -1.0f);
rectangle[1] = MAX(rectangle[1], -1.0f);
rectangle[2] = MIN(rectangle[2], width + 1.0f);
rectangle[3] = MIN(rectangle[3], height + 1.0f);
halo_draw_bounds(rectangle);

return;
}

void draw_bounds_cube(
real_point3d const *centre,
real half_width)
{
real low[3];
real high[3];

low[0] = low[1] = low[2] = -half_width;
high[0] = high[1] = high[2] = half_width;
draw_bounds_box(centre, global_forward3d, global_left3d, global_up3d, low, high);

return;
}

void draw_bounds_none(
void)
{
halo_draw_bounds(NULL);

return;
}
32 changes: 32 additions & 0 deletions port/linux/game/draw_bounds.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
DRAW_BOUNDS.H

The part of a view that a pass over the level can change (draw_bounds.c).
*/

#ifndef DRAW_BOUNDS_H
#define DRAW_BOUNDS_H

#include "math/real_math.h"

/* the draws from now on change no pixel of the view outside a box (world
units): its middle, its three axes (unit vectors), and how far it reaches
along each of them, from low to high */
void draw_bounds_box(
real_point3d const *centre,
real_vector3d const *forward,
real_vector3d const *left,
real_vector3d const *up,
real const low[3],
real const high[3]);

/* ... outside a cube about a point, the world's axes its own */
void draw_bounds_cube(
real_point3d const *centre,
real half_width);

/* the draws from now on are not bounded */
void draw_bounds_none(
void);

#endif
17 changes: 17 additions & 0 deletions port/linux/game/render_interpolation.c
Original file line number Diff line number Diff line change
Expand Up @@ -2584,6 +2584,23 @@ void render_interpolation_object_point(long object_index, real_point3d *point)
matrix4x3_transform_point(&drawn[0], &local, point);
}

/* the middle of a model's bounding sphere where the frame draws the model:
moved with the object (render_interpolation_object_point) if the model is
an object's own, drawn about its sphere (render_objects.c gives render_model
the object's index and its sphere's centre); as given for any other, whose
identifier need be no object's (a flag's cloth, a first-person weapon) */
void render_interpolation_model_centre(long unique_identifier, real_point3d const *centre, real_point3d *drawn)
{
struct object_datum *object;

*drawn = *centre;
if (unique_identifier == NONE || !DATUM_INDEX_TO_IDENTIFIER(unique_identifier))
return;
object = object_try_and_get(unique_identifier);
if (object && !csmemcmp(&object->object.bounding_sphere_center, centre, sizeof(*centre)))
render_interpolation_object_point(unique_identifier, drawn);
}

/* A point the game works out from an object's state reads some of it as the
tick left it (its position, its bounding sphere) and some as a frame draws
it (its nodes and markers, object_get_node_matrices): a unit's camera on foot
Expand Down
6 changes: 5 additions & 1 deletion port/linux/game/render_prepared.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ front end turns into pipelines and targets as the settings and the screen
are now (prepared_settings says of each setting why), and the walk draws,
as it records, what every setting's would (the enhanced lights' passes,
the ambient occlusion's pre-pass and Panini's pass, whatever the settings:
the front end plays back what the settings now want of them). Played back
the front end plays back what the settings now want of them). (One choice
of the backend's is in what the walk draws: a cut-out's depth first, beside
the cut-out as one draw, where xgpu_backend_capabilities.cutout_prepass
(HALO_VULKAN_CUTOUT_PREPASS=1). A record made without it leaves those two
draws' pipelines to be made in play.) Played back
under the settings, backend and GPU it was made with (its derivation), the
map's enumeration (the set of distinct draws as the front end describes
them: xgpu_manifest_enumeration) must be the record's; under others, which
Expand Down
24 changes: 24 additions & 0 deletions port/linux/include/halo_linux_source_fixups.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ void render_interpolation_frame_end(void);
float render_interpolation_fraction(void);
struct real_matrix4x3 *render_interpolation_object_node_matrices(long object_index);
void render_interpolation_object_point(long object_index, union real_point3d *point);
/* a model's bounding sphere's centre where the frame draws the model, if it
is an object's own (render_interpolation.c) */
void render_interpolation_model_centre(long unique_identifier, union real_point3d const *centre,
union real_point3d *drawn);
/* an object's origin and a unit's camera where a frame draws them, not
mixed of the tick's state and the frame's (render_interpolation.c) */
void render_interpolation_object_origin(long object_index, union real_point3d *origin);
Expand Down Expand Up @@ -279,12 +283,24 @@ it kept, and the range it had in previous (NULL: not wanted): a range in
the last step before 1 draws behind everything drawn, still clipped at the
far plane (port/linux/src/d3d8_device.c) */
void d3d8_viewport_depth_range(float minimum, float maximum, float previous[2]);
/* the rectangle of the viewport that the draws from now on can change
pixels in (left, top, right, bottom, in the viewport's pixels from its left
and top; none of it, if the right is not past the left or the bottom past
the top), to which they are scissored where the backend gains by it; NULL:
the whole viewport, as before (port/linux/src/d3d8_device.c, "the draws'
bounds"; from port/linux/game/draw_bounds.c) */
void halo_draw_bounds(const float *rectangle);
/* the stage samples a region of its texture as a texture of the region's
alone, addressed by its border beyond it (D3DTADDRESS_BORDER, whatever the
stage's address modes): region its width and height, then its left and top,
in the texture's coordinates (0 to 1); NULL: the whole texture, as the
stage's address modes have it (port/linux/src/d3d8_device.c) */
void d3d8_texture_region(unsigned long stage, const float *region);
/* the viewport's rectangle of the colour target cleared, the rest of the
target of no use from now on; and whether the renderer gains by it: a pass
then costs by the part of the target it covers (port/linux/src/d3d8_device.c) */
int d3d8_clears_alone(void);
void d3d8_clear_viewport_alone(unsigned long color);
/* takes up a new width between frames (F11); returns the width */
long halo_screen_commit(void);
/* the shadow maps' pixels for each of their 128 texels each way, a power of
Expand Down Expand Up @@ -321,6 +337,14 @@ preparation's record) */
void halo_screen_panini(short x0, short y0, short x1, short y1, const float projection[8]);
/* the enhanced dynamic lights (display.dynamic_lights) */
#include "halo_dynamic_lights.h"

/* the model the game's draws are of from now on (port/linux/src/d3d8_device.c):
its bounding sphere (the tick's), its middle as the frame draws it, the
middle's distance from the camera, whether it is a first-person model; a
NULL centre or no radius: not known (no model, or one without a sphere).
Nonzero if no enhanced dynamic light reaches it: it is drawn as with no
light, and the game gives it no point lights */
int halo_model_bounds(const float centre[3], const float drawn[3], float radius, float distance, int first_person);
/* display.hdr's tone map of a window's 3D view, before its anti-aliasing
(source/render/render.c), and what the game's renderer tells it of its
draws (port/linux/src/d3d8_device.c, xgpu_hdr.h): the category drawing now
Expand Down
Loading