Loading...

mac-opengl@lists.apple.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: Weird figures with OpenGL 3.2 and Intel HD3000 vincent habchi Thu Feb 02 06:08:02 2012

Ingemar,

> It is not super-fast (just 16 cores), but it is a *good* GPU,
> full-featured 9000 series. I have been using it for my courses in advanced
> game programming and GPU computing and it is a joy to see it outperform
> the CPU effortlessly. I make jokes about it being a simple laptop GPU and
> then run my demos... wham! Oops! Not monster number as if I used a 590,
> but still a decent performer for being a mini-GPU.

I agree, I must admit I was pretty much pleased with it. And since I get these 
very good figures, I think I’ll use it also for some OpenCL computations. After 
all, it is idle most of time between two frames.

>> 
>> (BTW, I made a mistake in my first message. On the HD3000, it takes 10 ms,
>> not 10 µs).
> 
> That is a huge difference. To me, it sounds like the rendering is dropping
> into software rendering somewhere. Maybe in the fragment shader? Then the
> number of vertices wouldn't affect the problem.

Well, I have put some probes at the GL context initialization:

[[self openGLContext] getValues:& gpuProcess 
forParameter:NSOpenGLCPGPUVertexProcessing];
NSLog(@"Using %@ vertex shader", gpuProcess == 0 ? @"CPU" : @"GPU");
[[self openGLContext] getValues:& gpuProcess 
forParameter:NSOpenGLCPGPUFragmentProcessing];
NSLog(@"Using %@ fragment shader", gpuProcess == 0 ? @"CPU" : @"GPU");

and it reports GPU for both. 

> I have a GMA 950 in my old MacBook, and it is awful. It has shader
> support, but beyond a pretty small shader size, it turns to software and
> everything stops. Same problem? Can it be the shader size or some feature
> in the shaders that makes that happen? No comments in the infolog?

My shader are very simple :

Vertex:

#version 150

uniform         mat4            positionMatrix;

uniform         mat4            lookAt;
uniform         mat4            projLookAt;

uniform         mat4            projLookAtFromLight;
uniform         vec4            lightPosition;

uniform         bool            computeShadowMap;
        
        in      vec3            position;
        in      vec3            normalVector;
        in      vec2            textureCoord;

smooth  out     vec4            fragCoord;
smooth  out     vec4            shadowCoord;
smooth  out     vec2            texCoord;

smooth  out     float           diffLight;

void main (void) {
        vec4    truePosition = positionMatrix * vec4 (position, 1);
        
        if (! computeShadowMap) {
                // Compute transformation of normals
                // In the case of spheres, there is no need to compute the 
inverse transpose of the MV matrix
                // Since we ignore translation and scaling, only LookAt is 
relevant, and LookAt is unitary
                
                vec4    norm = lookAt * vec4 (normalVector, 0);
                        norm.w = 0.0;
                        diffLight = 1.0 - pow (1.0 - max (dot (lightPosition, 
norm), 0.0), 10.0);
                
                // Transformation of texture coordinates (both true and shadow 
mapping)
                texCoord = textureCoord;
                shadowCoord = 0.5 * projLookAtFromLight * truePosition + vec4 
(0.5, 0.5, 0.5, 0.5);
        }
        
        // Output projected 2D coordinates for our vertex
        gl_Position = projLookAt * truePosition;
}

Fragment (all shadow mapping stuff is currently disabled):

#version 150

// What are we drawing?

uniform         bool            drawEarth;
uniform         bool            drawMoon;
uniform         bool            computeShadowMap;

// Texture stuff
smooth          in      vec2    texCoord;
uniform         sampler2D       mainTexture;
uniform         sampler2D       auxiliaryTexture;
uniform         float           dayAngle;

uniform         sampler2DShadow shadowSampler;

// Light stuff
uniform         float           ambiantLight;
uniform         vec4            lightColor;
uniform         float           lightIntensity;

smooth  in      float           diffLight;

// Geometry inputs

smooth  in      vec4            shadowCoord;

                out vec4        fragColor;

