Add simple optim and instrumentation for tthe number of input buffer changes per frame"

This commit is contained in:
sam gateau 2018-09-05 11:34:33 -07:00
parent 8344cb9aff
commit ce86e94e6f
4 changed files with 25 additions and 29 deletions

View file

@ -781,25 +781,6 @@ void FBXReader::buildModelMesh(FBXMesh& extractedMesh, const QString& url) {
attribChannel = 2;
totalAttribBufferSize = totalVertsSize - positionsSize - normalsAndTangentsSize;
} else {
/*
auto posBuffer = std::make_shared<gpu::Buffer>();
posBuffer->setData(positionsSize, (const gpu::Byte*) vertBuffer->getData() + positionsOffset);
vertexBufferStream->addBuffer(posBuffer, 0, positionElement.getSize());
// update channels and attribBuffer size accordingly
interleavePositions = false;
auto tangentBuffer = std::make_shared<gpu::Buffer>();
tangentBuffer->setData(normalsAndTangentsSize, (const gpu::Byte*) vertBuffer->getData() + normalsAndTangentsOffset);
vertexBufferStream->addBuffer(tangentBuffer, 0, normalsAndTangentsStride);
interleaveNormalsTangents = false;
tangentChannel = 1;
attribChannel = 2;
totalAttribBufferSize = totalVertsSize - positionsSize - normalsAndTangentsSize;*/
}
// Define the vertex format, compute the offset for each attributes as we append them to the vertex format
@ -813,9 +794,9 @@ void FBXReader::buildModelMesh(FBXMesh& extractedMesh, const QString& url) {
}
if (normalsSize) {
vertexFormat->setAttribute(gpu::Stream::NORMAL, tangentChannel, normalElement, bufOffset);
bufOffset = normalElement.getSize();
bufOffset += normalElement.getSize();
vertexFormat->setAttribute(gpu::Stream::TANGENT, tangentChannel, normalElement, bufOffset);
bufOffset = normalElement.getSize();
bufOffset += normalElement.getSize();
if (!interleaveNormalsTangents) {
bufOffset = 0;
}
@ -895,7 +876,7 @@ void FBXReader::buildModelMesh(FBXMesh& extractedMesh, const QString& url) {
vertexBufferStream->addBuffer(attribBuffer, 0, vStride);
}
// MEsh vertex format and vertex stream is ready
// Mesh vertex format and vertex stream is ready
mesh->setVertexFormatAndStream(vertexFormat, vertexBufferStream);
// Index and Part Buffers

View file

@ -268,9 +268,18 @@ void GLBackend::updateInput() {
auto offset = _input._bufferOffsets.data();
auto stride = _input._bufferStrides.data();
// Profile the count of buffers to update and use it to short cut the for loop
int numInvalids = _input._invalidBuffers.count();
_stats._ISNumInputBufferChanges += numInvalids;
PROFILE_COUNTER_IF_CHANGED(render_gpu, "numInputBuffersbound", int, numInvalids);
for (GLuint buffer = 0; buffer < _input._buffers.size(); buffer++, vbo++, offset++, stride++) {
if (_input._invalidBuffers.test(buffer)) {
glBindVertexBuffer(buffer, (*vbo), (*offset), (GLsizei)(*stride));
numInvalids--;
if (numInvalids <= 0) {
break;
}
}
}

View file

@ -78,7 +78,10 @@ void GL41Backend::updateInput() {
const Stream::Format::AttributeMap& attributes = _input._format->getAttributes();
auto& inputChannels = _input._format->getChannels();
_stats._ISNumInputBufferChanges++;
_stats._ISNumInputBufferChanges += _input._invalidBuffers.count();
// Profile the count of buffers to update
PROFILE_COUNTER_IF_CHANGED(render_gpu, "numInputBuffersbound", int, _input._invalidBuffers.count());
GLuint boundVBO = 0;
for (auto& channelIt : inputChannels) {

View file

@ -27,8 +27,6 @@ void GL45Backend::resetInputStage() {
}
void GL45Backend::updateInput() {
// PROFILE_RANGE(render_gpu, __FUNCTION__);
bool isStereoNow = isStereo();
// track stereo state change potentially happening wihtout changing the input format
// this is a rare case requesting to invalid the format
@ -131,21 +129,26 @@ void GL45Backend::updateInput() {
}
if (_input._invalidBuffers.any()) {
// PROFILE_RANGE(render_gpu, "bindInputBuffers");
auto vbo = _input._bufferVBOs.data();
auto offset = _input._bufferOffsets.data();
auto stride = _input._bufferStrides.data();
int numSet = 0;
// Profile the count of buffers to update and use it to short cut the for loop
int numInvalids = _input._invalidBuffers.count();
_stats._ISNumInputBufferChanges += numInvalids;
PROFILE_COUNTER_IF_CHANGED(render_gpu, "numInputBuffersbound", int, numInvalids);
auto numBuffers = _input._buffers.size();
for (GLuint buffer = 0; buffer < numBuffers; buffer++, vbo++, offset++, stride++) {
if (_input._invalidBuffers.test(buffer)) {
glBindVertexBuffer(buffer, (*vbo), (*offset), (GLsizei)(*stride));
numSet++;
numInvalids--;
if (numInvalids <= 0) {
break;
}
}
}
PROFILE_COUNTER_IF_CHANGED(render_gpu, "numVBSbound", int, numSet);
_input._invalidBuffers.reset();
(void)CHECK_GL_ERROR();