Skip to content

Commit 69c14f7

Browse files
authored
Fix renderer test case batching (#2291)
* Ensure sprites using the same custom shader are batched * Fix for incorrect ProgramId check * Enhance check for valid batch ID * Use method name that indicates purpose
1 parent cfa6f51 commit 69c14f7

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

core/renderer/TrianglesCommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void TrianglesCommand::init(float globalOrder,
6868
blendDescriptor.sourceRGBBlendFactor = blendDescriptor.sourceAlphaBlendFactor = blendType.src;
6969
blendDescriptor.destinationRGBBlendFactor = blendDescriptor.destinationAlphaBlendFactor = blendType.dst;
7070

71-
if (_batchId == -1)
71+
if (!_pipelineDescriptor.programState->isBatchable())
7272
setSkipBatching(true);
7373

7474
if (!isSkipBatching())

core/renderer/backend/Program.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class AX_DLL Program : public Object
152152
* Get program id.
153153
* @return The program id.
154154
*/
155-
int64_t getProgramId() const { return _programId; }
155+
uint64_t getProgramId() const { return _programId; }
156156

157157
/**
158158
* Get uniform buffer size in bytes that can hold all the uniforms.

core/renderer/backend/ProgramManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ class AX_DLL ProgramManager
157157
};
158158

159159
BuiltinRegInfo _builtinRegistry[(int)backend::ProgramType::BUILTIN_COUNT];
160-
std::unordered_map<int64_t, BuiltinRegInfo> _customRegistry;
160+
std::unordered_map<uint64_t, BuiltinRegInfo> _customRegistry;
161161

162-
std::unordered_map<int64_t, Program*> _cachedPrograms; ///< The cached program object.
162+
std::unordered_map<uint64_t, Program*> _cachedPrograms; ///< The cached program object.
163163

164164
XXH64_state_s* _programIdGen;
165165

core/renderer/backend/ProgramState.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,18 @@ bool ProgramState::init(Program* program)
175175

176176
const auto programId = program->getProgramId();
177177
if (programId < ProgramType::BUILTIN_COUNT)
178+
{
178179
this->_batchId = programId;
180+
this->_isBatchable = true;
181+
}
179182

180183
return true;
181184
}
182185

183186
void ProgramState::updateBatchId()
184187
{
185188
_batchId = XXH64(_uniformBuffers.data(), _uniformBuffers.size(), _program->getProgramId());
189+
_isBatchable = true;
186190
}
187191

188192
void ProgramState::resetUniforms()
@@ -229,6 +233,7 @@ ProgramState* ProgramState::clone() const
229233
cp->_vertexLayout = !_ownVertexLayout ? _vertexLayout : new VertexLayout(*_vertexLayout);
230234

231235
cp->_batchId = this->_batchId;
236+
cp->_isBatchable = this->_isBatchable;
232237
return cp;
233238
}
234239

core/renderer/backend/ProgramState.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ class AX_DLL ProgramState : public Object
301301
*/
302302
uint64_t getBatchId() const { return _batchId; };
303303

304+
/*
305+
* Gets the state of the batch ID. If true, then batch ID is valid
306+
*/
307+
bool isBatchable() const { return _isBatchable; };
308+
304309
/*
305310
* Update batchID of current program state, by default, custom program was traits with mutable uniforms
306311
* so batch ID was set to -1 indicate batch was disabled
@@ -399,7 +404,8 @@ class AX_DLL ProgramState : public Object
399404
VertexLayout* _vertexLayout = nullptr;
400405
bool _ownVertexLayout = false;
401406

402-
uint64_t _batchId = -1;
407+
uint64_t _batchId = -1;
408+
bool _isBatchable = false;
403409

404410
#if AX_ENABLE_CACHE_TEXTURE_DATA
405411
EventListenerCustom* _backToForegroundListener = nullptr;

tests/cpp-tests/Source/NewRendererTest/NewRendererTest.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,9 @@ RendererUniformBatch::RendererUniformBatch()
824824
Size s = Director::getInstance()->getWinSize();
825825

826826
auto blurState = createBlurProgramState();
827+
blurState->updateBatchId();
827828
auto sepiaState = createSepiaProgramState();
829+
sepiaState->updateBatchId();
828830

829831
auto x_inc = s.width / 20;
830832
auto y_inc = s.height / 6;
@@ -896,8 +898,10 @@ RendererUniformBatch2::RendererUniformBatch2()
896898
{
897899
Size s = Director::getInstance()->getWinSize();
898900

899-
auto blurState = createBlurProgramState();
901+
auto blurState = createBlurProgramState();
902+
blurState->updateBatchId();
900903
auto sepiaState = createSepiaProgramState();
904+
sepiaState->updateBatchId();
901905

902906
auto x_inc = s.width / 20;
903907
auto y_inc = s.height / 6;

0 commit comments

Comments
 (0)