Skip to content

Commit

Permalink
Merge pull request #47832 from lawnjelly/ewok_store_batch_items
Browse files Browse the repository at this point in the history
Batching - store parent items in default batches
  • Loading branch information
akien-mga authored Apr 12, 2021
2 parents f72c91e + 40a267c commit c406f56
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
7 changes: 5 additions & 2 deletions drivers/gles2/rasterizer_canvas_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void RasterizerCanvasGLES2::_batch_render_generic(const Batch &p_batch, Rasteriz
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Item *p_current_clip, bool &r_reclip, RasterizerStorageGLES2::Material *p_material) {
void RasterizerCanvasGLES2::render_batches(Item *p_current_clip, bool &r_reclip, RasterizerStorageGLES2::Material *p_material) {

int num_batches = bdata.batches.size();

Expand All @@ -318,9 +318,12 @@ void RasterizerCanvasGLES2::render_batches(Item::Command *const *p_commands, Ite
default: {
int end_command = batch.first_command + batch.num_commands;

RAST_DEV_DEBUG_ASSERT(batch.item);
RasterizerCanvas::Item::Command *const *commands = batch.item->commands.ptr();

for (int i = batch.first_command; i < end_command; i++) {

Item::Command *command = p_commands[i];
Item::Command *command = commands[i];

switch (command->type) {

Expand Down
2 changes: 1 addition & 1 deletion drivers/gles2/rasterizer_canvas_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RasterizerCanvasGLES2 : public RasterizerCanvasBaseGLES2, public Rasterize
void canvas_render_items_implementation(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform);
void render_joined_item(const BItemJoined &p_bij, RenderItemState &r_ris);
bool try_join_item(Item *p_ci, RenderItemState &r_ris, bool &r_batch_break);
void render_batches(Item::Command *const *p_commands, Item *p_current_clip, bool &r_reclip, RasterizerStorageGLES2::Material *p_material);
void render_batches(Item *p_current_clip, bool &r_reclip, RasterizerStorageGLES2::Material *p_material);

// low level batch funcs
void _batch_upload_buffers();
Expand Down
7 changes: 5 additions & 2 deletions drivers/gles3/rasterizer_canvas_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void RasterizerCanvasGLES3::_legacy_canvas_render_item(Item *p_ci, RenderItemSta
}
}

void RasterizerCanvasGLES3::render_batches(Item::Command *const *p_commands, Item *p_current_clip, bool &r_reclip, RasterizerStorageGLES3::Material *p_material) {
void RasterizerCanvasGLES3::render_batches(Item *p_current_clip, bool &r_reclip, RasterizerStorageGLES3::Material *p_material) {
// bdata.reset_flush();
// return;

Expand All @@ -527,9 +527,12 @@ void RasterizerCanvasGLES3::render_batches(Item::Command *const *p_commands, Ite
default: {
int end_command = batch.first_command + batch.num_commands;

RAST_DEV_DEBUG_ASSERT(batch.item);
RasterizerCanvas::Item::Command *const *commands = batch.item->commands.ptr();

for (int i = batch.first_command; i < end_command; i++) {

Item::Command *c = p_commands[i];
Item::Command *c = commands[i];

switch (c->type) {

Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/rasterizer_canvas_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RasterizerCanvasGLES3 : public RasterizerCanvasBaseGLES3, public Rasterize
void canvas_render_items_implementation(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform);
void render_joined_item(const BItemJoined &p_bij, RenderItemState &r_ris);
bool try_join_item(Item *p_ci, RenderItemState &r_ris, bool &r_batch_break);
void render_batches(Item::Command *const *p_commands, Item *p_current_clip, bool &r_reclip, RasterizerStorageGLES3::Material *p_material);
void render_batches(Item *p_current_clip, bool &r_reclip, RasterizerStorageGLES3::Material *p_material);

// low level batch funcs
void _batch_upload_buffers();
Expand Down
27 changes: 19 additions & 8 deletions drivers/gles_common/rasterizer_canvas_batcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,15 @@ class RasterizerCanvasBatcher {
// first vertex of this batch in the vertex lists
uint32_t first_vert;

BatchColor color;
// we can keep the batch structure small because we either need to store
// the color if a handled batch, or the parent item if a default batch, so
// we can reference the correct originating command
union {
BatchColor color;

// for default batches we will store the parent item
const RasterizerCanvas::Item *item;
};
};

struct BatchTex {
Expand Down Expand Up @@ -655,8 +663,11 @@ class RasterizerCanvasBatcher {
RAST_DEBUG_ASSERT(batch);
}

if (p_blank)
if (p_blank) {
memset(batch, 0, sizeof(Batch));
} else {
batch->item = nullptr;
}

return batch;
}
Expand Down Expand Up @@ -857,6 +868,7 @@ PREAMBLE(void)::_prefill_default_batch(FillState &r_fill_state, int p_command_nu
r_fill_state.curr_batch->type = RasterizerStorageCommon::BT_DEFAULT;
r_fill_state.curr_batch->first_command = extra_command;
r_fill_state.curr_batch->num_commands = 1;
r_fill_state.curr_batch->item = &p_item;

// revert to the original transform mode
// e.g. go back to NONE if we were in hardware transform mode
Expand All @@ -882,6 +894,7 @@ PREAMBLE(void)::_prefill_default_batch(FillState &r_fill_state, int p_command_nu
r_fill_state.curr_batch->type = RasterizerStorageCommon::BT_DEFAULT;
r_fill_state.curr_batch->first_command = p_command_num;
r_fill_state.curr_batch->num_commands = 1;
r_fill_state.curr_batch->item = &p_item;
}
}

Expand Down Expand Up @@ -2445,15 +2458,14 @@ PREAMBLE(void)::flush_render_batches(RasterizerCanvas::Item *p_first_item, Raste
// send buffers to opengl
get_this()->_batch_upload_buffers();

RasterizerCanvas::Item::Command *const *commands = p_first_item->commands.ptr();

#if defined(TOOLS_ENABLED) && defined(DEBUG_ENABLED)
if (bdata.diagnose_frame) {
RasterizerCanvas::Item::Command *const *commands = p_first_item->commands.ptr();
diagnose_batches(commands);
}
#endif

get_this()->render_batches(commands, p_current_clip, r_reclip, p_material);
get_this()->render_batches(p_current_clip, r_reclip, p_material);

// if we overrode the fvf for lines, set it back to the joined item fvf
bdata.fvf = backup_fvf;
Expand Down Expand Up @@ -2552,15 +2564,14 @@ PREAMBLE(void)::_legacy_canvas_item_render_commands(RasterizerCanvas::Item *p_it

int command_count = p_item->commands.size();

RasterizerCanvas::Item::Command *const *commands = p_item->commands.ptr();

// legacy .. just create one massive batch and render everything as before
bdata.batches.reset();
Batch *batch = _batch_request_new();
batch->type = RasterizerStorageCommon::BT_DEFAULT;
batch->num_commands = command_count;
batch->item = p_item;

get_this()->render_batches(commands, p_current_clip, r_reclip, p_material);
get_this()->render_batches(p_current_clip, r_reclip, p_material);
bdata.reset_flush();
}

Expand Down

0 comments on commit c406f56

Please sign in to comment.