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

Optimization for distorted rects + "similar" objects #549

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f576c59
Fumbling toward a transformation on CoronaTotalTime, so far the comma…
ggcrunchy Feb 7, 2019
6626191
Moved some of the time transform stuff into ShaderResource with link …
ggcrunchy Feb 8, 2019
e59f04a
Better argument checking for time transforms
ggcrunchy Feb 9, 2019
e05f972
Whoops, wasn't always linking Program back to ShaderResource
ggcrunchy Feb 10, 2019
c7af750
Removed notes to self about changes
ggcrunchy Feb 11, 2019
9058c1f
timeTransform ignored if no time dependency
ggcrunchy Feb 11, 2019
c01d916
Minor changes
ggcrunchy May 29, 2020
08dc3b6
Maintenance Revert Test
scottrules44 Sep 20, 2021
05b91fb
Simulator: Adding Samsung Galaxy 21 as a skin
scottrules44 Sep 22, 2021
f44be24
Maintenance
scottrules44 Sep 22, 2021
581d844
Android: adding rest of media intents for Android 11
scottrules44 Sep 22, 2021
265be3c
Merge
ggcrunchy Sep 23, 2021
e217c80
Merge
ggcrunchy Oct 4, 2021
ca300c1
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Oct 19, 2021
0b5e1e9
First go at graphics.undefineEffect()
ggcrunchy Nov 9, 2021
b41e624
Revert "First go at graphics.undefineEffect()"
ggcrunchy Nov 10, 2021
5be6193
Merging upstream
ggcrunchy Aug 18, 2022
f38ecec
Merge branch 'master' of https://github.com/ggcrunchy/corona
ggcrunchy Aug 18, 2022
bb395b8
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Dec 16, 2022
dfe75aa
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Jan 25, 2023
e8b2d71
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Apr 14, 2023
5c006cd
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Apr 14, 2023
adfe169
Optimization for batching patterns with deformed rects
ggcrunchy Apr 17, 2023
f7e9fe5
Program difference not strengthened in general if batch breaks, but i…
ggcrunchy Apr 19, 2023
fa090f4
Merge branch 'master' into DeformedRectOptimization
ggcrunchy Dec 16, 2023
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
2 changes: 1 addition & 1 deletion librtt/Renderer/Rtt_Program.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Program : public CPUResource
const char *GetHeaderSource() const { return fHeaderSource; }
void SetHeaderSource( const char *source );

ShaderResource *GetShaderResource() { return fResource; }
ShaderResource *GetShaderResource() const { return fResource; }
void SetShaderResource( ShaderResource *resource ) { fResource = resource; }
#if defined( Rtt_USE_PRECOMPILED_SHADERS )
ShaderBinaryVersions* GetCompiledShaders() const { return fCompiledShaders; }
Expand Down
24 changes: 22 additions & 2 deletions librtt/Renderer/Rtt_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "Core/Rtt_Types.h"
#include "Renderer/Rtt_MCPUResourceObserver.h"

#include "Display/Rtt_ShaderResource.h"

#define ENABLE_DEBUG_PRINT 0

#include <limits>
Expand Down Expand Up @@ -450,6 +452,14 @@ Renderer::PopMaskCount()
--fMaskCountIndex;
}

static bool
OnlyTryingToDowngradeMod( const Program* newProgram, const Program* oldProgram )
{
const ShaderResource* resource = newProgram->GetShaderResource();

return NULL != oldProgram && resource == oldProgram->GetShaderResource() && resource->GetProgramMod( ShaderResource::k25D ) == oldProgram;
}

void
Renderer::Insert( const RenderData* data )
{
Expand All @@ -463,13 +473,21 @@ Renderer::Insert( const RenderData* data )
Rtt_ASSERT( fBackCommandBuffer != NULL );
Rtt_ASSERT( fFrontCommandBuffer != NULL );

// If using deformed rects, avoid some batch-breaking when only other objects with the same effect are drawn, by not
// falling back to non-deformed variant. The deformed variant is a superset, with some additional operations. (TODO:
// In theory rendering many "normal" objects in a row will outweigh the switching cost. One idea here is to emit the
// geometry as though it were batch-friendly, since it might be, but perform speculative bind texture and draw commands
// If we do indeed cross the critical point, keep the commands; otherwise convert them to no-ops.)
bool programsDifferWeakly = data->fProgram != fPrevious.fProgram;
bool programsDifferStrongly = programsDifferWeakly && !OnlyTryingToDowngradeMod( data->fProgram, fPrevious.fProgram );

bool blendDirty = data->fBlendMode != fPrevious.fBlendMode;
bool blendEquationDirty = data->fBlendEquation != fPrevious.fBlendEquation;
bool fillDirty0 = data->fFillTexture0 != fPrevious.fFillTexture0 && data->fFillTexture0;
bool fillDirty1 = data->fFillTexture1 != fPrevious.fFillTexture1 && data->fFillTexture1;
bool maskTextureDirty = data->fMaskTexture != fPrevious.fMaskTexture; // since PushMask() can stomp on the previous texture, a "not NULL" check here is unreliable
bool maskUniformDirty = data->fMaskUniform != fPrevious.fMaskUniform; // ...ditto
bool programDirty = data->fProgram != fPrevious.fProgram || MaskCount() != fCurrentProgramMaskCount;
bool programDirty = programsDifferStrongly || MaskCount() != fCurrentProgramMaskCount;
bool userUniformDirty0 = data->fUserUniform0 != fPrevious.fUserUniform0 && data->fUserUniform0;
bool userUniformDirty1 = data->fUserUniform1 != fPrevious.fUserUniform1 && data->fUserUniform1;
bool userUniformDirty2 = data->fUserUniform2 != fPrevious.fUserUniform2 && data->fUserUniform2;
Expand Down Expand Up @@ -524,6 +542,8 @@ Renderer::Insert( const RenderData* data )
if( primitiveType != fPreviousPrimitiveType || primitiveType != Geometry::kTriangleStrip )
{
batch = false;

programsDifferStrongly = programsDifferWeakly; // non-strips do not always populate 'q' member of vertex
}

// If the previous RenderData had its Geometry stored on the GPU,
Expand Down Expand Up @@ -686,7 +706,7 @@ Renderer::Insert( const RenderData* data )

// NOTE: The mask count is incremented just in time to select the correct program version, so we re-compare
// instead of using programDirty which does the equivalent calculation for batching purposes.
if( data->fProgram != fPrevious.fProgram || MaskCount() != fCurrentProgramMaskCount )
if( programsDifferStrongly || MaskCount() != fCurrentProgramMaskCount )
{
if( !data->fProgram->fGPUResource )
{
Expand Down