Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Greyscale-Filter is too slow. How to improve performance?

This thread is locked; no one can reply to it. rss feed Print
 1   2   3   4 
Greyscale-Filter is too slow. How to improve performance?
Marcello
Member #1,860
January 2002
avatar

Wouldn't a hardware-accelerated grayscale filter require programmable pixel shader?

Marcello

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Quote:

Wouldn't a hardware-accelerated grayscale filter require programmable pixel shader?

No. Texture combiners with dot product support would be enough. :)

A J
Member #3,025
December 2002
avatar

Quote:

Someone programmed a realtime ray tracer and used prefetching when traversing KD-tree*

i know not what a KD-Tree is, but i presume it uses ptrs to store data, so data will not be linear in memory, therefore prefetch would make sense, and achieve some speed up.

dont bother with that article, i'll do some more research...
i've heard all the theory of prefetch, but have yet to see it work (for me) in practice.

___________________________
The more you talk, the more AJ is right. - ML

HoHo
Member #4,534
April 2004
avatar

Quote:

i presume it uses ptrs to store data, so data will not be linear in memory

You persume wrong. The KDTree is static and calculated in preprocesing step and gets stored in single array. That makes things a bit better than linked list. The data structure is laid out so that close nodes should be quite close in memory too so when one node is prefetched some of it's neibourghs get prefetched too. Each node is 8 bytes so usually quite a lot of them get fetched.

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

dudaskank
Member #561
July 2000
avatar

Hoho, that piece of code was on the filterMakeMonochromApprox2() on your post... so when you said it didn't work, I've made some test...

the code:

1public class TesteGray {
2 
3 public static void main(String[] args) {
4 int i, x = 100000000;
5 long t1, t2;
6 int gray;
7 gray = 0x80;
8 System.out.printf("gray: %x\n", gray);
9 System.out.printf("gray rgb1: %x\n", gray * ( ( 1 << 16 ) | ( 1 << 8 ) | 1 ));
10 System.out.printf("gray rgb2: %x\n", gray | ( gray << 8 ) | ( gray << 16));
11 System.out.printf("a simple benchmark...\n");
12 // method rgb1
13 t1 = System.currentTimeMillis();
14 for(i = 0; i < x; i++) {
15 gray = 0x80;
16 gray *= ( (1 << 16) | (1 << 8) | 1);
17 }
18 t2 = System.currentTimeMillis();
19 System.out.printf("rgb1 method %d times: %d ms\n", x, t2 - t1);
20 // method rgb2
21 t1 = System.currentTimeMillis();
22 for(i = 0; i < x; i++) {
23 gray = 0x80;
24 gray |= (gray << 8) | (gray << 16);
25 }
26 t2 = System.currentTimeMillis();
27 System.out.printf("rgb2 method %d times: %d ms\n", x, t2 - t1);
28 }
29}

well it's Java but you get the idea, hehehe... the output in my machine is:

gray: 80
gray rgb1: 808080
gray rgb2: 808080
a simple benchmark...
rgb1 method 100000000 times: 971 ms
rgb2 method 100000000 times: 951 ms

so you can see the method #2 works too... but don't have that super speed improvement that I think, hehehe

Toque a balada do amor inabalável, eterna love song de nós dois
Eduardo "Dudaskank"
[ Home Page (ptbr) | Blog (ptbr) | Tetris 1.1 (ptbr) | Resta Um (ptbr) | MJpgAlleg 2.3 ]

A J
Member #3,025
December 2002
avatar

that just makes the colour grey{Solid} we (as the topic heading indicates) are trying to do grey{scale}

___________________________
The more you talk, the more AJ is right. - ML

HoHo
Member #4,534
April 2004
avatar

Also there is no memory access.

For a bit better performance numbers you should put that whole function content to a new function an call it around five to ten times in a row. I wouldn't be suprised if speed increases several times.

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

 1   2   3   4 


Go to: