Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coin batching #848

Draft
wants to merge 6 commits into
base: develop/2.4.0
Choose a base branch
from
Draft
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
224 changes: 112 additions & 112 deletions actors/coin/geo.inc.c

Large diffs are not rendered by default.

366 changes: 61 additions & 305 deletions actors/coin/model.inc.c

Large diffs are not rendered by default.

66 changes: 19 additions & 47 deletions actors/common1.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,59 +35,31 @@ extern const GeoLayout red_coin_no_shadow_geo[];
extern const GeoLayout silver_coin_geo[];
extern const GeoLayout silver_coin_no_shadow_geo[];

extern const Gfx coin_seg3_dl_yellow_0[];
extern const Gfx coin_seg3_dl_yellow_22_5[];
extern const Gfx coin_seg3_dl_yellow_45[];
extern const Gfx coin_seg3_dl_yellow_67_5[];
extern const Gfx coin_seg3_dl_yellow_90[];
extern const Gfx coin_seg3_dl_yellow_67_5_r[];
extern const Gfx coin_seg3_dl_yellow_45_r[];
extern const Gfx coin_seg3_dl_yellow_22_5_r[];
extern const Gfx coin_seg3_dl_0[];
extern const Gfx coin_seg3_dl_22_5[];
extern const Gfx coin_seg3_dl_45[];
extern const Gfx coin_seg3_dl_67_5[];
extern const Gfx coin_seg3_dl_90[];

extern const Gfx coin_seg3_dl_blue_0[];
extern const Gfx coin_seg3_dl_blue_22_5[];
extern const Gfx coin_seg3_dl_blue_45[];
extern const Gfx coin_seg3_dl_blue_67_5[];
extern const Gfx coin_seg3_dl_blue_90[];
extern const Gfx coin_seg3_dl_blue_67_5_r[];
extern const Gfx coin_seg3_dl_blue_45_r[];
extern const Gfx coin_seg3_dl_blue_22_5_r[];
extern const Gfx coin_seg3_dl_secret_draw[];

extern const Gfx coin_seg3_dl_red_0[];
extern const Gfx coin_seg3_dl_red_22_5[];
extern const Gfx coin_seg3_dl_red_45[];
extern const Gfx coin_seg3_dl_red_67_5[];
extern const Gfx coin_seg3_dl_red_90[];
extern const Gfx coin_seg3_dl_red_67_5_r[];
extern const Gfx coin_seg3_dl_red_45_r[];
extern const Gfx coin_seg3_dl_red_22_5_r[];

extern const Gfx coin_seg3_dl_secret_0[];
extern const Gfx coin_seg3_dl_secret_22_5[];
extern const Gfx coin_seg3_dl_secret_45[];
extern const Gfx coin_seg3_dl_secret_67_5[];
extern const Gfx coin_seg3_dl_secret_90[];
extern const Gfx coin_seg3_dl_secret_67_5_r[];
extern const Gfx coin_seg3_dl_secret_45_r[];
extern const Gfx coin_seg3_dl_secret_22_5_r[];
extern const Gfx coin_seg3_dl_yellow_draw_r[];
extern const Gfx coin_seg3_dl_blue_draw_r[];
extern const Gfx coin_seg3_dl_red_draw_r[];
extern const Gfx coin_seg3_dl_secret_draw_r[];

#else
extern const Gfx coin_seg3_sub_dl_begin[];
extern const Gfx coin_seg3_sub_dl_end[];
extern const Gfx coin_seg3_dl_yellow_front[];
extern const Gfx coin_seg3_dl_yellow_tilt_right[];
extern const Gfx coin_seg3_dl_yellow_side[];
extern const Gfx coin_seg3_dl_yellow_tilt_left[];
extern const Gfx coin_seg3_dl_blue_front[];
extern const Gfx coin_seg3_dl_blue_tilt_right[];
extern const Gfx coin_seg3_dl_blue_side[];
extern const Gfx coin_seg3_dl_blue_tilt_left[];
extern const Gfx coin_seg3_dl_red_front[];
extern const Gfx coin_seg3_dl_red_tilt_right[];
extern const Gfx coin_seg3_dl_red_side[];
extern const Gfx coin_seg3_dl_red_tilt_left[];
extern const Gfx coin_seg3_dl_front[];
extern const Gfx coin_seg3_dl_tilt_right[];
extern const Gfx coin_seg3_dl_side[];
extern const Gfx coin_seg3_dl_tilt_left[];
#endif

