Comments (6)
PR #2105 shows the expected output (with 4 draw calls):
from axmol.
It seems that once a uniform value is updated, ProgramState::updateBatchId()
needs to be called in order to update the batch ID, and that in turn fixes the issue. This also ensures that same-value uniforms are batched together.
from axmol.
I think it's a bug. You should not be required to call updateBatchId()
.
from axmol.
The batch ID is equal to the program ID if it is using one of the built in shaders:
bool ProgramState::init(Program* program)
{
...
const auto programId = program->getProgramId();
if (programId < ProgramType::BUILTIN_COUNT)
this->_batchId = programId
...
}
The problem is when we do not use any of the built-in set of shaders; what does the batch ID get set to? Right now, it's set to a hash value. which is calculated via this:
void ProgramState::updateBatchId()
{
_batchId = XXH64(_uniformBuffers.data(), _uniformBuffers.size(), _program->getProgramId());
}
This is an expensive call, and should only be made if and only if a custom shader is being used, and the uniform data has changed. The only way to set this would be to add a call in the setUniform
method:
void ProgramState::setUniform(const backend::UniformLocation& uniformLocation, const void* data, std::size_t size)
{
if (uniformLocation.vertStage)
setVertexUniform(uniformLocation.vertStage.location, data, size, uniformLocation.vertStage.offset);
#ifdef AX_USE_METAL
if (uniformLocation.fragStage)
setFragmentUniform(uniformLocation.fragStage.location, data, size, uniformLocation.fragStage.offset);
#endif
const auto programId = program->getProgramId();
if (programId >= ProgramType::BUILTIN_COUNT)
updateBatchId();
}
In this case we're adding extra logic that should only ever apply when using custom shaders, and I'm not sure how many developers would be using their own. Would this be a worthwhile change to ProgramState::setUniform
?
Also, the change above doesn't check if the uniform data has changed, and only relies on the program using custom shaders.
@halx99 One other thing, is the hash generated by XXH64
guaranteed to be greater than the value of ProgramType::BUILTIN_COUNT
?
from axmol.
@halx99 One other thing, is the hash generated by
XXH64
guaranteed to be greater than the value ofProgramType::BUILTIN_COUNT
?
Yes
from axmol.
Builtin shaders can also have different uniforms, so there will be situations when they can't be batched either. I don't see why builtin shaders should have different logic than user shaders. And now I have suspicion that builtin shader batching is working by chance if their uniforms are ignored.
Maybe this should be solved with a dirty flag set when modifying uniforms and a possibility to trigger update manually by using ProgramState::updateBatchId()
, so you can do it after updating uniforms, while the uniform buffers are still in cache. But otherwise, it should be automatic.
from axmol.
Related Issues (20)
- Two rapidjson with different version cause unexpected crash problem on apple family platforms HOT 15
- MediaPlayer Video not correctly rendered for Android 11 and older devices
- [ImGui] Invalid texture data drawn on modal popups HOT 1
- ArchLinux setup dependencies always fail
- VolatileTextureMgr::addImage memory leak HOT 1
- HttpClient释放response指针异常
- FontFreeType performance issues on Android HOT 2
- UITest.json source HOT 3
- Node:getChildren()性能问题 HOT 6
- Unknow function "setTargetFlags" & "ax::RenderTargetFlag" in Live2D extensions
- Font Issue with Emojis & Emoticons HOT 2
- TextureCache::addImage should be return when textures found.
- checkReallySupportsASTC does not work on ios device HOT 6
- Can't add package to XCode project HOT 8
- 执行csb文件,打开界面慢 HOT 8
- MediaPlayer Video not correctly rendered for Android (Galaxy S22 Ultra)
- Incorrect child widget positions when using normalized positioning HOT 6
- `Sprite::setPolygonInfo()` doesn't set content size HOT 4
- The MediaPlayer controller widgets position incorrect after commit 4011 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axmol.