B3D game that worked fine a year ago now running at 5 FPS

Started by Randall_Flagg, January 08, 2025, 21:24:28

Previous topic - Next topic

Randall_Flagg

Hi All.

First time poster on forum but long time B3D user.

I wrote a game a couple of years back that worked at 60 FPS no issues but when I tried it the other day, it was running it 5 FPS.

After some investigation, I found that it was drawing an image to a texture that was slowing the game down.

Essentially its a 2D game but instead of drawing onto the screen, I draw the game screen onto a texture and then use the texture on a 3D sprite and set up the camera so that it just shows the sprite and looks like a 2D game. Advantage of this is more GFX power in 3D mode (in this case 60 FPS compared to 30 FPS in 2D mode) and also auto scaling when the window size in changed.

When I update the screen graphics, I set the screen texture into a texture buffer, I draw a background image onto the texture using "drawimage" and then the game graphics are drawn on top of the image.

This worked fine at 60 FPS but for some reason now it doesn't. If I disable the drawimage part, the rest of the game graphics draw fine and back up to 60 FPS.

Is this likely to be an effect of B3D using DX7?

Coder Apprentice

If it was running 60fps before then the first thing I would try is to compile it with one of the current version of Blitz3D. Try the latest first v1.118. You can download it from itch.

https://blitzresearch.itch.io/blitz3d

Dabz

It's pretty much a question with too many open ends to go "Thats the issue"

What OS did you last run it on, and is it the same? Have you reinstalled drivers, is it even the same GFX driver/card. If your using a dedicated GFX card, and have an integrated setup too, what is it like using that, can you test it on another machine?

DirectX7 is really old now, so, no surprise if it's starting to wobble, even now MS are implementing a mapping layer for DirectX9 in the form of a DDI (Device Driver Interface called D3D9on12) for use with DirectX9 which takes the lift from driver support from the hardware to picking up on DX9 related calls and passing them to DX12 instead. You still need the runtimes, but overall, this means DX9 should solidly last another 20 odd years.

I havent got a clue with how DirectX 7 is actually looked at nowadays within modern graphics tech, but one thing is for sure, I wouldnt rely on it being robust anymore.

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Coder Apprentice

#3
Interestingly Blitz3D with its DX7 engine is less problematic than DX9 apps as you don't have to install anything. Before Mark removed the network code it was asking for directplay and the install was one click away as windows offered to install it right on the spot. Blitz3D is actually pretty stable on both Windows 10 and 11. I ran lots of tests recently and never had an issue. Played through Madjack's Tank Universal (B3D version) Demo a few times on one of my low end Win11 laptop without any problem.

The "only issue" besides the well known lack of modern features, that performance doesn't scale as well as DX9/OpenGL 2 and up engines that can fully rely on shaders. The way d3d7 is currently running on modern systems is that all the geometry processing is done on the CPU and it won't scale with GPU at all. However all the rest of the DX7 pipeline including texture processing is GPU accelerated. If you run lots of calculation in your game logic that is heavy on floating point calculations can reduce how much geometry you can process with good frame rates. Thankfully even low end CPUs are pretty fast nowadays so if you don't want poly heavy scenes you'll be fine. Advantages of more modern engines are obvious so I think whoever develops with old vanilla DX7 Blitz3D has to know the limits. But it runs on pretty much anything from WinXP to Win11, and there is also a separate version for Win98/95. From this perspective it's a pretty unique dev tool.

Randall_Flagg

#4
Quote from: Coder Apprentice on January 08, 2025, 22:19:45If it was running 60fps before then the first thing I would try is to compile it with one of the current version of Blitz3D. Try the latest first v1.118. You can download it from itch.

https://blitzresearch.itch.io/blitz3d
Hi, Yes have tried compiling it on the latest Blitz3D and also Blitz3D-NG and get the same result every time.

Quote from: Dabz on January 09, 2025, 06:05:36It's pretty much a question with too many open ends to go "Thats the issue"

What OS did you last run it on, and is it the same? Have you reinstalled drivers, is it even the same GFX driver/card. If your using a dedicated GFX card, and have an integrated setup too, what is it like using that, can you test it on another machine?

DirectX7 is really old now, so, no surprise if it's starting to wobble, even now MS are implementing a mapping layer for DirectX9 in the form of a DDI (Device Driver Interface called D3D9on12) for use with DirectX9 which takes the lift from driver support from the hardware to picking up on DX9 related calls and passing them to DX12 instead. You still need the runtimes, but overall, this means DX9 should solidly last another 20 odd years.

I havent got a clue with how DirectX 7 is actually looked at nowadays within modern graphics tech, but one thing is for sure, I wouldnt rely on it being robust anymore.

Dabz
I do have different hardware now. Have changed laptops since it was written. I can get some mates to download and try it and see if they get the same result on their hardware.

If anyone wants a look, there's a download link here. Game_Download_Link

If you play a game without Bezel and backdrop, it runs at 60 FPS. If you try a game with Bezel and Backdrop enabled, slow mo!

Coder Apprentice

If you could post some code that produces the same low frame rate would be cool. 

Randall_Flagg

graphics3d 1024,1024,32,2

setbuffer backbuffer()


screen_sprite=createsprite()

scalesprite screensprite,1024,1024

screen_texture=createtexture(1024,1024)

camera=createcamera()

cameraprojmode camera,2

camerazoom camera,0.0001 ; Zoom value may need adjusting

positionentity camera,0,0,-10

bezel_bg=loadimage("any_image_1024_by_1024.png") ; It seems that this can be any image including black screen. Also happens with smaller images.


while not keyhit(1)

setbuffer texturebuffer(screen_texture)

cls

drawimage bezel_bg,0,0 ; This is what slows everything down. Drawing an image to a texture.

; Draw game graphics on top of the image here.

setbuffer backbuffer()

entitytexture screen_sprite,screen_texture

renderworld

flip

wend

This is the basic code for the graphics display

RemiD

you can also use copyrect() instead of drawimage() to copy the texels of the image to the texture...
maybe it is faster...

or you can directly draw2d / render3d on the backbuffer and then use copyrect() to copy the texels of the backbuffer to the texture.

Coder Apprentice

#8
As Remi said you should use CopyRect. Check your Blitz3d folder -> samples->mak->tex_render which is a "render to texture" example.

Randall_Flagg

#9
Quote from: RemiD on January 09, 2025, 09:42:21you can also use copyrect() instead of drawimage() to copy the texels of the image to the texture...
maybe it is faster...

or you can directly draw2d / render3d on the backbuffer and then use copyrect() to copy the texels of the backbuffer to the texture.
Quote from: Coder Apprentice on January 09, 2025, 10:16:44As Remi said you should use CopyRect. Check your Blitz3d folder -> samples->mak->tex_render which is a "render to texture" example.


Great! thanks for the valuable advice. I will try this later.

Edit: Just tried using copyrect and works perfectly. Thank you all!