Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [solved] Horrible performance with GL_UNSIGNED_BYTE  (Read 1151 times)
0 Members and 1 Guest are viewing this topic.
Offline Kerai

Junior Member


Medals: 4



« Posted 2013-04-28 18:38:04 »

I'm learning OpenGL and decided to make some voxel rendering.

I use VBO to hold mesh for one chunk and I store only visible faces into the VBO
One VAO and one VBO per chunk.

Each chunk is only 32x32 so I decided to use unsigned byte as vertex data instead of floats.
Each vertex is stored with its local position in chunk.
I store chunk offset as uniform and add it to vertex data to render it at correct position.

Performance decreased... mostly visible on ATI cards (its horrible there)

I noticed it is very dependant on number of vertices. As all data is uploaded to VBO, it is clear that it's fail on GPU side.
I removed the lightning calculations to see if they were the cause, but it seems they weren't.

Maybe it's something with shaders having problem converting data types?
It works good with floats, but not with bytes.

Here are my shaders:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
#version 130

uniform mat4 camera;
uniform vec3 chunk; // chunk offset

in vec3 vert; // vertex
in vec2 vtex; // texture coordinate

out vec2 ftex;


void main() {
   // as I store UV in bytes, i need to divide them by amount of tiles I have in texture (currently 2x2)
   ftex = vtex/2;
   
   // I add vertex position and chunk offset to get corrent world position of vertex
   gl_Position = camera * vec4(vert+chunk, 1);
}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
#version 130

uniform sampler2D tex;

in vec2 ftex;

out vec4 final;

void main() {
    final = texture2D(tex, ftex);
}


They do almost nothing, but they perform hirribly.
Might it be the problem with input data definition?

in vec3 vert; // vertex
in vec2 vtex; // texture coordinate

vec3 and vec2 are float vectors - but VBO contains bytes.. is it really so hard for gpu to convert those types? I don't believe.
Maybe I should have use ivec3 and ivec2 (or uvec3 and uvec2) but if I use them I get veery werid input. deffinitely not what vbo contains.

What my scene looks like you can see in this demo: (light and all the stuff is removed to concentrate on the problem - simple vertex data rendering is horribly slow)
http://dev.keraj.net/czyde/ - it should work with about 900fps .. but it works with 100 on NVIDIA and 15(!) on ATI.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 757
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2013-04-28 20:48:55 »

Show us how you configure your VAOs.
Also compare your numbers when using half-floats,

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline pitbuller
« Reply #2 - Posted 2013-04-28 21:53:31 »

Is you data 4-byte aligned?

http://www.opengl.org/wiki/Vertex_Specification_Best_Practices
1  
2  
3  
4  
There is something you should watch out for. The alignment of any attribute's data should be no less than 4bytes.
So if you have a vec3 of GLushort​s, you can'
t use that 4th component for a new attribute (such as a vec2
of GLbyte​s). If you want to pack something into that instead of having useless padding, you
need to make it a vec4 of GLushort​s.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Kerai

Junior Member


Medals: 4



« Reply #3 - Posted 2013-04-28 22:19:38 »

@pitbuller: That's probably it!

I used 3 unsigned bytes for coords + 2 unsigned bytes for texture coords.

I just changed vec3 to vec4 and added one dummy value + changed UV to unsigned shorts. So they are all now 4-byte aligned and it went to 300 fps on ATI card.

Thanks!

How could I have missed that best-practices page. Cheesy
Offline pitbuller
« Reply #4 - Posted 2013-04-28 22:48:55 »

@pitbuller: That's probably it!

I used 3 unsigned bytes for coords + 2 unsigned bytes for texture coords.

I just changed vec3 to vec4 and added one dummy value + changed UV to unsigned shorts. So they are all now 4-byte aligned and it went to 300 fps on ATI card.

Thanks!

How could I have missed that best-practices page. Cheesy

So is it still 3times slower than with just using floats?
Offline Kerai

Junior Member


Medals: 4



« Reply #5 - Posted 2013-04-28 23:12:47 »

No, the case I tested it with now is the same speed with floats.
Sorry for additional confusion.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36

Riven (45 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!