Which parts of DirectX interfere with Lua?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Which parts of DirectX interfere with Lua?

Matt Campbell-2
Hello:

I've read that DirectX causes problems with Lua because it sets the FPU
to single-precision mode.  Which parts of DirectX do this?  If I use
DirectSound but not DirectDraw or Direct3D, will I still have problems?  
Thanks.

--
Matt Campbell
Lead Programmer
Serotek Corporation
www.freedombox.info
"The Accessibility Anywhere People"

Reply | Threaded
Open this post in threaded view
|

RE: Which parts of DirectX interfere with Lua?

Richard Ranft
>
> Hello:
>
> I've read that DirectX causes problems with Lua because it sets the FPU
> to single-precision mode.  Which parts of DirectX do this?  If I use
> DirectSound but not DirectDraw or Direct3D, will I still have problems?
> Thanks.

And can we circumvent this by locally changing Lua's handling to either
single precision, or flipping the FPU to single precision when DirectX
requires the use of it?

Anyone have a suggested workaround/fix for this?

Richard

Reply | Threaded
Open this post in threaded view
|

RE: Which parts of DirectX interfere with Lua?

Chen Li (MSRA)
In reply to this post by Matt Campbell-2
You can use "D3DCREATE_FPU_PRESERVE" when creating the D3D device (the behavior flag).

This will force Direct3D to not change the FPU control word, running the pipeline using the precision of the calling thread.

This is the easiest way to solve this problem, although there might be performance hit to enable this flag.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Matt Campbell
Sent: 2006年4月17日 12:01
To: [hidden email]
Subject: Which parts of DirectX interfere with Lua?

Hello:

I've read that DirectX causes problems with Lua because it sets the FPU
to single-precision mode.  Which parts of DirectX do this?  If I use
DirectSound but not DirectDraw or Direct3D, will I still have problems?  
Thanks.

--
Matt Campbell
Lead Programmer
Serotek Corporation
www.freedombox.info
"The Accessibility Anywhere People"

Reply | Threaded
Open this post in threaded view
|

Re: Which parts of DirectX interfere with Lua?

Greg Falcon
In reply to this post by Richard Ranft
On 4/17/06, Richard Ranft <[hidden email]> wrote:
> >
> > Hello:
> >
> > I've read that DirectX causes problems with Lua because it sets the FPU
> > to single-precision mode.  [...]
>
> Anyone have a suggested workaround/fix for this?
>
> Richard