void main (void) {
        
        // If we do a shadow map computing, then we don’t care about color
        if (computeShadowMap) {
                
                fragColor = vec4 (0, 0, 0, 1);
        }
        
        else {
                // Perform Phong-Gouraud shading
                
                if (drawEarth) {
                        // Blend day and night textures according to 
diffLightValue
                        // Offset simulates Earth rotation

                        vec2    earthTextureOffset = vec2 (- dayAngle / 360.0, 
0);
                        vec2    earthTextureCoord = texCoord + 
earthTextureOffset;
                        
                        vec4    dayTexel = texture (mainTexture, 
earthTextureCoord);
                        vec4    nightTexel = texture (auxiliaryTexture, 
earthTextureCoord);
                        
                        fragColor = lightColor * mix (nightTexel, dayTexel, 
diffLight);
                }
                
                else {
                        // Moon or satellite drawing: do shadow mapping
                        // Perform a 5 x 5 weighted dithering on the shadow map
                        if (drawMoon) {
                                // Apply texture
                                fragColor = texture (mainTexture, texCoord);
                        }
                        else {
                                fragColor = vec4(1, 1, 1, 1);
                        }
                        
                        /*float shadowFilter = 0;
                        
                        shadowFilter += 0.125 * textureProjOffset 
(shadowSampler, shadowCoord, ivec2 (-2, -2));
                        shadowFilter += 0.2 * textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (-2, -1));
                        shadowFilter += 0.25 * textureProjOffset 
(shadowSampler, shadowCoord, ivec2 (-2, 0));
                        shadowFilter += 0.2 * textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (-2, 1));
                        shadowFilter += 0.125 * textureProjOffset 
(shadowSampler, shadowCoord, ivec2 (-2, 2));
                        shadowFilter += 0.2 * textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (-1, -2));
                        shadowFilter += 0.5 * textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (-1, -1));
                        shadowFilter += textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (-1, 0));
                        shadowFilter += 0.5 * textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (-1, 1));
                        shadowFilter += 0.2 * textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (-1, 2));
                        shadowFilter += 0.25 * textureProjOffset 
(shadowSampler, shadowCoord, ivec2 (0, -2));
                        shadowFilter += textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (0, -1));
                        shadowFilter += 2 * textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (0, 0));
                        shadowFilter += textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (0, 1));
                        shadowFilter += 0.25 * textureProjOffset 
(shadowSampler, shadowCoord, ivec2 (0, 2));
                        shadowFilter += 0.2 * textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (1, -2));
                        shadowFilter += 0.25 * textureProjOffset 
(shadowSampler, shadowCoord, ivec2 (1, -1));
                        shadowFilter += textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (1, 0));
                        shadowFilter += 0.25 * textureProjOffset 
(shadowSampler, shadowCoord, ivec2 (1, 1));
                        shadowFilter += 0.2 * textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (1, 2));
                        shadowFilter += 0.125 * textureProjOffset 
(shadowSampler, shadowCoord, ivec2 (2, -2));
                        shadowFilter += 0.2 * textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (2, -1));
                        shadowFilter += 0.25 * textureProjOffset 
(shadowSampler, shadowCoord, ivec2 (2, 0));
                        shadowFilter += 0.2 * textureProjOffset (shadowSampler, 
shadowCoord, ivec2 (2, 1));
                        shadowFilter += 0.125 * textureProjOffset 
(shadowSampler, shadowCoord, ivec2 (2, 2));
                        */

                        // Compute total lightning intensity                    
                        fragColor *= (clamp (diffLight, 0.0, 1.0) * 
lightIntensity) * lightColor;
                        // Clamps shadows to ambiant
                        fragColor = clamp (fragColor, ambiantLight, 1.0);
                }
        }
}

---

They are really straightforward, I can’t figure out where is the hurdle. BTW, 
as you can see, spheres are supposed to be Earth and Moon, this is going to be 
a small 3D app (mainly educational) to display satellites orbits in real time.

I’m unaware of a dynamic fallback mechanism from GPU to CPU. How could that 
happen?

Hej då!
Vincent _______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      ([EMAIL PROTECTED])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/alexiscircle%40gmail.com

This email sent to [EMAIL PROTECTED]