extern const Gfx coin_seg3_dl_yellow_draw[];
extern const Gfx coin_seg3_dl_blue_draw[];
extern const Gfx coin_seg3_dl_red_draw[];
extern const Gfx coin_seg3_dl_end[];

// dirt
extern const GeoLayout dirt_animation_geo[];
extern const GeoLayout cartoon_star_geo[];
Expand Down
18 changes: 12 additions & 6 deletions bin/segment2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2761,14 +2761,24 @@ const Gfx dl_draw_quad_verts_4567[] = {
gsSPEndDisplayList(),
};

#define G_CC_SHADOW TEXEL0, 0, SHADE, 0, TEXEL0, 0, PRIMITIVE, 0

const Gfx dl_shadow_begin[] = {
gsDPPipeSync(),
gsSPClearGeometryMode(G_LIGHTING | G_CULL_BACK),
gsDPSetCombineMode(G_CC_MODULATEIFADEA, G_CC_MODULATEIFADEA),
gsDPSetCombineMode(G_CC_SHADOW, G_CC_SHADOW),
gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON),
gsSPEndDisplayList(),
};

const Gfx dl_shadow_end[] = {
gsDPPipeSync(),
gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF),
gsSPSetGeometryMode(G_LIGHTING | G_CULL_BACK),
gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE),
gsSPEndDisplayList(),
};

#ifdef HD_SHADOWS
const Gfx dl_shadow_circle[] = {
gsSPDisplayList(dl_shadow_begin),
Expand Down Expand Up @@ -2810,13 +2820,9 @@ static const Vtx vertex_shadow[] = {
};

// 0x02014638 - 0x02014660
const Gfx dl_shadow_end[] = {
const Gfx dl_shadow_tris[] = {
gsSPVertex(vertex_shadow, 4, 0),
gsSP2Triangles( 0, 2, 1, 0x0, 1, 2, 3, 0x0),
gsDPPipeSync(),
gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF),
gsSPSetGeometryMode(G_LIGHTING | G_CULL_BACK),
gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE),
gsSPEndDisplayList(),
};

Expand Down
5 changes: 5 additions & 0 deletions include/geo_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum GeoLayoutCommands {
/*0x1E*/ GEO_CMD_NOP_1E,
/*0x1F*/ GEO_CMD_NOP_1F,
/*0x20*/ GEO_CMD_NODE_CULLING_RADIUS,
/*0x21*/ GEO_CMD_NODE_BATCH_DISPLAY_LIST,

GEO_CMD_COUNT,
};
Expand Down Expand Up @@ -360,6 +361,10 @@ enum GeoLayoutCommands {
CMD_BBH(GEO_CMD_NODE_DISPLAY_LIST, layer, 0x0000), \
CMD_PTR(displayList)

#define GEO_BATCH_DISPLAY_LIST(layer, batch, displayList) \
CMD_BBH(GEO_CMD_NODE_BATCH_DISPLAY_LIST, layer, batch), \
CMD_PTR(displayList)

/**
* 0x16: Create shadow scene graph node
* 0x01: unused
Expand Down
36 changes: 36 additions & 0 deletions include/sm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,48 @@ enum RenderLayers {
LAYER_OCCLUDE_SILHOUETTE_OPAQUE,
LAYER_OCCLUDE_SILHOUETTE_ALPHA,
#endif
LAYER_CLD,
LAYER_TRANSPARENT_DECAL,
LAYER_TRANSPARENT,
LAYER_TRANSPARENT_INTER,
LAYER_COUNT
};

#ifdef IA8_30FPS_COINS
#define BATCH_COIN_COUNT 5
#else
#define BATCH_COIN_COUNT 4
#endif

enum BatchAlpha {
#if SILHOUETTE
BATCH_ALPHA_COUNT,
};

enum BatchSilhouetteAlpha {
#endif
BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST,
BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_LAST = BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + BATCH_COIN_COUNT - 1,

#if SILHOUETTE
BATCH_OCCLUDE_SILHOUETTE_ALPHA_COUNT,
#else
BATCH_ALPHA_COUNT,
#endif
};

enum BatchTransparentDecal {
BATCH_TRANSPARENT_DECAL_SHADOW_CIRCLE,
BATCH_TRANSPARENT_DECAL_SHADOW_SQUARE,
BATCH_TRANSPARENT_DECAL_COUNT,
};

enum BatchCld {
BATCH_CLD_SHADOW_CIRCLE,
BATCH_CLD_SHADOW_SQUARE,
BATCH_CLD_COUNT,
};

#define LAYER_FIRST LAYER_FORCE
#define LAYER_LAST (LAYER_COUNT - 1)

Expand Down
66 changes: 66 additions & 0 deletions src/engine/batch_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "batch_list.h"

#include "actors/common1.h"
#include "game/segment2.h"

static const struct BatchDisplayLists BatchesTransparentDecal[] = {
[ BATCH_TRANSPARENT_DECAL_SHADOW_CIRCLE ] = { dl_shadow_circle, dl_shadow_end },
[ BATCH_TRANSPARENT_DECAL_SHADOW_SQUARE ] = { dl_shadow_square, dl_shadow_end },
};
STATIC_ASSERT(BATCH_TRANSPARENT_DECAL_COUNT == sizeof(BatchesTransparentDecal) / sizeof(*BatchesTransparentDecal), "Mismatch in transparent decal batch count");

static const struct BatchDisplayLists BatchesCLD[] = {
[ BATCH_CLD_SHADOW_CIRCLE ] = { dl_shadow_circle, dl_shadow_end },
[ BATCH_CLD_SHADOW_SQUARE ] = { dl_shadow_square, dl_shadow_end },
};
STATIC_ASSERT(BATCH_CLD_COUNT == sizeof(BatchesCLD) / sizeof(*BatchesCLD), "Mismatch in CLD batch count");

static const struct BatchDisplayLists BatchesAlpha[] = {
#if SILHOUETTE
};
static const struct BatchDisplayLists BatchesOccludeSilhouetteAlpha[] = {
#endif

#ifdef IA8_30FPS_COINS
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 0 ] = { coin_seg3_dl_0 , coin_seg3_dl_end },
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 1 ] = { coin_seg3_dl_22_5 , coin_seg3_dl_end },
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 2 ] = { coin_seg3_dl_45 , coin_seg3_dl_end },
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 3 ] = { coin_seg3_dl_67_5 , coin_seg3_dl_end },
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 4 ] = { coin_seg3_dl_90 , coin_seg3_dl_end },
#else
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 0 ] = { coin_seg3_dl_front , coin_seg3_dl_end },
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 1 ] = { coin_seg3_dl_tilt_right, coin_seg3_dl_end },
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 2 ] = { coin_seg3_dl_side , coin_seg3_dl_end },
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 3 ] = { coin_seg3_dl_tilt_left , coin_seg3_dl_end },
#endif
};

STATIC_ASSERT(BATCH_ALPHA_COUNT == sizeof(BatchesAlpha) / sizeof(*BatchesAlpha), "Mismatch in alpha batch count");
#if SILHOUETTE
STATIC_ASSERT(BATCH_OCCLUDE_SILHOUETTE_ALPHA_COUNT == sizeof(BatchesOccludeSilhouetteAlpha) / sizeof(*BatchesOccludeSilhouetteAlpha), "Mismatch in occlude silhouette alpha batch count");
#endif

static inline struct BatchArray* batch_array_alloc(struct AllocOnlyPool *pool, int count, const struct BatchDisplayLists* dls) {
struct BatchArray* batches = alloc_only_pool_alloc(pool, sizeof(struct BatchArray) + count * sizeof(struct DisplayListLinks));
batches->count = count;
batches->batchDLs = dls;
return batches;
}

struct BatchArray* batch_list_objects_alloc_xlu_decal(struct AllocOnlyPool *pool) {
return batch_array_alloc(pool, BATCH_TRANSPARENT_DECAL_COUNT, BatchesTransparentDecal);
}

struct BatchArray* batch_list_objects_alloc_cld(struct AllocOnlyPool *pool) {
return batch_array_alloc(pool, BATCH_CLD_COUNT, BatchesCLD);
}

struct BatchArray* batch_list_objects_alloc_alpha(struct AllocOnlyPool *pool) {
return batch_array_alloc(pool, BATCH_ALPHA_COUNT, BatchesAlpha);
}

#if SILHOUETTE
struct BatchArray* batch_list_objects_alloc_occlude_silhouette_alpha(struct AllocOnlyPool *pool) {
return batch_array_alloc(pool, BATCH_OCCLUDE_SILHOUETTE_ALPHA_COUNT, BatchesOccludeSilhouetteAlpha);
}
#endif
26 changes: 26 additions & 0 deletions src/engine/batch_list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "sm64.h"
#include "engine/graph_node.h"

struct BatchArray* batch_list_objects_alloc_xlu_decal(struct AllocOnlyPool *pool);
struct BatchArray* batch_list_objects_alloc_cld(struct AllocOnlyPool *pool);
struct BatchArray* batch_list_objects_alloc_alpha(struct AllocOnlyPool *pool);
struct BatchArray* batch_list_objects_alloc_occlude_silhouette_alpha(struct AllocOnlyPool *pool);

static inline struct BatchArray* batch_list_objects_alloc(struct AllocOnlyPool *pool, enum RenderLayers layer) {
switch (layer) {
case LAYER_TRANSPARENT_DECAL:
return batch_list_objects_alloc_xlu_decal(pool);
case LAYER_CLD:
return batch_list_objects_alloc_cld(pool);
case LAYER_ALPHA:
return batch_list_objects_alloc_alpha(pool);
#if SILHOUETTE
case LAYER_OCCLUDE_SILHOUETTE_ALPHA:
return batch_list_objects_alloc_occlude_silhouette_alpha(pool);
#endif
default:
return 0;
}
}
10 changes: 10 additions & 0 deletions src/engine/geo_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ GeoLayoutCommandProc GeoLayoutJumpTable[] = {
/*GEO_CMD_NOP_1E */ geo_layout_cmd_nop2,
/*GEO_CMD_NOP_1F */ geo_layout_cmd_nop3,
/*GEO_CMD_NODE_CULLING_RADIUS */ geo_layout_cmd_node_culling_radius,
/*GEO_CMD_NODE_BATCH_DISPLAY_LIST */ geo_layout_cmd_node_batch_display_list,
};

struct GraphNode gObjParentGraphNode;
Expand Down Expand Up @@ -751,6 +752,15 @@ void geo_layout_cmd_node_culling_radius(void) {
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}

void geo_layout_cmd_node_batch_display_list(void) {
s32 drawingLayer = cur_geo_cmd_u8(0x01);
s32 batch = cur_geo_cmd_s16(0x02);
void *displayList = cur_geo_cmd_ptr(0x04);
struct GraphNodeBatchDisplayList *graphNode = init_graph_node_batch_display_list(gGraphNodePool, NULL, displayList, drawingLayer, batch);
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
}

struct GraphNode *process_geo_layout(struct AllocOnlyPool *pool, void *segptr) {
// set by register_scene_graph_node when gCurGraphNodeIndex is 0
// and gCurRootGraphNode is NULL
Expand Down
1 change: 1 addition & 0 deletions src/engine/geo_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void geo_layout_cmd_nop(void);
void geo_layout_cmd_copy_view(void);
void geo_layout_cmd_node_held_obj(void);
void geo_layout_cmd_node_culling_radius(void);
void geo_layout_cmd_node_batch_display_list(void);

struct GraphNode *process_geo_layout(struct AllocOnlyPool *pool, void *segptr);

Expand Down
23 changes: 23 additions & 0 deletions src/engine/graph_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "game/rendering_graph_node.h"
#include "game/area.h"
#include "geo_layout.h"
#include "batch_list.h"

/**
* Initialize a geo node with a given type. Sets all links such that there
Expand Down Expand Up @@ -122,6 +123,13 @@ struct GraphNodeMasterList *init_graph_node_master_list(struct AllocOnlyPool *po

if (on) {
graphNode->node.flags |= GRAPH_RENDER_Z_BUFFER;
for (int layer = 0; layer < LAYER_COUNT; layer++) {
graphNode->layers[layer].objects = batch_list_objects_alloc(pool, layer);
}
} else {
for (int layer = 0; layer < LAYER_COUNT; layer++) {
graphNode->layers[layer].objects = NULL;
}
}
}

Expand Down Expand Up @@ -522,6 +530,21 @@ struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *po
return graphNode;
}

struct GraphNodeBatchDisplayList* init_graph_node_batch_display_list(struct AllocOnlyPool *pool, struct GraphNodeBatchDisplayList *graphNode, void *displayList, s32 drawingLayer, s32 batch) {
if (pool != NULL) {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeBatchDisplayList));
}

if (graphNode != NULL) {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_BATCH_DISPLAY_LIST);
SET_GRAPH_NODE_LAYER(graphNode->node.flags, drawingLayer);
graphNode->displayList = displayList;
graphNode->batch = batch;
}

return graphNode;
}

/**
* Adds 'childNode' to the end of the list children from 'parent'
*/
Expand Down
Loading