News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

GDI Vertical blank and vertical retrace test

Started by Siekmanski, April 16, 2018, 11:04:05 AM

Previous topic - Next topic

Siekmanski

This is a nice challenge, but if we will succeed?....  ::)
Creative coders use backward thinking techniques as a strategy.

avcaballero

Well, the important thing about the road is not to cross it, but to enjoy the landscape. When we get tired we can always take another path, but we will surely have learned something :t

jj2007

Excuse my ignorance: How do you synchronise with the VBI? I see you are not using the D3DKMTWaitForVerticalBlankEvent function (see johnsa's Vertical Retrace Sync with GDI/Win32 post).

avcaballero

In what I have seen, "D3DKMT_WAITFORVERTICALBLANKEVENT" sounds to directx

daydreamer

Wouldn't it be better to stress test gdi with a scrolling background +lots of moving enemies ala # of enemies like space invaders,each having its bitblt?
Now I got curious how lord adef solves it,with how many bitblt /frame do he needs in his game?what fps do you achieve?
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

Siekmanski

Quote from: jj2007 on April 29, 2018, 03:52:22 AM
Excuse my ignorance: How do you synchronise with the VBI? I see you are not using the D3DKMTWaitForVerticalBlankEvent function (see johnsa's Vertical Retrace Sync with GDI/Win32 post).

D3DKMTWaitForVerticalBlankEvent has some side effect as you can read in johnsa's Vertical Retrace Sync with GDI/Win32 thread.

Alfonso,
D3DKMTWaitForVerticalBlankEvent you can find in the gdi32.dll ( it's not available in the masm32 gdi32.lib )

I'm setting up a fake video device ( tricky but it works ) to get to the interface that gives me access to the Video/Monitor rasterizer.
First I get the monitor refresh rate from GetDeviceCaps then create a timer thread with the SystemClock interface and set up a one-shot advise request for the reference time at slightly less then the monitor refresh rate.
Then I continuously poll the signal till it enters the Vertical blank, and start the one-shot advise timer again.
From now on I'm sure I don't poll more then necessary and we don't drift away out of the vertical blank period. ( it's only +/- 0.5 milliseconds long )
On my machine it has +/- 10 microseconds accuracy and not too much cpu workload.

The only thing ( I think, not 100% sure) is not to wake up the GDI event queue when we dont want it to take over the drawing management from us.
And another thing, not every video card behaves the same as other cards......
I miss the old Amiga days, perfect 50 Hz on all machines, no stutter at all.  :eusa_boohoo:
Creative coders use backward thinking techniques as a strategy.

jj2007

Quote from: Siekmanski on April 29, 2018, 07:44:07 AMD3DKMTWaitForVerticalBlankEvent you can find in the gdi32.dll ( it's not available in the masm32 gdi32.lib )

If you can't find it there, check d3d10core.dll

avcaballero

Just an jotting on this subject, an interesting msdn article comparing GDI and D2D. I haven't read it in its entirity (... well, just a few...  :biggrin:)

An interesting paragraph:
Quote
Direct2D and GDI are both 2D immediate-mode rendering APIs and are hardware accelerated
Quote
Rendering method
In order to maintain compatibility, GDI performs a large part of its rendering to aperture memory using the CPU. In contrast, Direct2D translates its APIs calls into Direct3D primitives and drawing operations. The result is then rendered on the GPU. Some of GDI's rendering is performed on the GPU when the aperture memory is copied to the video memory surface representing the GDI window.
Quote
Availability of Hardware Acceleration
GDI is hardware accelerated on Windows XP, and accelerated on Windows 7 when the Desktop Window Manager is running and a WDDM 1.1 driver is in use. Direct2D is hardware accelerated on almost any WDDM driver and whether or not DWM is in use. On Vista, GDI will always render on the CPU.

Siekmanski

After reading this article, it makes clear GDI acceleration is different per operating system.
And what about different handling in the blit functions between Sytem and Video memory......
Aplha Blending and Transparency same story.
A bit of a bummer, because you can create many effects with it.
Maybe we can do the alpha stuff preparing in software, have to check this first. ( new challenge  :biggrin:)
As long as the blit operations are accelerated we can still create nice games with it.

So prepare for testing code to check different operating systems.
As an experiment I'll write a jpg/png/bmp image loader for GDI which can handle and prepare alpha channels.
Just curious how it acts with the GDI blit operations without using the GDI Alpha Blending and Transparency functions.

Do you guys have experience with alpha blending in GDI?
Creative coders use backward thinking techniques as a strategy.

avcaballero

Except anyone demonstrate me how to use alpha blending in GDI I think there is no such capability in GDI, except that you can do it by yourself, sure, that's the beauty of GDI :lol:. In fact, in GDI, alpha color has to be = 0, otherwise you will get error.

Attached a tinyc example.
1. First you have to rename it from "zip" to "7z", its real extension
2. unzip its contents to a folder, executable and bmp image

daydreamer

Quote from: Siekmanski on April 29, 2018, 08:27:43 PM
Do you guys have experience with alpha blending in GDI?
does GDI support .dds file format or maybe write one and make use of dx9 sdk texture tool, that can import different file formats and you can choose one image file as alpha channel, and export as ARGB 32bit .dds format
it worked with d3d9 texture,but havent tested with GDI
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

Siekmanski

Hi Alfonso,
I see just with BitBlt, exactly what I hoped for, Direct3D9 handles the colors the same way.
Piece of a cake, we don't need the later GDI alpha functions.  :t

Hi Magnus,
We are going to do that ourselfs with pixel manipulation.
Creative coders use backward thinking techniques as a strategy.

Siekmanski

Implemented 2 switching backbuffers in video memory. ( leaves us with more processing time for the routines )
Blitting to the window and clearing the backbuffers are done simultaneously in the background by the timer thread.

Implemented movement control in fragments of pixels.

In the attachment are 2 examples.
One of them closes all open windows at startup and opens them again when done.

See if the stutter control is improved or not.....
Think this is the closest we can get for stutter free GDI.

Please let me know if the stutters are reduced or gone.  :t
Creative coders use backward thinking techniques as a strategy.

LordAdef

Hi Marinus,

Both are still stuttering here for me. Have you tried without the stretch blt?

Siekmanski

Hi Alex,

Yes, I used all blit methods, they all execute within the vertical blank.
If the operating system has no heavy tasks to run it scrolls very smooth without stutters.
But when it starts up doing something the stutters begin.
The timer thread runs in realtime priority and stays steady.
It must have something to do with how GDI renders/blits stuff in the background, priorities queueing, I don't know.  :(
I'm out of ideas to get it better.
On my machine it runs 90% of the time smooth but now and then periods of those nasty stutters appear.
Sometimes it runs smooth without stutters for 30 minutes.  ::)
Creative coders use backward thinking techniques as a strategy.