The MASM Forum

Miscellaneous => Miscellaneous Projects => Topic started by: mikorians on October 19, 2012, 03:29:02 AM

Title: Seeking friendly collaborator
Post by: mikorians on October 19, 2012, 03:29:02 AM
Maybe I've been closed in my hospital room too much and just do not understand the way normal people think.

I've been trying to get someone to spend a little spare time (not every living moment) helping me to upgrade my
application in siome way so that I can finish off an item that has been on my bucket list for 30 years now.
I offer people a little friendly incentive money and everyone grows quiet.  I just want to be fair and pay people what their time is worth...
I'm not asking for a major commitment because I know how little $200/month means to people in professional fields-- it's like--- nothing.
I have no connections, and no friends, no facebook, no twitter - I never bought into any of those because I thought they were kinda silly.

I cannot grasp why in these troubling times nobody feels that the money I'm offering is not worth a couple of hours a week helping finish a project
that is 3D ---  fun, fulfilling, interesting, beneficial to both of us as well as the rest of the whole world --- this isn't a commercial venture - it's open source.
They'd be doing what they're already seemingly willing to do for free-- helping people on these boards...
I just have no connection and no hope.

Why?
Title: Re: Seeking friendly collaborator - why do people go silent?
Post by: caballero on October 19, 2012, 03:54:25 AM
Your message sounds a bit negative, isn't it? Maybe you should explain a bit what your project is about and maybe people will start to feel interested. As far as I'm concerned, I have no time for another project, sorry. But I must say that anyone who has posted something on the Internet feels anything like as if he had thrown it into the void...
Title: Re: Seeking friendly collaborator - why do people go silent?
Post by: mikorians on October 19, 2012, 04:11:17 AM
You're absolutely right.  It does sound negative, doesn't it.  Desperation does this to people.
I'm sorry.  I don't mean to come off as all negative.

Positive swing now---
It really is a great old engine and it is actually finished and potentially quite educational.
It has test levels, and inventory and icon system, and it plays okay.  It has many features which I have found enjoyable.
If a programmer enjoys his own program, then it must be at least somewhat fun to play, yes?
It has a carnival with sky umbrellas, a merry-go-round, tube slides, some pretty good soothing music.
It is designed to be a therapeutic and relaxingly entertaining program.

All it needs is a little tender-loving-care to make it run a bit faster - perhaps not much at all.
It really needs someone familiar with Visual Basic 6 to just browse over it and become familiar with the reasons why it was made the way it was,
and then we could focus on ways to make it run faster and work better within those parameters.
The x-files themselves are probably are where some of the greatest improvements could be made since I've learned a lot from a friendly Russian fellow lately.
So you can see that I already have a few good ideas for optimization already.
How hard could it be, yes?  It would at least be interesting conversation.  Isn't that worth a little money?  I mean, I know you can't just buy friendship, but it helps, hmmm?
Title: Re: Seeking friendly collaborator - why do people go silent?
Post by: dedndave on October 19, 2012, 04:12:16 AM
i would probably help if i were a bit more qualified   :t
others have different reasons, of course
but we aren't all "3D graphics gurus", either   :P
Title: Re: Seeking friendly collaborator - why do people go silent?
Post by: mikorians on October 19, 2012, 04:24:04 AM
Who says you're not qualified dave?

I wasn't qualified when I started either.  Remember this took 30 years.
My price was time instead of money.
These games are expensive to make commercially...   As you know.
Do you know VB6 or VB7?  Even if you don't but can interface with it, then there's a possibility.
Do you have the time?  I would like to get 2 hours a week in on this so I'd know progress was being made.  I think that's fair enough.
You also have some familiarity with MASM32 or you wouldn't be here?
I want to post this thing, but I am embarrassed to do so in its present state.  So private communication.
I need a 1-on-1 thing going because you can't post over 512K here, so it would have to be email.
Title: Re: Seeking friendly collaborator
Post by: dedndave on October 19, 2012, 04:41:00 AM
i don't use VB or C at all, really
i can generally read those languages well enough to learn what i want

i can't see charging you money for learning how to do stuff - lol
i have a little intrest in 3D graphics - but it's not high on my priority list, at the moment

Farabi seems to write some pretty fast stuff
maybe you could get a little direction from him
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 19, 2012, 04:48:35 AM
Folks pay tuition, and what I learn will be the right way to do all of this.
I'm an old fart, and youngsters pick up stuff so fast I can't believe it.

Now see-- You're right.  3D isn't high on your priority list, but maybe some of the things you'd be able to do with the extra money are.
You simply have to gauge which is more important to yourself.

Now this Farabi... isn't here.  You are.
What would be the proper protocol for me to contact him/her?

I need a sounding board and a friend.  Only the work is 2 hours a week.
Tell me about some of the most complex things you've written.  I'll bet you'd wow me.
My focus is very narrow, so I'm good at just this one thing.
Title: Re: Seeking friendly collaborator
Post by: dedndave on October 19, 2012, 04:59:54 AM
Onan Farabi is one of our forum members that enjoys 3D graphics and game development
you can send him a PM - or just wait a day or so and he'll probably post in this thread

as for me...
i am also an old fart - lol
i wrote a lot of assembler code back in the 16-bit days
and - i have written assembler for a number of different processors and microcontrollers

as for win32 code, i am still a bit of a newbie
i spent a couple years just playing with console-mode programs to learn the "behind the scenes" stuff
and in the last year or so, i have started to play with windows GUI apps
i am just learning to properly apply GDI code at the moment
once i have a handle on that, i want to spend some time learning the SSE instruction sets
i also want to spend more time with COM development and macros - both of which i am weak on

