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

remove skip batch for custom program #20544

Open
wants to merge 1 commit into
base: v4
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
20 changes: 5 additions & 15 deletions cocos/renderer/CCTrianglesCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,24 @@ void TrianglesCommand::init(float globalOrder, Texture2D* texture, const BlendFu
}
_mv = mv;

if (_programType != _pipelineDescriptor.programState->getProgram()->getProgramType() ||
if (_programState != _pipelineDescriptor.programState ||
_texture != texture->getBackendTexture() ||
_blendType != blendType)
{
_programType = _pipelineDescriptor.programState->getProgram()->getProgramType();
_programState = _pipelineDescriptor.programState;
_texture = texture->getBackendTexture();
_blendType = blendType;

//since it would be too expensive to check the uniforms, simplify enable batching for built-in program.
if(_programType == backend::ProgramType::CUSTOM_PROGRAM)
setSkipBatching(true);

//TODO: minggo set it in Node?
auto& blendDescriptor = _pipelineDescriptor.blendDescriptor;
blendDescriptor.blendEnabled = true;
blendDescriptor.sourceRGBBlendFactor = blendDescriptor.sourceAlphaBlendFactor = blendType.src;
blendDescriptor.destinationRGBBlendFactor = blendDescriptor.destinationAlphaBlendFactor = blendType.dst;

if(!isSkipBatching())
generateMaterialID();
generateMaterialID();
}
}

void TrianglesCommand::updateMaterialID()
{
setSkipBatching(false);
generateMaterialID();
}

TrianglesCommand::~TrianglesCommand()
{
}
Expand All @@ -86,6 +75,7 @@ void TrianglesCommand::generateMaterialID()
struct
{
void* texture;
void* programState;
backend::ProgramType programType;
backend::BlendFactor src;
backend::BlendFactor dst;
Expand All @@ -97,9 +87,9 @@ void TrianglesCommand::generateMaterialID()
memset(&hashMe, 0, sizeof(hashMe));

hashMe.texture = _texture;
hashMe.programState = _programState;
hashMe.src = _blendType.src;
hashMe.dst = _blendType.dst;
hashMe.programType = _programType;
_materialID = XXH32((const void*)&hashMe, sizeof(hashMe), 0);
}

Expand Down
7 changes: 2 additions & 5 deletions cocos/renderer/CCTrianglesCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ NS_CC_BEGIN
*/
namespace backend {
class TextureBackend;
class Program;
class ProgramState;
}

class Texture2D;
Expand Down Expand Up @@ -99,9 +99,6 @@ class CC_DLL TrianglesCommand : public RenderCommand
/**Get the model view matrix.*/
const Mat4& getModelView() const { return _mv; }

/** update material ID */
void updateMaterialID();

protected:
/**Generate the material ID by textureID, glProgramState, and blend function.*/
void generateMaterialID();
Expand All @@ -118,7 +115,7 @@ class CC_DLL TrianglesCommand : public RenderCommand

// Cached value to determine to generate material id or not.
BlendFunc _blendType = BlendFunc::DISABLE;
backend::ProgramType _programType = backend::ProgramType::CUSTOM_PROGRAM;
backend::ProgramState* _programState = nullptr;
backend::TextureBackend* _texture = nullptr;
};

Expand Down