Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
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  
  speed of glsl  (Read 2917 times)
0 Members and 1 Guest are viewing this topic.
Offline lhkbob

JGO Knight


Medals: 32



« Posted 2007-11-02 23:32:09 »

Recently I had posted on the jogl forum topic with a similar question, so pardon my double-posting.  However, no one was able to come with a good answer to explain what I was seeing.

Anyway, here it goes:
When I'd draw a scene on either an intel mac book pro w/ geforce 8800 mobile or an amd pc with ati x700 using a custom glsl shader (even when it was only one line of work to assign the fragment color), it would perform significantly slower than the fixed function pipeline.
This is contrary to everything that I've heard, so I was wondering if anyone has experienced something similar or if there are ways in which you can incorrectly setup a shader program that causes it to run slower (and fyi, I only called glUseProgram() once so I no there was no additional call overhead slowing it down).

Thanks,

Offline gouessej

« In padded room »



TUER


« Reply #1 - Posted 2007-11-09 13:16:13 »

I will get my ATI Radeon X1950 in a few days and I would like to test your shader. I've already a small program written in JOGL which allows me to test the shaders. I would like to know if you're right because I plan to implement the Phong model in a shader and I don't want to decrease a lot the performances.

Offline Majick

Senior Newbie





« Reply #2 - Posted 2007-11-09 15:13:25 »

If memory serves correct(and correct me if i am wrong), you were not replacing fixed functionality, you were using a shader on top of it. (I.E. using all of the gl.glDoSomething() commands for your rendering etc... and then just changing the frag color with your shader) Take a look at http://www.gamedev.net/reference/programming/features/glsllib/
for an example of how to replace fixed functionality with shaders. The example shows how to replace texture and lighting functionality with shaders. It also shows how to build a shader library(actually the main purpose for the article).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 51
Projects: 11


Monkey for a head


« Reply #3 - Posted 2007-11-09 15:34:48 »

If memory serves correct(and correct me if i am wrong), you were not replacing fixed functionality, you were using a shader on top of it. (I.E. using all of the gl.glDoSomething() commands for your rendering etc... and then just changing the frag color with your shader)

Shaders only replace a portion of the existing API, you still need to use the same methods for submitting geometry data.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline lhkbob

JGO Knight


Medals: 32



« Reply #4 - Posted 2007-11-09 15:55:57 »

I had done some searching through gamedev and found other people that have had similar problems.  One of the things that they said may have been the cause was that there is some small constant overhead when drawing using a shader vs. ffp.  If this is true, it would explain the behavior of my test cases since increasing the complexity of the shader didn't cause in performance decrease (solid color to directional lighting model).

Offline Majick

Senior Newbie





« Reply #5 - Posted 2007-11-09 17:45:28 »

Quote
Shaders only replace a portion of the existing API, you still need to use the same methods for submitting geometry data.

- this i understand.....

the original post asked.....
Quote
it seems that the shader programs give me worse framerate.  With a fixed function pipeline, I could get about 18 fps drawing 10,000 cubes, while using the shader it would give me only 12.5.  The shader consited of this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
vertex shader:
void main() {
gl_FrontColor = gl_Color;
gl_Position = ftransform();
}
fragment shader:
void main() {
gl_FragColor = vec4(.2, .4, .5, 1);
}


my point went along w/ what ezmic added in the original post.... The shader that was shown doesn't seem to replace any fixed functionality ..... It looks like it is just setting a frag color in addition to the original rendering(original rendering 18fps, original rendering + shader changing frag color = more work so this should be slightly slower)  .... am i missing something?? I am very sorry if i am just confused on this. I wouldn't want to send anyone off in the wrong direction....

Offline Orangy Tang

JGO Kernel


Medals: 51
Projects: 11


Monkey for a head


« Reply #6 - Posted 2007-11-09 18:52:41 »

- this i understand.....

the original post asked.....
my point went along w/ what ezmic added in the original post.... The shader that was shown doesn't seem to replace any fixed functionality ..... It looks like it is just setting a frag color in addition to the original rendering(original rendering 18fps, original rendering + shader changing frag color = more work so this should be slightly slower)  .... am i missing something?? I am very sorry if i am just confused on this. I wouldn't want to send anyone off in the wrong direction....


Well a basic no-lighting no-textures FF setup will stil have to output the surface colour. So the original rendering would use the FF pipeline to output a solid colour, whereas the shader version disables the FF part and replaces it with an identical shader implementation.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Majick

Senior Newbie





« Reply #7 - Posted 2007-11-09 19:57:38 »

1  
2  
3  
4  
ok so lets say i render something large  where i specify a color for all verticies as case 1......

[code]gl.glInterleavedArrays(GL.GL_C4F_N3F_V3F, 0, meshVertices);
           gl.glDrawArrays(GL.GL_TRIANGLES, 0, MeshVertCount);


for case 2 i do the same thing w/ a simple shader but i use GL.GL_N3F_V3F  and let the shader handle color

1  
2  
3  
4  
           //use program.................
          gl.glInterleavedArrays(GL.GL_N3F_V3F, 0, meshVertices);
           gl.glDrawArrays(GL.GL_TRIANGLES, 0, MeshVertCount);
           //useProgram(0);


case 2 should be faster right???

and for case 3 i do what case 1 did with the shader as well. Aren't i doing the color stuff w/ the FF and the shader basically duplicating effort, therefor adding overhead Huh......

code]
           //use program.................
           gl.glInterleavedArrays(GL.GL_C4F_N3F_V3F, 0, meshVertices);
           gl.glDrawArrays(GL.GL_TRIANGLES, 0, MeshVertCount);
           //useProgram(0);
[/code]

if Interleaved Arrays are a bad example replace that with gl.glVertex3f(), gl.glColor4f(), and gl.glNormal3f() ..... 

I would test this now but my work computer is horrible and doesn't support shaders Sad

Offline lhkbob

JGO Knight


Medals: 32



« Reply #8 - Posted 2007-11-09 23:05:16 »

According to the opengl spec, shaders are supposed to replace a portion of the FF pipeline, mainly vertex processing for a vertex shader and calculating fragment color for pixel stuff.  Thus is a shader is enabled, the FF portion won't be run along with the shader portion, it's one or the other.  However, shaders have so many extra attributes that are supposed to be available to them from the gl state that maybe making them available to the custom shader has some overhead. 

Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #9 - Posted 2007-11-11 14:01:32 »

Can you please post your entire test case for us? I think it would help us if we have the entire test case to see...

DP Smiley

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight


Medals: 32



« Reply #10 - Posted 2007-11-12 06:24:42 »

I would if it still gave the results that I said it did.  However, I had set it aside for a while and coming back to it, it no longer performs slower in the test case.  Performance is now identical.  I don't think I changed anything except that mac came out with a new software update, so that might have had an effect.  Anyway, I found an answer that worked and I'm not sure the problem really exists, so thanks all for the help.

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.

xsi3rr4x (31 views)
2014-04-15 18:08:23

BurntPizza (28 views)
2014-04-15 03:46:01

UprightPath (43 views)
2014-04-14 17:39:50

UprightPath (26 views)
2014-04-14 17:35:47

Porlus (43 views)
2014-04-14 15:48:38

tom_mai78101 (64 views)
2014-04-10 04:04:31

BurntPizza (124 views)
2014-04-08 23:06:04

tom_mai78101 (224 views)
2014-04-05 13:34:39

trollwarrior1 (190 views)
2014-04-04 12:06:45

CJLetsGame (198 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!