Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » DirectX VRAM-VRAM accelerated stretch blit

This thread is locked; no one can reply to it. rss feed Print
DirectX VRAM-VRAM accelerated stretch blit
GullRaDriel
Member #3,861
September 2003
avatar

Please, you seem to be both competent to modify and test those file.
I can leave you my access throught a VNC client, and you'll have all you need to do it.

Really, i think i'm not able to do this alone.

I'm not enough 'competent'

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Evert
Member #794
November 2000
avatar

Quote:

Please, you seem to be both competent to modify and test those file.

I lack a suitable operating system.

Quote:

I can leave you my access throught a VNC client, and you'll have all you need to do it.

You couldn't make that an ssh remote login, could you? Anyway, I'll see about attaching a patched up file for you. in a moment.

EDIT: here you go! Replace allegro/src/win/wddaccel.c with the attached version and recompile Allegro.

GullRaDriel
Member #3,861
September 2003
avatar

i can grant you a telnet access, openssh isn't installed.

EDIT:
telnet installed, ready to receive you after a little router reboot.
Just PM me some IM where i can join you

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Evert
Member #794
November 2000
avatar

See my above edit.

GullRaDriel
Member #3,861
September 2003
avatar

ok
i test

EDIT: it is still OK for the access, if even you wanna test yourself

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Evert
Member #794
November 2000
avatar

This is the full patch I'm going to propose as soon as my provider's sendmail server is unblocked:

1Index: src/win/wddaccel.c
2===================================================================
3--- src/win/wddaccel.c (revision 5662)
4+++ src/win/wddaccel.c (working copy)
5@@ -15,6 +15,7 @@
6 * Bugfixes by Isaac Cruz.
7 *
8 * Accelerated rectfill() and hline() added by Shawn Hargreaves.
9+ * Accelerated stretch_blit() and friends by Thomas Harte
10 *
11 * See readme.txt for copyright information.
12 */
13@@ -34,6 +35,7 @@
14 static void (*_orig_rectfill) (BITMAP * bmp, int x1, int y1, int x2, int y2, int color);
15 static void (*_orig_draw_sprite) (BITMAP * bmp, BITMAP * sprite, int x, int y);
16 static void (*_orig_masked_blit) (BITMAP * source, BITMAP * dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);
17+static void (*_orig_stretch_blit) (BITMAP *source, BITMAP *dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height, int masked);
18
19
20
21@@ -193,6 +195,68 @@
22
23
24
25+/* ddraw_do_stretch_blit:
26+ * Accelerated stretch_blit, stretch_sprite, stretch_masked_blit
27+ */
28+static void ddraw_do_stretch_blit(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height, int masked)
29+{
30+ RECT dest_rect, source_rect;
31+ DDCOLORKEY src_key;
32+ HRESULT hr;
33+ BITMAP *dest_parent;
34+ BITMAP *source_parent;
35+
36+ dest_rect.left = dest_x + dest->x_ofs;
37+ dest_rect.top = dest_y + dest->y_ofs;
38+ dest_rect.right = dest_x + dest->x_ofs + dest_width;
39+ dest_rect.bottom = dest_y + dest->y_ofs + dest_height;
40+
41+ source_rect.left = source_x + source->x_ofs;
42+ source_rect.top = source_y + source->y_ofs;
43+ source_rect.right = source_x + source->x_ofs + dest_width;
44+ source_rect.bottom = source_y + source->y_ofs + dest_height;
45+
46+ src_key.dwColorSpaceLowValue = source->vtable->mask_color;
47+ src_key.dwColorSpaceHighValue = source->vtable->mask_color;
48+
49+ if (is_video_bitmap(source) || is_system_bitmap(source)) {
50+
51+ /* find parents */
52+ dest_parent = dest;
53+ while (dest_parent->id & BMP_ID_SUB)
54+ dest_parent = (BITMAP *)dest_parent->extra;
55+
56+ source_parent = source;
57+ while (source_parent->id & BMP_ID_SUB)
58+ source_parent = (BITMAP *)source_parent->extra;
59+
60+ _enter_gfx_critical();
61+ gfx_directx_release_lock(dest);
62+ gfx_directx_release_lock(source);
63+
64+ IDirectDrawSurface2_SetColorKey(DDRAW_SURFACE_OF(source_parent)->id,
65+ DDCKEY_SRCBLT, &src_key);
66+
67+ hr = IDirectDrawSurface2_Blt(DDRAW_SURFACE_OF(dest_parent)->id, &dest_rect,
68+ DDRAW_SURFACE_OF(source_parent)->id, &source_rect,
69+ (masked ? DDBLT_KEYSRC : 0) | DDBLT_WAIT, NULL);
70+ _exit_gfx_critical();
71+
72+ if (FAILED(hr))
73+ _TRACE(PREFIX_E "Blt failed (%x)\n", hr);
74+
75+ /* only for windowed mode */
76+ if ((gfx_driver->id == GFX_DIRECTX_WIN) && (dest_parent == gfx_directx_forefront_bitmap))
77+ win_gfx_driver->paint(&dest_rect);
78+ }
79+ else {
80+ /* have to use the original software version */
81+ _orig_stretch_blit(source, dest, source_x, source_y, source_width, source_height, dest_x, dest_y, dest_width, dest_height, masked);
82+ }
83+}
84+
85+
86+
87 /* ddraw_clear_to_color:
88 * Accelerated screen clear routine.
89 */
90@@ -458,6 +522,7 @@
91 _orig_rectfill = _screen_vtable.rectfill;
92 _orig_draw_sprite = _screen_vtable.draw_sprite;
93 _orig_masked_blit = _screen_vtable.masked_blit;
94+ _orig_stretch_blit = _screen_vtable.do_stretch_blit;
95
96 /* accelerated video to video blits? */
97 if (ddcaps.dwCaps & DDCAPS_BLT) {
98@@ -466,8 +531,9 @@
99 _screen_vtable.blit_to_self_backward = ddraw_blit_to_self;
100 _screen_vtable.blit_from_system = ddraw_blit_to_self;
101 _screen_vtable.blit_to_system = ddraw_blit_to_self;
102+ _screen_vtable.do_stretch_blit = ddraw_do_stretch_blit;
103
104- gfx_capabilities |= (GFX_HW_VRAM_BLIT | GFX_HW_SYS_TO_VRAM_BLIT);
105+ gfx_capabilities |= (GFX_HW_VRAM_BLIT | GFX_HW_SYS_TO_VRAM_BLIT | GFX_HW_STRETCH_BLIT);
106 }
107
108 /* accelerated color fills? */
109Index: include/allegro/gfx.h
110===================================================================
111--- include/allegro/gfx.h (revision 5662)
112+++ include/allegro/gfx.h (working copy)
113@@ -142,6 +142,7 @@
114 #define GFX_HW_SYS_TO_VRAM_BLIT 0x00100000
115 #define GFX_HW_SYS_TO_VRAM_BLIT_MASKED 0x00200000
116 #define GFX_SYSTEM_CURSOR 0x00400000
117+#define GFX_HW_STRETCH_BLIT 0x00800000
118
119
120 AL_VAR(int, gfx_capabilities); /* current driver capabilities */

GullRaDriel
Member #3,861
September 2003
avatar

do you wanna me to post it for you ?

it's still compiling, i make a distclean before a make all

EDIT: compiled, i'm uploading the whole compiled.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Neil Walker
Member #210
April 2000
avatar

Remember to change the draw_sprite code to remove the offsets when you do the stretch_blit update. I guess the mystery of the masked_blit working/the clipping code can remain so.

I don't know how often the CVS is updated but it would also be great to have a fix for it not crashing when you destroy a system sub-bitmap :)

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

GullRaDriel
Member #3,861
September 2003
avatar

who wanna test?

Download the sfx archive

It's the whole library including source and compiled version of allegro-patched

EDIT: when testing at my home, i just modify the exscale to load a pink masked pcx, and i use the masked_stretch_blit.

How can we check what does it use ? hardware or software ?

EDIT: attached is the modified exscale... i can ensure you that is it accelerated on my pc ! (now with source and modified mysha.pcx)

I can't see what the picture is now, it's too fast !

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Neil Walker
Member #210
April 2000
avatar

It doesn't work. I actually only tested it for the draw_sprite change, which works, but my sample code also does stretch_blit.

If you have a memory bitmap and a memory buffer all is well, if you have a system/video buffer and/or a system/video bitmap you either end up with a crash or (in the case of sub-bitmaps) instead of stretching it it actually makes the sub-bitmap bigger so you simply get a larger area of the master image!

Do you want a copy of my test program to try it, and you can modify the bitmap types easily to see?

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Evert
Member #794
November 2000
avatar

Quote:

it's still compiling, i make a distclean before a make all

Next time, don't! That's the point in using make: it only recompiles what it has to to safe time.

Quote:

How can we check what does it use ? hardware or software ?

Normally I'd put printf() or trace statements in the code and see if I get output from those. That doesn't work in Windows though, so I guess you'd have to check the framerate.

Quote:

Remember to change the draw_sprite code to remove the offsets when you do the stretch_blit update.

Neil... please don't plug these things whenever you have a chance. Honestly, if it's know it's known. Don't start posting reminders for unapplied patches unless more than a week has passed since the last message about it or you get no feedback whatsoever. Also don't do it in threads about other topics. It's impolite.

Quote:

I don't know how often the CVS is updated

The SVN repository gets updated whenever a patch is applied. I'm not sure what you mean?

EDIT:

Quote:

It doesn't work. I actually only tested it for the draw_sprite change, which works, but my sample code also does stretch_blit.

That doesn't make sense. The code for stretch_blit() and the code for draw_sprite() (and masked_stretch_blit) is the same. So as far as I can see it either works, or it doesn't.

GullRaDriel
Member #3,861
September 2003
avatar

yeah, of course !

(even if we talk here of a masked_stretch_blit)

EDIT: Modified in 800x600 for Sev' attached

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Neil Walker
Member #210
April 2000
avatar

Quote:

That doesn't make sense. The code for stretch_blit() and the code for draw_sprite() (and masked_stretch_blit) is the same. So as far as I can see it either works, or it doesn't.

what you are saying is correct - none of them work when you are not using memory bitmaps, all of them work when you are using memory bitmaps. The errors you get are depenant upon whether you are using system/video for the graphics or the back-buffer or both and whether your graphics are sub-bitmaps

Attached is a test program that will show bitmaps and a stretched bitmap. The current version you see is using sub-bitmaps and memory bitmap/buffer only that works fine.

To change it to see how it crashes/fails then

To change the back-buffer edit config.xml, change graphicsmode="0" (0=double, 1=system double, 2=paged, 3=triple). Obviously 2/3 use video.

To change the graphics edit animations.xml and change bmp_type="1" (1 is memory, 2 is system, 3 is video).

It will fail in different ways when you use anything other than memory bitmaps.

After you've waded through those, rename the animations.xml file to animations.old or something and rename animations_single.xml to be animations.xml and repeat the tests. This will change the graphics from being sub-bitmaps to be individually loaded bitmaps. These have a different result again.

btw, don't worry about the crash when you use system bitmaps and buffer with sub-bitmaps. This is a known error.

Quote:

Neil... please don't plug these things whenever you have a chance. Honestly, if it's know it's known. Don't start posting reminders for unapplied patches unless more than a week has passed since the last message about it or you get no feedback whatsoever. Also don't do it in threads about other topics. It's impolite.

Ok, I'll address the first point - all I was doing was reminding someone as it wasn't a definite CVS update, just a thread conversation. Secondly, I wasn't posting about other topics, the stretch blit problems are linked to the draw_sprite problems, which in turn are linked to the subbitmaps of system bitmaps crashing fault.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

GullRaDriel
Member #3,861
September 2003
avatar

i'll try to compil it tomorrow with the modified allegro.
I test , and it is already a nice work.
I'm smoking my last before going to sleep.

See you tomorow for the tests, All.

EDIT: and for the 'windows' specific , i'm thinkin of providing a ssh access to my pc for AD. I'll keep you informed. I think i can easily provide a ftp-ssh-x11-vnc compliant access.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Neil Walker
Member #210
April 2000
avatar

I've just this second modified my download file in the previous email as I included the wrong XML files, so if anyone has downloaded it before now you'll have to get it again. There is no compilation as it's a windows executable. See stretch working first then try the different modes by editing the xml files to see the new code fail.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Evert
Member #794
November 2000
avatar

Quote:

what you are saying is correct

Wait... you said

Quote:

It doesn't work. I actually only tested it for the draw_sprite change, which works, but my sample code also does stretch_blit.

I read this as `It doesn't work, but draw_sprite works. When I use stretch_blit it doesn't work'. I don't think that's what you meant and it certainly doesn't make any sense (as I said). So do I understand you correctly if I understand that hardware accelerated VRAM->VRAM streched blits do not work for you?

Quote:

- none of them work when you are not using memory bitmaps, all of them work when you are using memory bitmaps. The errors you get are depenant upon whether you are using system/video for the graphics or the back-buffer or both and whether your graphics are sub-bitmaps

Please keep it simple, or take a little more time to explain what you're doing!
Leave system bitmaps, subbitmaps and whatnot out of it for the moment as testing all of this at the same time is much, much too confusing. At least it is for me. One thing at a time. If you are doing too many things at once it just becomes too complicated and convoluted to keep track of what's going on.
All that needs to be tested in response to the patch I posted above is wether or not VRAM->VRAM stretched blits are now hardware accelerated or not.
GullRaDriel's post suggested that it works for him, I get the impression that it doesn't work for you? Have you tested his modified exscale?

Quote:

After you've waded through those, rename the animations.xml file to animations.old or something and rename animations_single.xml to be animations.xml and repeat the tests. This will change the graphics from being sub-bitmaps to be individually loaded bitmaps. These have a different result again.

Please keep the test case simple. As I said, there's far too much going on here to keep track of what's going on and what's failing and what isn't and why.

Quote:

Ok, I'll address the first point - all I was doing was reminding someone as it wasn't a definite CVS update, just a thread conversation.

I fail to see what that has to do with saying `Remember to change the draw_sprite code to remove the offsets when you do the stretch_blit update.' The current test has nothing to do with draw_sprite. Maybe I'm missing something?

Quote:

Secondly, I wasn't posting about other topics, the stretch blit problems are linked to the draw_sprite problems, which in turn are linked to the subbitmaps of system bitmaps crashing fault.

I don't see that. There are no subbitmaps or system bitmaps in sight for this thread. Anyway, if that's causing the problems you're seeing (which I'm not saying it isn't), you have a patched version of Allegro, right? Does it work properly with that?

Please try to describe in a clear, simple and concise manner if and when things work and when they don't. Don't try to test every possible case at once and if you do put some work in how you present the results (eg, make a table of the posibilities and results). As it is, I can't make heads or tails of it.

Thomas Fjellstrom
Member #476
June 2000
avatar

OT:

This started me thinking about possible enhancments of the X driver(s), Besides just using standard X functions, theres a few extensions that may help, though I'm not sure how much.. The XDamage extension allows you to get detailed info about damaged areas, XRender allows you to render the window to an off screen surface (and other windows as well) as well as use various rendering modes, and the Xcomposite extension works with the other two to give us fancy compositing eye candy.

I would be happy to work on integrating some of these (namely XDamage and XRender) into allegro, at least once the open source ATI drivers support XRender for my 9600xt. Though I probably won't beable to do it all myself.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Thomas Harte
Member #33
April 2000
avatar

Ahhh, I've found a potential problem. To cut a long story short:

