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

Introduce batching engine and shadow batching #847

Open
wants to merge 5 commits into
base: develop/3.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
14 changes: 9 additions & 5 deletions bin/segment2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,14 @@ const Gfx dl_shadow_begin[] = {
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 +2818,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
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
};

enum BatchOpaque {
BATCH_OPAQUE_CORKBOX,
BATCH_OPAQUE_COUNT,
};

enum BatchAlpha {
// coin frames batches, it goes 0, 1, 2, 3, 4, 3, 2, 1
BATCH_ALPHA_COINS_FIRST,
BATCH_ALPHA_COINS_LAST = BATCH_ALPHA_COINS_FIRST + 4,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk how I feel about this, what does the 4 actually represent here, number of coin textures? If so, that should be defined somewhere, ideally automatically computed or enforced with a static assert if possible.

Ditto for the flames.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the easiest solution is to add a static assert. sm64.h is a glue between subsystems geo->layer->batches->dls. It would be hard to deduce amount of coin textures without including actors in sm64.h which is not something I want to do.

For now I will remove those enums because they are unused anyways and reland them later with batching for specific objects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have provided the static asserts for constant batches, it actually appeared to be pretty easy to implement.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these be moved to batch_list.h? Idk if they make the most sense in sm64.h anyway, though to be fair the layer definitions are also here...

BATCH_ALPHA_SMOKE,
BATCH_ALPHA_COUNT,
};

enum BatchTransparent {
BATCH_TRANSPARENT_SMOKE,
BATCH_TRANSPARENT_MIST,
BATCH_TRANSPARENT_RED_FLAMES_FIRST,
BATCH_TRANSPARENT_RED_FLAMES_LAST = BATCH_TRANSPARENT_RED_FLAMES_FIRST + 7,
BATCH_TRANSPARENT_BLUE_FLAMES_FIRST,
BATCH_TRANSPARENT_BLUE_FLAMES_LAST = BATCH_TRANSPARENT_BLUE_FLAMES_FIRST + 7,
BATCH_TRANSPARENT_COUNT,
};

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
33 changes: 33 additions & 0 deletions src/engine/batch_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "batch_list.h"

#include "game/segment2.h"

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

static inline void batch_setup(struct BatchArray* arr, int idx, const void* start, const void* end)
{
struct Batch* batch = &arr->batches[idx];
batch->startDl = start;
batch->endDl = end;
}

struct BatchArray* batch_list_objects_alloc_xlu_decal(struct AllocOnlyPool *pool)
{
struct BatchArray* arr = batch_array_alloc(pool, BATCH_TRANSPARENT_DECAL_COUNT);
batch_setup(arr, BATCH_TRANSPARENT_DECAL_SHADOW_CIRCLE, dl_shadow_circle, dl_shadow_end);
batch_setup(arr, BATCH_TRANSPARENT_DECAL_SHADOW_SQUARE, dl_shadow_square, dl_shadow_end);
return arr;
}

struct BatchArray* batch_list_objects_alloc_cld(struct AllocOnlyPool *pool)
{
struct BatchArray* arr = batch_array_alloc(pool, BATCH_CLD_COUNT);
batch_setup(arr, BATCH_CLD_SHADOW_CIRCLE, dl_shadow_circle, dl_shadow_end);
batch_setup(arr, BATCH_CLD_SHADOW_SQUARE, dl_shadow_square, dl_shadow_end);
return arr;
}
20 changes: 20 additions & 0 deletions src/engine/batch_list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#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);

static inline struct BatchArray* batch_list_objects_alloc(struct AllocOnlyPool *pool, enum RenderLayers layer)
gheskett marked this conversation as resolved.
Show resolved Hide resolved
{
switch (layer)
{
case LAYER_TRANSPARENT_DECAL:
return batch_list_objects_alloc_xlu_decal(pool);
case LAYER_CLD:
return batch_list_objects_alloc_cld(pool);
default:
return 0;
}
}
8 changes: 8 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
29 changes: 26 additions & 3 deletions src/engine/graph_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,38 @@ struct DisplayListNode {
struct DisplayListNode *next;
};

struct DisplayListHead {
gheskett marked this conversation as resolved.
Show resolved Hide resolved
struct DisplayListNode* head;
struct DisplayListNode* tail;
};

struct Batch {
// filled in when master node is created
const void* startDl;
const void* endDl;

// filled in rendering of the master list
struct DisplayListHead list;
};

struct BatchArray {
int count;
struct Batch batches[0];
};

struct MasterLayer {
struct DisplayListHead list;
struct BatchArray* objects;
};

/** GraphNode that manages the 8 top-level display lists that will be drawn
* Each list has its own render mode, so for example water is drawn in a
* different master list than opaque objects.
* It also sets the z-buffer on before rendering and off after.
*/
struct GraphNodeMasterList {
/*0x00*/ struct GraphNode node;
/*0x14*/ struct DisplayListNode *listHeads[LAYER_COUNT];
/*0x34*/ struct DisplayListNode *listTails[LAYER_COUNT];
struct GraphNode node;
struct MasterLayer layers[LAYER_COUNT];
};

/** Simply used as a parent to group multiple children.
Expand Down
Loading