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 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
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
13 changes: 13 additions & 0 deletions include/sm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,25 @@ enum RenderLayers {
LAYER_OCCLUDE_SILHOUETTE_OPAQUE,
LAYER_OCCLUDE_SILHOUETTE_ALPHA,
#endif
LAYER_CLD,
LAYER_TRANSPARENT_DECAL,
LAYER_TRANSPARENT,
LAYER_TRANSPARENT_INTER,
LAYER_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
30 changes: 30 additions & 0 deletions src/engine/batch_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "batch_list.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 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);
}
18 changes: 18 additions & 0 deletions src/engine/batch_list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#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) {
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
26 changes: 23 additions & 3 deletions src/engine/graph_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,35 @@ struct DisplayListNode {
struct DisplayListNode *next;
};

struct DisplayListLinks {
struct DisplayListNode* head;
struct DisplayListNode* tail;
};

struct BatchDisplayLists {
const void* startDl;
const void* endDl;
};

struct BatchArray {
int count;
const struct BatchDisplayLists* batchDLs;
struct DisplayListLinks batches[0];
};

struct MasterLayer {
struct DisplayListLinks 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