Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » HLSL shader platform

This thread is locked; no one can reply to it. rss feed Print
HLSL shader platform
Dizzy Egg
Member #10,824
March 2009
avatar

Hello. I'm currently playing with HLSL shaders in Allegro, and was wondering if anyone knows how to force the compiler to use a higher version than PS_2_0.

One of my shaders has too much arithmetic (only 64 instructions allowed on PS_2_0) so I was hoping to bump it up to PS_3_0 or PS_4_0.

All of the things I've tried from online research seem to be very DirectX specific, and I can't quite work out how to do this in Allegro (or if it's even possible).

Any suggestions welcomed!

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Dizzy Egg
Member #10,824
March 2009
avatar

Thanks Edgar.

I've ported over the HLSL to OpenGL, which runs it fine (with the same arithmetic). I think for now I'll stick with OpenGL, everyone has that nowadays right? ;D

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Dizzy Egg
Member #10,824
March 2009
avatar

Frustratingly OpenGL with allegro runs a little choppy on my laptop.

Regardless of complexity (a simple bitmap being blitted at 1280x720), if I run it using DirectX/3D it runs beautifully, if I run it using OpenGL (especially fullscreen) it "judders", like frames are being missed.

I'm using the good ol' logic of a timer (1.0 /60) and waiting for event, redraw, etc.

I suppose my on-board card prefers DirectX to OpenGL when it comes to allegro?

I looked into using interplation but couldn't get the math right in my head.

Any tips? 8-)

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

It may be a vsync issue. It's usually up to the driver to pick whether vsync is on or not, and that usually comes from the system graphics driver settings.

Guessing DX is better on your laptop, with an integrated chipset.

Most monitors also refresh on 59.97 HZ, not actually 60.0 .

Dizzy Egg
Member #10,824
March 2009
avatar

I still can't work out whether it was a vsync issue or a too many frame being drawn issue, but I have found a solution that's working out really well.

I create the display as usual using al_create_display, but then I grab a HDC* to the opengl context, and instead of using al_flip_display() as usual, I call SwapBuffers wrapped within a combination of calls to glReadBuffer/glDrawBuffer, to make sure the same frame never gets drawn.

It's completely cured the jittery effect, it's performance now is on par with the Direct3D option.

Many bothans died to bring us this information, which is another way of saying MAN that took a lot of trial and error (and googling * shouting / fps).

EDIT:

And that's also running smooth with a single shader using 32 lights, just to make it an even better night! 8-)

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Neil Roy
Member #2,229
April 2002
avatar

I can't remember what I coded now, but I recall something where I tried out DirectX and OpenGL and found that OpenGL ran at half the frame rate under Allegro. Not sure what it was off hand now, been a while. Coded some stuff in straight Windows code + OpenGL and had no problems with some good frame rates.

---
“I love you too.” - last words of Wanda Roy

SiegeLord
Member #7,827
October 2006
avatar

It's easy enough to get PS_3_0, if you can compile Allegro yourself, just apply this patch:

#SelectExpand
1--- a/src/win/d3d_shader.cpp 2+++ b/src/win/d3d_shader.cpp 3@@ -47,7 +47,7 @@ static const char *technique_source_vertex = 4 "{\n" 5 " pass p1\n" 6 " {\n" 7- " VertexShader = compile vs_2_0 vs_main();\n" 8+ " VertexShader = compile vs_3_0 vs_main();\n" 9 " PixelShader = null;\n" 10 " }\n" 11 "}\n"; 12@@ -58,7 +58,7 @@ static const char *technique_source_pixel = 13 " pass p1\n" 14 " {\n" 15 " VertexShader = null;\n" 16- " PixelShader = compile ps_2_0 ps_main();\n" 17+ " PixelShader = compile ps_3_0 ps_main();\n" 18 " }\n" 19 "}\n\n"; 20 21@@ -67,8 +67,8 @@ static const char *technique_source_both = 22 "{\n" 23 " pass p1\n" 24 " {\n" 25- " VertexShader = compile vs_2_0 vs_main();\n" 26- " PixelShader = compile ps_2_0 ps_main();\n" 27+ " VertexShader = compile vs_3_0 vs_main();\n" 28+ " PixelShader = compile ps_3_0 ps_main();\n" 29 " }\n" 30 "}\n";

Getting 4_0 and 5_0 is more complicated.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Go to: