-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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 SpriteBatch when running non VertexArray VertexDataModes. (GL30 default) #7346
Merged
+103
−1
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
57ee279
SpriteBatch optimizations to preupload full indices data for the size…
Tom-Ski 3973c78
Apply formatter
actions-user c479202
Add message for waiting for data
Tom-Ski f8ba121
Merge remote-tracking branch 'origin/master' into spritebatch-index-o…
Tom-Ski 42dbcbc
Changelog
Tom-Ski File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteBatchPerformanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/******************************************************************************* | ||
* Copyright 2011 See AUTHORS file. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
******************************************************************************/ | ||
|
||
package com.badlogic.gdx.tests; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.graphics.GL20; | ||
import com.badlogic.gdx.graphics.Texture; | ||
import com.badlogic.gdx.graphics.g2d.BitmapFont; | ||
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | ||
import com.badlogic.gdx.math.WindowedMean; | ||
import com.badlogic.gdx.tests.utils.GdxTest; | ||
import com.badlogic.gdx.tests.utils.GdxTestConfig; | ||
import com.badlogic.gdx.utils.StringBuilder; | ||
|
||
@GdxTestConfig | ||
public class SpriteBatchPerformanceTest extends GdxTest { | ||
|
||
private Texture texture; | ||
private SpriteBatch spriteBatch; | ||
private WindowedMean counter = new WindowedMean(10000); | ||
private StringBuilder stringBuilder = new StringBuilder(); | ||
|
||
private BitmapFont bitmapFont; | ||
|
||
@Override | ||
public void create () { | ||
texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); | ||
spriteBatch = new SpriteBatch(8191); | ||
bitmapFont = new BitmapFont(); | ||
} | ||
|
||
@Override | ||
public void render () { | ||
Gdx.gl20.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); | ||
Gdx.gl20.glClearColor(0.2f, 0.2f, 0.2f, 1); | ||
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); | ||
|
||
spriteBatch.begin(); | ||
|
||
// Accelerate the draws | ||
for (int j = 0; j < 100; j++) { | ||
|
||
// fill the batch | ||
for (int i = 0; i < 8190; i++) { | ||
spriteBatch.draw(texture, 0, 0, 1, 1); | ||
} | ||
|
||
long beforeFlush = System.nanoTime(); | ||
|
||
spriteBatch.flush(); | ||
Gdx.gl.glFlush(); | ||
long afterFlush = System.nanoTime(); | ||
|
||
counter.addValue(afterFlush - beforeFlush); | ||
|
||
} | ||
|
||
spriteBatch.end(); | ||
|
||
spriteBatch.begin(); | ||
stringBuilder.setLength(0); | ||
stringBuilder.append("Mean Time ms: "); | ||
stringBuilder.append(counter.getMean() / 1e6); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add a conditional that shows "Please Wait..." on the text dependign if |
||
bitmapFont.draw(spriteBatch, stringBuilder, 0, 200); | ||
spriteBatch.end(); | ||
} | ||
|
||
@Override | ||
public void dispose () { | ||
texture.dispose(); | ||
spriteBatch.dispose(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor thing but maybe instead of drawing a single point we can change it to something like 20px * 20px just for the user to see something is happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@obigu i think it would bias the test since it will overload fragment shader stage, considering there are about 819.000 drawings, it would have to render 20x20 pixels each, so ~327 Mega pixels which could be a lot compared to the actual amount (less than 1 Mega pixels). In this end it would defeat isolation of this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we want to isolate a bit more, we could disable blending and use depth test (never pass) in order to fully bypass fragment stage.