C++ SIMD for 3D graphics programming?

This is a discussion on C++ SIMD for 3D graphics programming? within the C++ Programming forums, part of the General Programming Boards category; Is there any good books for this? I really don't have any idea on how to code it in C++. ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    64

    C++ SIMD for 3D graphics programming?

    Is there any good books for this? I really don't have any idea on how to code it in C++. Can anyone give me a good starting learning code for it?

    I read in wiki that it is widely use in 3D graphics programming so I went here and ask it. Do I need math here? I'm good in Calculus and Linear Algebra.

    I found this site. Is it a good introduction? http://www.codeproject.com/KB/recipes/sseintro.aspx

    Sarah22

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,173
    I really don't have any idea on how to code it in C++
    And you are already thinking about SIMD?

    Learn basic C++ first. This site has a tutorial, for example.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    64
    Quote Originally Posted by cyberfish View Post
    And you are already thinking about SIMD?
    Yes, because I read somewhere on the net that it enhance performance.

    Quote Originally Posted by cyberfish View Post
    Learn basic C++ first.
    Basic C++? Like what?

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,173

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    63
    IIRC, several C++ compilers offer support for automatically generating SSE(1/2/3/4) where possible. MSVC, GCC, and the Intel compiler can all do it for you. IIRC, MSVC and GCC can do SSE and SSE2, but the Intel compiler can do 1, 2, 3, and 4.

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by sarah22 View Post
    Yes, because I read somewhere on the net that it enhance performance.
    It does, but its not for the faint of heart, it basically involves either using inline assembly, or the macros Microsoft so 'graciously' replaced inline assembly with.

    Basic C++? Like what?
    Well, for starters have you written Hello World in C/C++ yet?
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    As of MSVC 2005 all MSVS compilers support SIMD instructions and will use them if you set it in the options. MSVC 2005 by default has this turned on which is why the new games would not run on my old AMD system which did not support SIMD.

    Intel and AMD's tech refs explain SIMD in great detail but you had better have a good understanding of the x86 architecture. I would not recommend hand coding SIMD into an application unless you really knew what you were doing. SIMD for 3D is sort of a moot point now since the video card is just as fast or faster than the equivalent SIMD. For accelerated 2D multimedia I could see some usage for it but I'm not sure it's worth the pain.

  8. #8
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by Bubba View Post
    As of MSVC 2005 all MSVS compilers support SIMD instructions and will use them if you set it in the options. MSVC 2005 by default has this turned on which is why the new games would not run on my old AMD system which did not support SIMD.
    I stand corrected, originally 2005 did not support inline assembly SIMD instructions, which are not the same as intrinsics. 2008 appears to do so again though. I guess I can stop using VS 6.0 now, although I still need to keep using VS 4.0.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  9. #9
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    OK, I thought I was correct in my original assertion so I looked back at some notes. VS does NOT support inline assembly for 64 bit mode.

    and to the OP, this demonstrates how much faster SIMD is than C++, at least on Intel processors, AMD SIMD performance is less than spectacular last time I checked.

    Code:
    #include <windows.h>
    #include <stdio.h>
    
    int main(){
    	double* pData	= (double*)_aligned_malloc(sizeof(double) * 2 * 67108864, 16);
    	double* pOutput	= (double*)_aligned_malloc(sizeof(double) * 2, 16);
    	for(int x = 0;x<67108864 * 2;x++) pData[x] = 1.0;
    
    	DWORD SIMF_Start = GetTickCount();
    	_asm {
    		pushad;
    		mov	                eax , pData;
    		prefetcht0        [eax];
    		mov	                edx , pOutput;
    		mov	                edi , edx;
    		mov	                edx , 0x00000010;
    		mov	                ecx , 0x04000000;
    		xorpd               xmm0 , xmm0;
    the_loop:
    		prefetcht0        [eax+16];
    		addpd              xmm0 , [eax];
    		add	                eax , edx;
    		loop	                the_loop;
    		mov	                edx , edi;
    		movapd            [edx] , xmm0;
    
    		popad;
    		}
    	DWORD SIMD_Stop = GetTickCount();
    
    	DWORD CPP_Start = GetTickCount();
    	for(int x = 0;x<2 * 67108864;x++) pOutput[0] += pData[x];
    	DWORD CPP_Stop = GetTickCount();
    
    	printf("SIMD took %d\nCPP took %d\n" , SIMD_Stop-SIMF_Start  , CPP_Stop-CPP_Start);
    
    	return 0;
    	}
    Last edited by abachler; 09-27-2009 at 09:21 AM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Provided your compiler would not have already used SIMD in place of your original C++ code. Without looking at the output asm from the compiler I would say it's a bit dangerous to try to out-optimize the compiler without first doing some research.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Turtle Graphics, how does it work?
    By freddyvorhees in forum C++ Programming
    Replies: 15
    Last Post: 08-28-2009, 09:57 AM
  2. Beginning Game Programming Type Books
    By bumfluff in forum Game Programming
    Replies: 36
    Last Post: 09-13-2006, 04:15 PM
  3. Graphics Programming :: Approach and Books
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 05-11-2004, 08:33 PM
  4. egavga.bgi problem
    By sunil21 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-22-2003, 05:06 PM
  5. Graphics Devices and Cprintf clash
    By etnies in forum C Programming
    Replies: 6
    Last Post: 05-09-2002, 11:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21