There are two workarounds suggested on the lua bugs page
(http://www.lua.org/bugs.html#5.1):

   The simplest solution is to use DirectX with the D3DCREATE_FPU_PRESERVE flag
   Otherwise, you can change the definition of lua_number2int in
luaconf.h to this one:

   #define lua_number2int(i,d)   __asm fld d   __asm fistp i

Greg F
Reply | Threaded
Open this post in threaded view
|

Re: Which parts of DirectX interfere with Lua?

David Given
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Greg Falcon wrote:
[...]
>    Otherwise, you can change the definition of lua_number2int in
> luaconf.h to this one:
>
>    #define lua_number2int(i,d)   __asm fld d   __asm fistp i

Not if you're using gcc, you can't... beware inline assembly! It's horribly
non-portable!

Does the naive approach (simply defining the macro to 'i=(int)d') work
effectively?

- --
+- David Given --McQ-+ "If you're up against someone more intelligent
|  [hidden email]    | than you are, do something insane and let him think
| ([hidden email]) | himself to death." --- Pyanfar Chanur
+- www.cowlark.com --+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFERAqKf9E0noFvlzgRAmaGAKCG+lzf1SjhggvX7ClRbWK7/C4w/ACfZNXr
si5RkQJXLnGr7XKi9XXLjFE=
=IJF3
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: Which parts of DirectX interfere with Lua?

Alex Queiroz
Hallo,

On 4/17/06, David Given <[hidden email]> wrote:
>
> Does the naive approach (simply defining the macro to 'i=(int)d') work
> effectively?
>

     It works, it's just slow to a crawl.

--
-alex
http://www.ventonegro.org/
Reply | Threaded
Open this post in threaded view
|

Re: Which parts of DirectX interfere with Lua?

David Given
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alex Queiroz wrote:
[...]
> On 4/17/06, David Given <[hidden email]> wrote:
>> Does the naive approach (simply defining the macro to 'i=(int)d') work
>> effectively?
[...]
>      It works, it's just slow to a crawl.

Why? Not that I'm arguing, I'm just curious to know why such a primitive
operation is so slow. If the eight or so instructions that gcc generates
to do this (I just checked) can be replaced with the two FPU
instructions described earlier, or a cunning integer arithmetic hack,
then why doesn't gcc do this by default?

- --
+- David Given --McQ-+
|  [hidden email]    | "Those that repeat truisms, are also forced to
| ([hidden email]) | repeat them." --- Anonymous from Slashdot
+- www.cowlark.com --+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFERLuff9E0noFvlzgRAhlMAKC49i9EN+8BshR+MrNSBHo8Z37emwCgvQjE
UFRFBriGHvijnKqOKC3IhtU=
=3yAl
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: Which parts of DirectX interfere with Lua?

Alex Queiroz
Hallo,

On 4/18/06, David Given <[hidden email]> wrote:
>
> Why? Not that I'm arguing, I'm just curious to know why such a primitive
> operation is so slow. If the eight or so instructions that gcc generates
> to do this (I just checked) can be replaced with the two FPU
> instructions described earlier, or a cunning integer arithmetic hack,
> then why doesn't gcc do this by default?
>

     Because of the C conversion rules, which specifies the cast must
be a truncation unlike normal arithmetic that uses rounding. To switch
between these modes the compiler generates the fldcw opcode that
flushes the floating-point pipeline. Modern CPUs rely on deep
pipelines.

--
-alex
http://www.ventonegro.org/
Reply | Threaded
Open this post in threaded view
|

Re: Which parts of DirectX interfere with Lua?

Roberto Ierusalimschy
In reply to this post by Alex Queiroz
> > Does the naive approach (simply defining the macro to 'i=(int)d') work
> > effectively?
> >
>
>      It works, it's just slow to a crawl.

It is slower than the non-naive approach, but I would not say that it
is that slow, mainly if you dilute the performance penalty in a real
application (that does other things besides accessing integer arrays).

-- Roberto
Reply | Threaded
Open this post in threaded view
|

Re: Which parts of DirectX interfere with Lua?

Alex Queiroz
Hallo,

On 4/18/06, Roberto Ierusalimschy <[hidden email]> wrote:
>
> It is slower than the non-naive approach, but I would not say that it
> is that slow, mainly if you dilute the performance penalty in a real
> application (that does other things besides accessing integer arrays).
>

     Well, this whole thread started with game programming. Some naive
programmer could flush his floating-point pipeline in some very
undesirable places and lose all the optimizations present in modern
CPUs.

--
-alex
http://www.ventonegro.org/
Reply | Threaded
Open this post in threaded view
|

Re: Which parts of DirectX interfere with Lua?

A.Cicak-2
In reply to this post by Richard Ranft
Why dont you simply pass D3DCREATE_FPU_PRESERVE and forget about that
problem. I did some tests on our app (which uses D3D extensively) and there
was not any drop in performance.


"Richard Ranft" <[hidden email]> wrote in message
news:[hidden email]...

> >
>> Hello:
>>
>> I've read that DirectX causes problems with Lua because it sets the FPU
>> to single-precision mode.  Which parts of DirectX do this?  If I use
>> DirectSound but not DirectDraw or Direct3D, will I still have problems?
>> Thanks.
>
> And can we circumvent this by locally changing Lua's handling to either
> single precision, or flipping the FPU to single precision when DirectX
> requires the use of it?
>
> Anyone have a suggested workaround/fix for this?
>
> Richard
>
>



--
----------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 600 spam emails to date.
Paying users do not have this message in their emails.
Try www.SPAMfighter.com for free now!