i think Farabi uses OpenGL, in preference to DirectX
when i get to the point where i want to do some 3D code, i will probably follow that same path
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 19, 2012, 05:09:18 AM
Nice to meet ya!
I have played both Blood and DukeNuke'm 3D and been jealous of the graphics they got away with back then.
My engine isn't as fast.
I have proffered DirectX over OpenGL because, believe it or not, I found it unpredictable or unsuitable for my purposes.  'nuf said.
I'm waffling between Directx6,8, and 9 because of various things I've heard and done.
I'm dreading a re-write - but that's what 6 or 9 means.
I wrote in 8, and the Russian guy has provided me with some eye-opening stuff with is DX_VB.DLL for DX9 that allows Visual Basic 6 to access DirectX9.
My performance increase in a test application went from 7FPS to 50FPS.
On the other hand, the wise old ones on this site have spoken, and they said I might want to go back to versions of DirectX that are less cluttered than 8 and 9.
I must benchtest these versions now as well, but the docs and API's for them would be very hard to find...
Title: Re: Seeking friendly collaborator
Post by: Tedd on October 20, 2012, 02:42:48 AM
Stop offering money as an incentive - it makes most people feel uncomfortable, as it would appear they're only replying to take your money. Members provide their assistance and expertise on this forum for free, out of interest and through choice. If you start waving money around, all you will attract is people who want your money for the minimum effort; while what you want is someone to work on a project with you because they also have an interest in that project - which is the same reason you are working on it.

I would recommend looking at SDL (www.libsdl.org (http://www.libsdl.org)) as an option, instead of worrying about DirectX v OpenGL, and version hell - you will still get access via these libraries anyway, but with a simpler interface and some nice additions.

Also, I know you won't like this idea, but you will benefit from re-writing in a complied language. It may seem like a lot of extra work when you already have working code - and it is - but consider how much extra time you're going to be spending trying to squeeze out more speed. I expect a large amount of it will end up being straightforward rewriting (a little boring, but not difficult) into the target language. It will also give you the opportunity to re-examine the structure and find more efficient methods you hadn't previously considered.
Title: Re: Seeking friendly collaborator
Post by: MichaelW on October 20, 2012, 03:15:24 AM
mikorians.

Have you considered switching from VB to  FreeBASIC (http://www.freebasic.net/forum/). By default the FreeBASIC compiler outputs Intel-syntax  GAS (http://en.wikipedia.org/wiki/GNU_Assembler) assembly, and supports the same syntax in inline assembly. And it supports “naked” procedures with no prologue or epilog code, so you can create assembly-code procedures with a minimal call overhead directly in your source. And while the GAS macro system is very different from the MASM macro system, and much less powerful, the Intel syntax was developed from the published MASM 6.0 grammar, so the assembly syntax is close to that of MASM.


Title: Re: Seeking friendly collaborator
Post by: mikorians on October 20, 2012, 03:34:45 AM
I've been running around in a spin trying to pick a direction to go in...  I've gotta be careful.

Tedd, thank you very much for the tips, and I will keep them all in mind from now on.
SDL sounds pretty major, but I'm trying to keep an open mind.  I don't know it I have the skill to implement that though since I'm completely unfamilliar with C.  I will examine it, however, to see if I can reach it at all with VB... [update]  No.  I don't want OpenGL.

MichaelW, FreeBASIC sounds more up my alley.  But I've also seen really great results from BlitzBasic, but it lacks API access and is too proprietary.
But how does FreeBASIC fare with DirectX access?  Is there a code library available?  I will investigate. [update] Q:I would LOVE to go back to QBasic.  Any DirectX examples?

So... Question: How does my GPU's vertex fill rate compare to real-world polygons/second?
I have now benchtested DirectX7 vs. DirectX8 and 9 as Hutch suggested.
There didn't seem to be much of a difference.  It's hard to calculate because it seems that actual triangle size matters a great deal...
My formula was to reduce the fill rate 67.5M verts/sec down to 450K faces/50th sec.
My current program pulls 140K faces/50th sec.
Title: Re: Seeking friendly collaborator
Post by: MichaelW on October 20, 2012, 03:56:09 AM
Quote
But how does FreeBASIC fare with DirectX access?

The FreeBASIC GfxLib uses DirectX by default, but this is for QuickBASIC-style graphics. I’m not into 3D so I don’t pay much attention to what people are doing with it. I do know that there are several 3D projects going, but I don’t know if they are using DirectX or OpenGL, or some library like SDL.


Title: Re: Seeking friendly collaborator
Post by: ToutEnMasm on October 20, 2012, 06:20:22 AM

Quote
Any DirectX examples ?
I have done some in masm.I can help you going this way for free.
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 20, 2012, 07:42:05 AM
 :dazzled:  Wow, that would be great if we could collaborate.
How are you at understanding the dll type link to Visual Basic 6?  Doesn't matter too much if you're thinking of a rewite.
I've learned that I've got to be flexible here.  Do you know FreeBasic?  I just got it and it looks interesting also - has tighter links to Asm.
We need to make this old engine scream!
Anybody know how I can tell if I've maxed out my GPU's performance?
Title: Re: Seeking friendly collaborator
Post by: ToutEnMasm on October 20, 2012, 06:33:29 PM
Quote
I've learned that I've got to be flexible here.  Do you know FreeBasic?  I just got it and it looks interesting also - has tighter links to Asm.
I was a user of the qbasic who was great in his time (who is past).I have no problem with other basic.I have used the microsoft one ,visual studio 6.
I have downloded the freebasic and play a little with it.
No problem at all with basic.
Title: Re: Seeking friendly collaborator
Post by: MichaelW on October 20, 2012, 07:36:31 PM
The FreeBASIC 0.24.0 Win32 release includes a DX9 example, d3d9_primitives.bas, in FreeBASIC\examples\win32. The source built without problems, and after I installed the end-user runtime, found the most recent DLL included, D3DX9_43.dll, copied it to my working directory and renamed it to D3DX9d.dll to match the name in the import library libd3dx9d.dll.a, it ran OK, displaying a rotating and zooming multi-color pyramid in a very normal API window.

The attachment contains the assembly output of the compiler.

Edit: The EXE triggers an access violation exception when I close it, on both of my systems, and I don't have time to run the problem down.

Edit2: The problem occurs only when the app is using the DLL in the current directory. When I move the DLL to the System32 directory then there is no problem.

Title: Re: Seeking friendly collaborator
Post by: MichaelW on October 20, 2012, 08:07:29 PM
You asked about a DLL interface with VB. The attachment contains everything that I have for a test that I did 6-7 years ago. I recall testing it and it working correctly, but I’m not sure if I tested with VB5 or VB6, I cannot find the VB source that I used, and I cannot recall if I used run-time dynamic linking or used the import library and load-time dynamic linking.
Title: Re: Seeking friendly collaborator
Post by: ToutEnMasm on October 21, 2012, 01:16:05 AM

There is further free basic to download
http://sourceforge.net/projects/fbc/files/
and there is also Just Basic
http://justbasic.com/download.html (http://justbasic.com/download.html)
Title: Re: Seeking friendly collaborator
Post by: ToutEnMasm on October 21, 2012, 03:35:21 AM
Quote
Edit: The EXE triggers an access violation exception when I close it, on both of my systems, and I don't have time to run the problem down.
Same thing for me when running outside the IDE (XP3).
Title: Re: Seeking friendly collaborator
Post by: jj2007 on October 21, 2012, 04:03:39 AM
You asked about a DLL interface with VB.

I add my version calling a DLL from a VB for Ms Word macro.
When I wrote this some time ago, the main problem was convincing VB that the calling convention was OK, by returning a specific value in esi. I have no idea if standalone VB shows the same idiosyncratic behaviour - see MasmBasicInsertStruct.bas in case you want to test it.

The macro takes a selected string content, e.g. SMALL_RECT, passes it on to a MasmBasic DLL, which looks up the struct in Windows.inc and writes it into a buffer supplied by the macro. The macro then replaces the selected text with the whole structure definition.

In case there is no Windows.inc, MasmBasic's Recall  (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1158)throws a runtime error, i.e. a MsgBox saying file not found; the DLL then passes back an error code that results in VB saying "bad calling convention".

There are three macros inside, two simple ones for testing and the more interesting InsertStruct macro. The latter uses SSE2 code which may not run on your machine.

In the testing phase, when I had not yet discovered that trick, Ms Word used to crash if an error happened in the DLL. If you intend to roll your own, be warned that these crashes are nasty. You lose immediately any open documents, and have to restart Ms Word.

Title: Re: Seeking friendly collaborator
Post by: mikorians on October 22, 2012, 12:32:14 AM
 :dazzled: Whoa, didn't see the second page of posts here !!!
I gotta catch up!  I will analyze all of your generous data!

Complex question (I guess for all of us)
Does anybody have a vertex-buffer-based example of skin mesh loading and proper hierarchy matrix walking.
All my engine did was use the built-in mesh loader in DX8 (it's reeeeaally slow)
This would finish up what I had, but I also had no LOD using Progressive meshes -- new thing I learned about only recently
- didn't think I would need it until now.

[update]
jj I can't make any of the masmbasic stuff work right, and I have no idea what msword basic is.   :greensml:
Justbasic seemed a little too basic to handle directx very well.

In FreeBasic I got pretty good throughput with a 2d example I tested and got like 100-200K fps, so it seems to be real tight asm compilation
Right now I am not running d3d9 in debug mode, so I couldn't run the .exe of the test d3d9primitives --  I really really wanted to though..  :badgrin:

[update2]
In all honesty, I do kindof understand matrix hierarchy walking, it's just that...  My prog says the x-file data has 3 matrices affecting each joint, and I'm not sure I understand why there are 3.  I had used the standard x-file mesh loader (it's reeeeally slow).  So here's an example of a skin mesh.  I only use skin weights of 1.0, so there's no funny stuff.  Note the shortcut used on material (means all verts), and the lack of vertex weights on the root bone.  This is quite standard in skin mesh files since these represent offset matrices and make the joints work right.  Here's a simple sample:

BTW: If any of you use 3ds max 5, I have a limpy little .x file importer maxscript that I've written recently to bring 'em back in after post-processing texture coordinates for sprite sheets.  It's kinda cool...

[update3]
d3dx9d.dll is not for my version of windows.  This is my medical computer running windows 98.  I cannot change the operating system.  Anybody got the .bi files for dx8?
I noted it seems to support DirectX7, this would be equitable if it can be done - it's the same, isn't it?  Dx8 Dx7...?  Skinning, Fog?
Title: Re: Seeking friendly collaborator
Post by: jj2007 on October 22, 2012, 02:46:34 AM
jj I can't make any of the masmbasic stuff work right, and I have no idea what msword basic is

Most MasmBasic algos won't work on your machine because it uses SSE2. MS Word Basic is what you see when you press Alt F11 in Microsoft Word - Visual Basic for applications. There are three macros in MasmBasicInsertStruct.bas, and the first two should work even on your machine. The whole mb2vb folder is a proof of concept showing that it is indeed possible to call assembler from Visual Basic.
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 22, 2012, 03:58:49 AM
OK.  Let us remember how slow I am (or can be, heh  :icon_rolleyes:).
I don't typically install excess packages on this old beastie.
I do not have Microsoft Word.
I have wordpad.
I have visual basic 6.
It is interesting that it's possible to run Asm within VB6.
I must first aquire the necessary VB equivilants before I can even try to translate them to Asm function calls.
I am just now trying to convert my old meshloader functions into vertex buffer calls.
The engine I have was finished, but not in an efficient manner apparently, so I have to play catch up now.
I do understand and have routines that were well written by the russian to use vertex buffers with static meshes, but not with skinned meshes.
These routines are in Visual Basic though, and I am now pointing myself more towards using FreeBasic because it looks faster---
unless you would recommend a different approach that would let me keep most of my engine in Visual Basic.

This old wounded soldier needs sound advice real soon.
Title: Re: Seeking friendly collaborator
Post by: ToutEnMasm on October 22, 2012, 04:06:53 AM
Quote
These routines are in Visual Basic though, and I am now pointing myself more towards using FreeBasic because it looks faster---
Bad choice.
After some tests,the freebasic is bugged and couldn't be used.
If you are an old machine, only an ide using the sdk could made it work.
other soluce is to use an old ide,if he want to work an actual system.
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 22, 2012, 04:09:05 AM
Anybody disagree with ToutEnMasm?  You've all been so helpful.  I am aquiver.   :greenclp: :greenclp: :greenclp:
So stick with VB6 and try to get in-line assy work?
Or Masm32 dll?
I did note that freebasic had dx7 and dx8 libraries... But no, eh?
Title: Re: Seeking friendly collaborator
Post by: ToutEnMasm on October 22, 2012, 04:17:50 AM

The good thing is that i have study the freebasic code and that  i know the c++ code.
The c++ code is the reference and the freebasic code is very near it.
The freebasic had no other choice than copy the c++ one.
It is your chance,use the vc ++ and you are certain to reach the goal.
I can help you doing that.
Title: Re: Seeking friendly collaborator
Post by: jj2007 on October 22, 2012, 04:18:53 AM
Bad choice.
After some tests,the freebasic is bugged and couldn't be used.

Please show us some examples of FreeBasic bugs, Yves.
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 22, 2012, 04:23:56 AM
I know I can't run the pseudo dx9 code they provided.  It's directx10.
Personal peve - C - can't use it myself.  Now if someone wants to make a library I can call to from VB, that's fine, but...  Well...  It would be almost overly generous...
My engine was very generic on purpose because I wanted to use the various switches to obtain certain effects.
Other callable applications like TrueVision3D and BlitzBasic --- while absolutely wonderful (don't get me wrong), were also quite proprietary and not modifiable.
My needs can be very specific.  Like translatable texture mapping, for example.  Neither of those apps support it correctly.
I got DevC++ to run, but it might as well be alien gibberish to me.  I could at least read freebasic.  Asm would be difficult, but something I'd learn if I had to make small changes to an existing code library.
Title: Re: Seeking friendly collaborator
Post by: ToutEnMasm on October 22, 2012, 04:31:34 AM
Quote
Please show us some examples of FreeBasic bugs, Yves.
read the post of michaelw and myself.
:\Program Files\FreeBASIC\examples\win32\d3d9_primitives.exe
Just crash when exit outside the ide,run it with a shortcut.
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 22, 2012, 04:33:54 AM
I think what we need to reach common ground with FreeBasic would be an example of Dx7 or Dx8 usage.  Dx9 is really Dx10 in FB.
Hutch advised that older versions run faster on older machines.
Besides, it has viable vb6 dll examples...

Other esoteric features my engine uses...
ForceFeedback
DirectShow - for intermission scenes - like avi, mp3.  Works well enough in DX8.
Use of material alpha channel for object translucency.
Title: Re: Seeking friendly collaborator
Post by: ToutEnMasm on October 22, 2012, 04:45:43 AM
Quote
I think what we need to reach common ground with FreeBasic would be an example of Dx7 or Dx8 usage.  Dx9 is really Dx10 in FB.
Dx10 is for WIN7.
i have the dx 9.C and he is in use with most of the game.
Have you tested the freebasic dx sample of wich I speak.
if just a crash satisfy you ....
 
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 22, 2012, 04:50:15 AM
Yeah...  Compiles, but cannot run it "DLL missing".  Downloaded dll.  Run program. "DLL is not for your version of windows"
But look in the include\win folder.  D3D.bi
Title: Re: Seeking friendly collaborator
Post by: ToutEnMasm on October 22, 2012, 05:00:34 AM
Quote
"DLL is not for your version of windows"
You need the directx sdk,x version
If  it say you, d3dx9d.dll is missing ,made this:
in windows\system32 directorie search (dir d3dx9d*.dll) for d3dx9d*.dll
You wil find some:
Quote
02/06/2010  14:23         2 261 336 d3dx9d.dll         ;don't exist
02/06/2010  14:23         3 795 800 d3dx9d_33.dll
02/06/2010  14:23         2 261 336 D3dx9d_43.dll
then:
copy d3dx9d_nn.dll d3dx9d.dll

And all is good.
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 22, 2012, 05:26:10 AM
Sigh...  Older DX version would be better...
[Update] Yeah.  Above dx9 sample's no good because the library file refers to dx10.
I copied the relevant files you suggested, and if just says I need a newer version of windows, contact my vendor.
Title: Re: Seeking friendly collaborator
Post by: MichaelW on October 22, 2012, 06:10:52 AM
I have not had much time to look at any of this but it looks like the FreeBASIC 0.24.0 distribution also includes the D3DX8 components. And given the target DLL, it's possible to create your own import library, with the DLL name tailored to whatever you need. The difficult part is the header files.
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 22, 2012, 08:47:12 AM
That would be good since 8 is what I'm most familiar with.   :greenclp:
I looked at 7, but all I could find in my archives were some examples, but not the all-important help files or sdk.exe   :redface:
Dx7 seems to use a different method to do texture transformations than 8.  Hm...
Title: Re: Seeking friendly collaborator
Post by: MichaelW on October 23, 2012, 04:14:03 PM
I found a DX8.1 VB SDK on one of my hard drives so I installed it and VB6 on my Windows XP SP3 system. The system already had a more recent version of DX installed, but I wanted the SDK for the documentation and sample code. Using MASM and Link I created a DLL that contains an assembly version of one of the functions in the VB D3Dframework utility module, and created a VB6 project to test and time it against the VB function. I made no special effort to optimize the assembly code, so it may be nowhere near the fastest possible. I’m not sure that this is all correct, but it appears to work as expected and I’m out of time to work on it. For the MASM test app I used the import library, but for the VB project only the DLL was required. After trying the project and System32 directories, I determined that the DLL had to be in the VB98 directory. Hopefully I included everything necessary in the attachment.

I used 1000000 loops timing the code so I could get reasonable repeatability on my 3GHz P4 Northwood. For slower systems you may need to reduce the loop count.

Title: Re: Seeking friendly collaborator
Post by: mikorians on October 24, 2012, 01:52:30 PM
Thank you for going through all of the trouble for this old antique.  I haven't yet heard much from the FreeBasic site, though I was wishing to.
It's good to hear from you.
So calling a dll from VB6...  would seem quite worth it --- same function, but much faster.
Granted, it's just a color function, but it is interesting.
How shall we proceed now?
Still dazed...
If you need anything from me, let me know.  I had all the old Dx8 stuff...

[Update]
I looked at the .asm of what you just did.  You're kinder than I thought.  You didn't call the API, you rewrote the function completely.
We'll still need to access the vertex buffer and rendering API (HW accelerator functions) of course.
Probably not too much to be gained there, but with Asm, who can say for sure?
It seems to trim the fat in places one doesn't expect.
On my machine we got 1.81 secs and .059 or something...  So 30x faster.       It read 1.6  .059 when compiled, 27x.
So as you can see on my system, compiled or interpreted, little difference.

[Update 2]
Got a taste on my friends computer (only slightly newer) of something a bit faster.
He had a NVidia 8800gts and a Core2Extreme 2.93mhz (X6800) with XP Pro SP3 on it, and my program runs about 10x faster with no optimization at all...   Wow.
Wish I could use it.  There are cards that are 10x faster than his too.  But we'd all be just throwing money at a problem that should be solved first before hardware IMHO...  Since money's real tight with my bills.
Title: Re: Seeking friendly collaborator
Post by: MichaelW on October 24, 2012, 03:22:53 PM
The attachment here compares the assembly procedure in the DLL to the VB function source as compiled by FreeBASIC. I’m not sure how well (or if) the cycle count macro will work on your older system. Assuming it will work, you will need to reduce the loop count to something that will run in a reasonable time, and you may need to reduce the priority to keep it from crashing Windows.
Title: Re: Seeking friendly collaborator
Post by: jj2007 on October 24, 2012, 04:32:22 PM
Celeron M:
  0 cycles
 62 cycles
 23 cycles


P.S.: No timings for the second function?

Function D3DCOLORVALUETOLONG(ByRef cv As D3DCOLORVALUE) As Long
function D3DCOLORVALUETOLONG_( byref cv as D3DCOLORVALUE ) as integer
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 25, 2012, 04:06:19 AM
Nope.  No crash.  Ran Test.exe--
0
102
42

FB took >twice as long as raw Asm.
And I haven't had much help with the folks on the forum at freebasic regarding DirectX.  They're like, obsessed with OpenGL-
Which I wouldn't personally choose.  I know it's cross-platform, but I tried it many years ago and didn't like it.  Picked standard DirectX for me.  :t
Fixed Test.bas to reflect _ function also...

99
102
42

Simple benchmark acknowledged.
So, remembering the former test...   Raw Asm was...   2.36x faster than FreeBasic and 30x faster than the DirectX DLL on the D3DColorValueToLong function on my machine.  Whoop.  Just noticed you compiled the raw asm in FreeBasic, not Masm32.  Same same, mm?

Which raw DirectX8 graphics functions can we not improve?  Why did someone not make a nice, generic optimized library a long time ago?  Even more modern XP users can still benefit from this technology (just a different DX9/10 label set, yes?)  Let us continue with this function set.

Enjoying this sweet meditation...  Ah...
Title: Re: Seeking friendly collaborator
Post by: MichaelW on October 25, 2012, 12:34:55 PM
Quote
Just noticed you compiled the raw asm in FreeBasic, not Masm32. Same same, mm?

The FreeBASIC app above calls the function in the DLL that was built with MASM. The .asm file included in the attachment is the FreeBASIC compiler output (using the command line fbc -w pedantic -v -C -R  -s console test.bas) , that is assembled with as (aka GAS) to produce an object module, that is then linked with ld (the GNU linker), using a long and complex command line, to produce an EXE.

But I can port the MASM code to a naked function, with only a few changes, and while as may not encode the instructions exactly as MASM would, the assembled code will be functionally equivalent to the code that MASM produces.

Code: [Select]
''===================================================================================
#include "counter.bas"
''===================================================================================
''
'' The newer cycle count macros are available here:
''
''    http://www.freebasic.net/forum/viewtopic.php?f=7&t=20003
''
''===================================================================================

Type D3DCOLORVALUE
    r As Single
    g As Single
    b As Single
    a As Single
End Type

extern "Windows-MS"
Declare Function D3DCOLORVALUETOLONGASM Lib "testdll" (ByRef cv As D3DCOLORVALUE) As Long
end extern

Function D3DCOLORVALUETOLONG(ByRef cv As D3DCOLORVALUE) As Long

    Dim r As Long
    Dim g As Long
    Dim b As Long
    Dim a As Long
    Dim c As Long

    r = cv.r * 255
    g = cv.g * 255
    b = cv.b * 255
    a = cv.a * 255

    If a > 127 Then
        a = a - 128
        c = a * 2 ^ 24 Or &H80000000
        c = c Or r * 2 ^ 16
        c = c Or g * 2 ^ 8
        c = c Or b
    Else
        c = a * 2 ^ 24
        c = c Or r * 2 ^ 16
        c = c Or g * 2 ^ 8
        c = c Or b
    End If

    D3DCOLORVALUETOLONG = c

End Function

function D3DCOLORVALUETOLONG_( byref cv as D3DCOLORVALUE ) as integer

    dim as integer r,g,b,a,c

    r = cv.r * 255
    g = cv.g * 255
    b = cv.b * 255
    a = cv.a * 255

    if a > 127 then
        a -= 128
        c = a * 2 ^ 24 or &H80000000
        c or= r * 2 ^ 16
        c or= g * 2 ^ 8
        c or= b
    else
        c = a * 2 ^ 24
        c or= r * 2 ^ 16
        c or= g * 2 ^ 8
        c or= b
    end if

    return c

End Function

''----------------------------------------------------
'' This is a naked function version of the MASM code.
''----------------------------------------------------

function D3DCOLORVALUETOLONG_NAKED naked( byref cv as D3DCOLORVALUE ) as integer
    asm

        push ebx
        push edi

        mov eax, [esp+12]

        sub esp, 16

        .section .data
            f255: .float 255
        .section .text

        fld DWORD PTR f255

        R = 0
        G = 4
        B = 8
        A = 12

        fld DWORD PTR [eax+R]
        fmul st, st(1)
        fistp DWORD PTR [esp]
        fld DWORD PTR [eax+G]
        fmul st, st(1)
        fistp DWORD PTR [esp+4]
        fld DWORD PTR [eax+B]
        fmul st, st(1)
        fistp DWORD PTR [esp+8]
        fld DWORD PTR [eax+A]
        fmul st, st(1)
        fistp DWORD PTR [esp+12]
        fstp st

        mov ebx, [esp]
        mov ecx, [esp+4]
        mov edx, [esp+8]
        mov edi, [esp+12]

        add esp, 16

        cmp edi, 127
        jna 0f

        sub edi, 128
        shl edi, 24
        or edi, 0x80000000
        mov eax, edi
        shl ebx, 16
        or eax, ebx
        shl ecx, 8
        or eax, ecx
        or eax, edx

        pop edi
        pop ebx
        ret 4

    0:

        shl edi, 24
        mov eax, edi
        shl ebx, 16
        or eax, ebx
        shl ecx, 8
        or eax, ecx
        or eax, edx

        pop edi
        pop ebx
        ret 4

    end asm

End Function

''===================================================================================

dim as D3DCOLORVALUE cv
dim as integer r

cv.r = 0.123
cv.g = 0.234
cv.b = 0.345
cv.a = 0.456

r = D3DCOLORVALUETOLONG( cv )
print hex(r)
r = D3DCOLORVALUETOLONG_( cv )
print hex(r)
r = D3DCOLORVALUETOLONG_NAKED( cv )
print hex(r)
r = D3DCOLORVALUETOLONGASM( cv )
print hex(r)
print

SetProcessAffinityMask( GetCurrentProcess(), 1)

sleep 5000

for i as integer = 1 to 4

    counter_begin( 10000000, REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_TIME_CRITICAL )
    counter_end()
    print counter_cycles;" cycles"

    counter_begin( 10000000, REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_TIME_CRITICAL )
        r = D3DCOLORVALUETOLONG( cv )
    counter_end()
    print counter_cycles;" cycles"

    counter_begin( 10000000, REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_TIME_CRITICAL )
        r = D3DCOLORVALUETOLONG_NAKED( cv )
    counter_end()
    print counter_cycles;" cycles"

    counter_begin( 10000000, REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_TIME_CRITICAL )
        r = D3DCOLORVALUETOLONGASM( cv )
    counter_end()
    print counter_cycles;" cycles"

next

sleep

Running on my P3:
Code: [Select]
741F3C58
741F3C58
741F3C58
741F3C58

 0 cycles
 78 cycles
 31 cycles
 30 cycles
 0 cycles
 78 cycles
 31 cycles
 30 cycles
 0 cycles
 78 cycles
 31 cycles
 30 cycles
 0 cycles
 78 cycles
 31 cycles
 30 cycles

And MASM leads by 1 full cycle.

Title: Re: Seeking friendly collaborator
Post by: mikorians on October 26, 2012, 02:18:16 AM
Feeling overwhelmed today.
Title: Re: Seeking friendly collaborator
Post by: MichaelW on October 26, 2012, 05:37:11 AM
P.S.: No timings for the second function?

Function D3DCOLORVALUETOLONG(ByRef cv As D3DCOLORVALUE) As Long
function D3DCOLORVALUETOLONG_( byref cv as D3DCOLORVALUE ) as integer

I didn’t bother timing it because there should be no significant difference in the compiled code. I was just trying to show the more compact syntax that FreeBASIC allows, compared to VB.
Title: Re: Seeking friendly collaborator
Post by: jj2007 on October 26, 2012, 07:22:46 AM
I was just trying to show the more compact syntax that FreeBASIC allows, compared to VB.

Yeah, FreeBASIC looks nice. What a pity that Masm and JWasm don't understand the syntax :biggrin:

Here is a port to Assembler (full version attached, including one algo using SSE2, and somewhat surprising results for Michael's DLL):

Quote
include \masm32\MasmBasic\MasmBasic.inc   ; download (http://masm32.com/board/index.php?topic=94.0)
include \masm32\macros\timers.asm   ; download from the Masm32 Laboratory (http://masm32.com/board/index.php?topic=49.0)

D3DCOLORVALUETOLONG PROTO pCv:DWORD

D3DCOLORVALUE STRUCT
    r REAL4 ?
    g REAL4 ?
    b REAL4 ?
    a REAL4 ?
D3DCOLORVALUE ENDS

.data
cv   D3DCOLORVALUE <0.123, 0.234, 0.345, 0.456>

  Init
  Dll "testdll"
  Declare D3DCOLORVALUETOLONGASM, 1   ; one arg = ptr D3DCOLORVALUE

  PrintLine Hex$(D3DCOLORVALUETOLONGASM(offset cv))

  invoke D3DCOLORVALUETOLONG, offset cv
  PrintLine Hex$(eax)

  REPEAT 2
       invoke Sleep, 200
       counter_begin 500000, HIGH_PRIORITY_CLASS
              void D3DCOLORVALUETOLONGASM(offset cv)   ; very slow because it uses GetProcAddress; the attached version is a lot faster
       counter_end
       Print Str$("\n%i cycles for the DLL", eax)
   
       invoke Sleep, 200
       counter_begin 500000, HIGH_PRIORITY_CLASS
              invoke D3DCOLORVALUETOLONG, offset cv
       counter_end
       Print Str$("\n%i cycles for Assembler\n", eax)
  ENDM

  Inkey "ok"
  Exit

D3DCOLORVALUETOLONG proc pCv
LOCAL xr, xg, xb, xc
xa equ eax
   mov edx, pCv
   ffree st(7)
   ffree st(6)
   push 255
   fild stack   ; 255 in ST(0)
   fld st
   fmul [edx.D3DCOLORVALUE.r]
   fistp xr
   fld st
   fmul [edx.D3DCOLORVALUE.g]
   fistp xg
   fld st
   fmul [edx.D3DCOLORVALUE.b]
   fistp xb
   fmul [edx.D3DCOLORVALUE.a]
   fistp stack
   pop xa
   .if xa>127
          sub xa, 128
          shl xa, 24
          or xa, 80000000h
   .else
          shl xa, 24
   .endif
   mov edx, xr
   shl edx, 16
   or xa, edx
   mov edx, xg
   shl edx, 8
   or xa, edx
   or xa, xb
   ret
D3DCOLORVALUETOLONG endp

end start
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 27, 2012, 04:42:33 AM
Dunno how helpful I can be, but I ran the .exe JJ, and here are the results.  Michael wins.

40 cycles for Michael's DLL
43 cycles for Assembler1
69 cycles for Assembler2
67 cycles for SSE2
Title: Re: Seeking friendly collaborator
Post by: jj2007 on October 27, 2012, 05:17:55 AM
Michael wins.

Indeed, by a great margin. Which is very surprising because the SSE instruction processes the 4 dwords in parallel ::)
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 27, 2012, 06:07:56 AM
Not too bad for an old computer,  an old OS, (and an old guy like me  :lol:) eh?   Yeah, I know....    :greensml:
It's strange that I can use some SSE instructions, but can't run MasmBasic's editor.
It's true that there are oddities with multi-threading, esp when you only have 1 cpu...  ha!
Erm.  I tried to recompile that program JJ, and it almost worked except for something missing--  The GDI plus .lib from NASM
May I please rant about something?  Mostly joking---  We all have to be careful about 'missing file litter'  If you're running 6 different compilers, etc..  please...   :badgrin:
Title: Re: Seeking friendly collaborator
Post by: jj2007 on October 27, 2012, 06:45:39 AM
I tried to recompile that program JJ, and it almost worked except for something missing--  The GDI plus .lib from NASM

What's wrong with the attached Masm32 version? It should already be part of your installation, if not: are you using an older Masm32 package? The current one if version 11.
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 27, 2012, 09:31:32 AM
The one that runs on the embedded CPU: v9r Legacy.  Aaaalmost compiled...

MasmBasic.lib(libtmpAB.obj) : warning LNK4078: multiple ".drectve" sections found with different attributes (00000A00)
MasmBasic.lib(libtmpAB.obj) : error LNK2001: unresolved external symbol _GetConsoleWindow@0
masmbasictest.exe : fatal error LNK1120: 1 unresolved externals
Link error
Ah well...  No insult meant to anybody...  But this is why I'm still kind of clinging to FreeBasic...
I can transition to Asm gradually.  It seems to run as fast as C.  They say it can process C, too.  (Not that I can process C  :biggrin:)
And other than this one little library issue for DX8, I had fun compiling the Win32 GUI examples (not DX9 - really DX10),
 and even wrote some code in it in QBasic very easily.  Yea.  :eusa_dance:
I did this little moving square graphic, and it ran at like 200,000FPS,  The original QBasic (which I can still run) was like... I dunno 50-100FPS

"This will be my C, and the inline Asm will be my future!"
Title: Re: Seeking friendly collaborator
Post by: jj2007 on October 27, 2012, 04:25:10 PM
MasmBasic.lib(libtmpAB.obj) : error LNK2001: unresolved external symbol _GetConsoleWindow@0
masmbasictest.exe : fatal error LNK1120: 1 unresolved externals
...
"This will be my C, and the inline Asm will be my future!"

Attached a special lib that has the call to GetConsoleWindow disabled (it's needed only for displaying Chinese and Arabic in the console window, so you can live without it ;)).
Title: Re: Seeking friendly collaborator
Post by: MichaelW on October 27, 2012, 05:18:15 PM
Quote
It seems to run as fast as C.

For some code it is, thanks to the efforts of the FreeBASIC developers on the compiler’s asm emitter. But for other code, where the C compiler optimizations are effective, the compiled C is code faster than the FreeBASIC-compiled code, and generally competitive with asm code. To demonstrate, I compiled this C version of the original VB function:
Code: [Select]
typedef struct _D3DCOLORVALUE_
{
    float r;
    float g;
    float b;
    float a;
} D3DCOLORVALUE_ ;

int D3DCOLORVALUETOLONG_C( D3DCOLORVALUE_ *cv )
{
    int r,g,b,a,c;

    r = cv->r * 255;
    g = cv->g * 255;
    b = cv->b * 255;
    a = cv->a * 255;

    if( a > 127 )
    {
        a -= 128;
        c = a << 24 | 0x80000000;
        c |= r << 16;
        c |= g << 8 ;
        c |= b;
    }
    else
    {
        c = a << 24;
        c |= r << 16;
        c |= g << 8;
        c |= b;
    }
    return c;
}

With the Microsoft Visual C++ Toolkit 2003 compiler using /O2 /G6 optimizations, and linked the object module into my FreeBASIC test app, and running on my P3 I got these results (the cycle count order is empty loop, FB normal function, FB naked function, MASM, C):
Code: [Select]
VB code               :741F3C58
VB code -> FB syntax  :741F3C58
FB naked function     :741F3C58
MASM function (in DLL):741F3C58
Compiler optimized C  :741F3C58

 0 cycles
 78 cycles
 31 cycles
 30 cycles
 33 cycles

 0 cycles
 78 cycles
 31 cycles
 30 cycles
 33 cycles

 0 cycles
 78 cycles
 31 cycles
 30 cycles
 33 cycles

 0 cycles
 78 cycles
 31 cycles
 30 cycles
 33 cycles


Title: Re: Seeking friendly collaborator
Post by: mikorians on October 28, 2012, 02:50:10 AM
Ok JJ, it compiled.  Ran it, MsgBox: Fatal Error: GetLastError (line ??): One of the library files needed to run this application cannot be found.

MichaelW: Thank you for the statistics. They have been interesting and informative for my descision.  And the likelihood of me using C for any reason is 0

Now that I've chosen either FB or Masm, how shall we go about writing a targeted library file for DX8 for it?  Of course MichaelW, see our conversation on FB Forum.  (If it's you)
Title: Re: Seeking friendly collaborator
Post by: jj2007 on October 28, 2012, 04:03:41 AM
Ok JJ, it compiled.  Ran it, MsgBox: Fatal Error: GetLastError (line ??): One of the library files needed to run this application cannot be found.

That could be gdiplus.dll or any other new dll that came along with XP. Sometimes
include \masm32\MasmBasic\MasmBasic.inc
MbUseErrLine = 1

helps to identify the culprit (it inserts extra code in each macro). Often, the XP dlls can be downloaded somewhere, but there is no guarantee that they work under Win98.
Title: Re: Seeking friendly collaborator
Post by: mikorians on October 29, 2012, 02:05:36 AM
Thanks, JJ.  Added MbUseErrLine = 1:  Got your compiled sample exe to run finally -stupid me- it wanted the .dll file test.dll and i hadn't put it in the same directory.
Your source listing above (Oct 26) apparently compiled differently from the .exe you included in your .zip file.  Ran it.
621 cycles for the DLL
42 cycles for Assembler

I've written some applications in FreeBasic now, and find the environment enjoyable, so all I need now are examples of DirectX3D8 invocation in either FB or Asm.
Some kind of .bi wrapper would be appreciated.

I have found a wrapper set for PowerBasic if it could be adapted perhaps for FreeBasic, or---
http://www.rvalois.com.br/downloads/free/dx8vbtl/DX8IncTut.zip (http://www.rvalois.com.br/downloads/free/dx8vbtl/DX8IncTut.zip)

Here was my attempt to convert/modify the relevant .bi files to point at the relevant libd3d8.dll.a library file
http://sites.google.com/site/mikorians/DX8 Demo (NG).zip (http://sites.google.com/site/mikorians/DX8 Demo (NG).zip)

HAPPY HALLOWEEN
Title: Re: Seeking friendly collaborator
Post by: mikorians on November 03, 2012, 09:46:35 AM
OK, JJ --
MasmBasic's your baby.  I've been having a lot of trouble getting any 3D up with FreeBasic.
I can't run your editor, but the library loads, and we seem to compile things.

Can you give me a windows98 comatible example of a dll call like 'shimgvw' -- which 98 doesn't have ?  --  We did call MichaelW's test dll successfully, so that's encouraging.
We'll be trying in the future to access DX7 (for raw polygon power without the overhead)
You said you were game for this.
Title: Re: Seeking friendly collaborator
Post by: jj2007 on November 03, 2012, 09:49:32 PM
Can you give me a windows98 comatible example of a dll call like 'shimgvw' -- which 98 doesn't have ?

Here is one. Don't give up on FreeBasic too early - MasmBasic is powerful, but many algos including the dynamic string engine use SSE2 and will crash with your CPU. But Dll & Declare should work. Try what happens if you activate the Print Str$ below  ::)

include \masm32\MasmBasic\MasmBasic.inc   ; download (http://masm32.com/board/index.php?topic=94.0)
.data
MyLowR8   REAL8 -123.4
MyHighR8   REAL8 456.7

   Init
   Dll "msvcrt"
   Declare floor, C:1   ; floor expects C calling convention and one argument

   push eax      ; create a slot for returning an integer from the FPU
   .if floor(MyLowR8)
      fistp stack   ; floor returns the value in ST0, so we need to drop it into the slot
   .else
      MsgBox 0, Str$("Error %i", eax), "Hi", MB_OK   ; never seen, it seems floor swallows everything...
   .endif
   pop ecx
   print str$(ecx), 9, "returned", 13, 10
   ; Print Str$("Result=%i",ecx), Str$(" for %f\n", MyLowR8)

   push eax      ; create a slot for returning an integer from the FPU
   void floor(MyHighR8)   ; instead of .if ..., we discard the return value
   fistp stack      ; (it's in eax, nonetheless, but we need the value returned in ecx)
   pop ecx
   print str$(ecx), 9, "returned", 13, 10
   ; Print Str$("Result=%i",ecx), Str$(" for %f\n", MyHighR8)

   Inkey
   Exit
end start
Title: Re: Seeking friendly collaborator
Post by: mikorians on November 04, 2012, 04:51:58 AM
-124    returned
456     returned
Result=4218990 for 456.7000

I'll check in at freebasic.
Been having a lot of luck with BlitzBasic3D --- Ever used it?
Title: Re: Seeking friendly collaborator
Post by: jj2007 on November 04, 2012, 06:31:14 AM
-124    returned
456     returned
Result=4218990 for 456.7000
So Dll/Declare works. I am surprised that Print works, it uses SSE2. But things like
print Str$("This is a float with nine digits precision: %9f\n", 3*PI)
print Str$("This is a float with nineteen digits precision: %Jf\n", PI)
should work, actually, i.e. combining Masm32 print (lowercase p) with MasmBasic Str$().

Quote
I'll check in at freebasic.
Been having a lot of luck with BlitzBasic3D --- Ever used it?

No. My experience with Basic is a bit of VB for Apps plus a lot of GfaBasic, and now MasmBasic.

EDIT: I attach an example with new Dll & Declare macros. Behaviour is identical except for the speed. Declare was not designed for innermost loops, so it called GetProcAddress all the time. The new version does it only once, so that should be a lot faster now.
Title: Re: Seeking friendly collaborator
Post by: MichaelW on November 04, 2012, 08:18:05 AM
mikorians,

Which Windows 98 are you running, first edition or second edition? IIRC the Windows version is something like 4.10.1998 for the first edition, and 4.10.2222 for the second edition. IIRC you can get the version number from the General tab in the System Properties dialog, available by right-clicking the My Computer icon and selecting Properties.
Title: Re: Seeking friendly collaborator
Post by: qWord on November 04, 2012, 08:55:18 AM
blank
Title: Re: Seeking friendly collaborator
Post by: mikorians on November 05, 2012, 05:02:28 AM
It's SE.

blank?

Blitzbasic3d has been running real fast.  I'm going to throw all of my models at it and see what it takes to slow it down.
Title: Re: Seeking friendly collaborator
Post by: Farabi on December 11, 2012, 11:54:25 AM
Unfortunately I only can do OpenGL instead of DirectX. I think DX and OGL had the same speed since it only interfacing the Gfx.
Title: Re: Seeking friendly collaborator
Post by: mikorians on December 12, 2012, 04:34:38 AM
Thank you for your reply Farabi, but I'm like, obsessed with DX since the cards all say dx compatible on the carton.
Title: Re: Seeking friendly collaborator
Post by: abnuque on February 01, 2013, 10:47:49 AM
I do graphics using openGL, if that is fine with you, please email me your specific requirements so that we can work it on. my address is abnuque@yahoo.com

Thanks.