if ((ddcaps.dwCaps & DDCAPS_COLORKEY) &&
       (ddcaps.dwCKeyCaps & DDCKEYCAPS_SRCBLT)) {
      _screen_vtable.masked_blit = ddraw_masked_blit;
      _screen_vtable.draw_sprite = ddraw_draw_sprite;

      /* new entry */
      if (ddcaps.dwCaps&DDCAPS_BLTSTRETCH)
         _screen_vtable.do_stretch_blit = ddraw_do_stretch_blit;

      if (_screen_vtable.color_depth == 8)
   _screen_vtable.draw_256_sprite = ddraw_draw_sprite;

      gfx_capabilities |= (GFX_HW_VRAM_BLIT_MASKED | GFX_HW_SYS_TO_VRAM_BLIT_MASKED);
   }

A better solution would allow non-masked stretch blitting where wither of DDCAPS_COLORKEY or DDCKEYCAPS_SRCBLT are not set.

EDIT:

Quote:

OT:

This started me thinking about possible enhancments of the X driver(s)

Yeah, the only reason I'm suddenly so up on where Allegro does what is that I've been researching improvements to the OS X driver...

Evert
Member #794
November 2000
avatar

Ok, how about the attached patch?
Copy it to the main Allegro directory (allegro/) and run patch -p0 < dx_stretch_blit.diff.
It should test the capabilities of the graphics card and separate the blit and masked_blit tests. The test programme should also report which of these two works (but it doesn't offer a way of testing either; that'll have to be fixed later).

Neil Walker
Member #210
April 2000
avatar

ok, i'll make a simple table of what works and what doesn't with various bitmap types in windows, to try and make it easier to read. However, I don't have any CVS tools, any chance of someone doing the diff and sending me the three files or tell me where to find patch?

Do you want me to limit the tests to just stretch_blit, or include masked_stretch or (dare I say it) draw_sprite?

Will any of the pivot/rotate stretch blits be affected by the changes?

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Evert
Member #794
November 2000
avatar

Quote:

However, I don't have any CVS tools, any chance of someone doing the diff and sending me the three files or tell me where to find patch?

I found http://gnuwin32.sourceforge.net/packages/patch.htm. You can also get http://unxutils.sourceforge.net/ for more useful utilities, like diff, grep, sed and awk.

Quote:

Do you want me to limit the tests to just stretch_blit, or include masked_stretch or (dare I say it) draw_sprite?

stretch_blit and masked_stretch_blit (or stretch_sprite). draw_sprite() is not affected by this patch so it's quite pointless to test anything with that.
Also check if the test programme lists `stretch blit' and `masked stretch blit' as hardware accelerated functions.

A J
Member #3,025
December 2002
avatar

thanks to everyone for doing this, its fantastic !

trivia: this thread, appears in google, i was looking for something else, and this thread was top of the google results!

I've been looking into whether the IDirectDrawSurface2_Blt() can accept a alpha channel value.

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

Thomas Harte
Member #33
April 2000
avatar

Quote:

Will any of the pivot/rotate stretch blits be affected by the changes?

Not by the current patches, but DirectDraw has the capability to accelerate this if the driver implements it. Certainly during the "classic" period of DirectDraw this was very rare, but perhaps things have changed now. I wouldn't be too surprised if modern DirectDraw isn't some sort of Microsoft generic implementation that utilises DirectGraphics, which should mean that rotation is there.

If no-one else does, I'll see if I can knock anything up for rotation/pivot/etc tomorrow.

Quote:

I've been looking into whether the IDirectDrawSurface2_Blt() can accept a alpha channel value.

Blt (and BltFast) certainly can't, I'm not sure if anything else exists that can which would not be too difficult to add into the existing code.

Neil Walker
Member #210
April 2000
avatar

I just thought if the code for stretch_blit was being changed then maybe pivot/rotate stretch might call the same code and may be affected somehow.

Anyway, I get an error running patch. I'm using the standard 4.2 allegro source code. I get the following error:

Quote:

D:\DATA\allegro>patch -p0 < dx_stretch_blit.diff
patching file src/win/wddaccel.c
Assertion failed: hunk, file ../patch-2.5.9-src/patch.c, line 340

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

D:\DATA\allegro>

I'll see if I can work out from the diff what the actual changes are and make them manually unless someone is reading this and responds sharpish :)

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Evert
Member #794
November 2000
avatar

Zip with modified files attached [for 4.2].



Go to: