May 23, 2012

Using P4SandBox for 3 Weeks or So

I have been using P4SandBox for 3 weeks or so, and I'm pretty happy with it. The private repo is great: creating new streams(read it as branches) and switching between them are fast. (It internally uses shelving, of course)  So streams almost work as branches + automatic shelving.

One bug I found:

  • If you MANUALLY shelve in a stream, you won't be able to unshelve it!  So currently I'm not doing any manual shelving in a stream: Instead, I keep creating a new stream if I need to shelve what I've been working on and start to work on something else. By the way, it works fine in the traditional central-controlled scheme with no P4SandBox involved.
One annoyance I found:
  • When you copy/merge, (it's basically push/pull in Git) it doesn't propagate change histories. Perforce said the next version will have this feature implemented

May 21, 2012

COM Smart Pointer in DX9/11 Renderer?

Main Article
Recently I've been developing a real-time application outside the gaming industry, and I happened to implement a very thin, stateless DX9 renderer, and then ported it to DX11. This piece of software runs on Windows PC, so it was kind of nice to deal with more powerful hardware than current-gen consoles, which I've been married to for the last 6+ years.

In the gaming industry, I don't think I saw anyone using COM smart pointers in a rendering engine while Direct3D is built on COM. Probably it's because of performance concerns.  But I'm not sure if it is still a valid concern. For the last few years, I saw more non-rendering game codes using smart pointers extensively, and most of the time the performance was fine. So I'm thinking now that it might be okay to use COM smart pointers for D3D objects.  Does anyone have any experience with this on a commercial game? If so, how did it behave?

Maybe I Should Add Something Useful Here
I feel guilty to finish this post without giving out any useful info. So let me just say how to use COM smart pointers for DX9 and 11.

For DX9:
To define smart pointers in DX9, just include comdef.h before including d3d9.h.

#incldue <comdef.h> 
#include <d3d9.h>

Then you will get a smart pointer for every single D3D type with ~Ptr prefix.  With this, your D3D device's smart pointer will be declared like this:

IDirect3DDevice9Ptr mDevice;

And using it is very straight-forward.  There's really no gotchas using this pointer.. (unlike dx11's)

For DX11:
d3d11.h doesn't contain any special preprocessor macros that automatically generate COM smart pointer types for D3D interfaces. So what I had to do was using atlbase's COM smart pointer.

First, include atlbase.h

#include <atlbase.h>

Now you can manually make smart pointers for any D3D declaration like this:

CComPtr<ID3D11Device> mDevice;

It works mostly same as DX9's COM smart pointer except one gotcha.  If you try to pass in the address of an atlbase COM smart pointer, while it's not empty, it'll assert on you.  And you know how often you have to pass in type** to a D3D calls. (e.g, to create a render target texture)  So if you do this, you should clear the smart pointer before you use & operator. This should be done by assigning nullptr to the smart pointer like this:

mRenderTarget = nullptr;

One gotcha here, I once assumed CComPtr's detach() function does the same thing as assigning nullptr, which was not true. gaaaahhh!! So don't do this, if you do that you will have unreleased resources hanging around.

K, I'm not feeling guilty anymore.. so ciao :)

May 1, 2012

Personal Choice of Version Control System in 2012

Sometime ago, I wrote a blog post about my personal choice of VCS and the winner was  Subversion.  But now there has been two changes from Perforce that made me want to re-evaluate. Those two changes are:
  • New feature called P4SandBox
  • More generous free version limitations: 20 users and 20 workspaces

What is P4SandBox?
This new feature available in Perforce 2012.1 enables us to use a local private depot similar to Git.  But this is not a completely distributed system: it is more like you make a mirror in your HDD and work offline.  Then when you are ready to commit to the central server, you push all your local changes to the central server. Also P4SandBox has the concept of streams which almost work similar to the powerful Git branching.

This video will explain these new features better than me :)

Being in the gaming industry about 10 years and playing with some open-source projects means I have dealt with different version control systems, or VCSs, from complete free, brute-force manual file copy method to very expensive commercial-grade Perforce.

So which program have I been using at home? Subversion.... I know! A lot of people will argue that other programs are better, and I am not gonna say they are wrong. The reason why I have been using Subversion is because it did what I want with the least amount of annoyance.  But now I'm gonna switch back to Perforce because I became to believe Perforce will serve me better now.  Below is the list of what I need/want from my personal VCS and how the most popular VCSs do the job:

Windows Support
Yes, I'm a MS whore.  I use Windows all the time, and I, as a game programmer, personally don't see huge need for Linux for myself.  Also if I can maintain only one OS at home, that's less drama for me. (Yay?).
  • Git(-2): I like Git a lot, especially how it handles branches, so I really wanted to use it on Windows.  But, as far as I know, the only way to use Git server on Windows is through Cygwin or msysgit.  Cygwin is basically doing Linux emulation in a sense, and I personally don't enjoy installing Cygwin. msysgit is a bit easier to install on Windows, but still I had to set up SSH or what not, so there's no one-button solution for Git on Windows.  So big no-no to a MS whore like me.
  • Perforce(+1): Perforce supports Windows pretty well.  It comes with easy-to-install server program/service for windows.
  • Subversion(+2): This was actually a big surprise to me.  There is a program called VisualSVN Server, which is one-click solution for Subversion server on Windows.  It just works and comes with https access and access control all in one nice and simple GUI.  This was even easier than installing Perforce.
Occasional Multi-User Support
Although my VCS is mostly there to keep a history and backups of my own codes, sometimes I open it up to my friends so that I can get useful feedback from them.  So having multi-user support is very useful for me.

  • Git(+1): Git can easily support multiple users.  But setting access control for each users can be a bit of PITA on Windows.  When I tried it last time, I had to make fake Windows user accounts and hook'em up with SSH.
  • Perforce(+1): Perforce used to be free for either i) 2 users and 5 client workspaces, or ii) unlimited users and up to 1000 files.  But now it's free for 20 users and 20 client workspaces with unlimited # of files.  I believe each user need 2 workspaces to get P4SandBox working(one for main and the other for the mirror) per computer.  So if we say each user uses 2 computers, one user will take up 4 workspaces.  So 5 full-time users...  I think it's very reasonable for my personal projects. So I changed this score from -1 to 1
  • Subversion(+2): As I said earlier in Windows Support section, VisualSVN Server comes with a nice GUI where you can simply setup users and access control.  So another big thumbs up from me.

I'm cheap. I love free stuff.

  • Git(+1): free
  • Perforce(0): free for limited use. and this time the limitation is not severe.. So I changed the score from -1 to 0.
  • Subversion(+1): free

GUI Client
I'm in love with Perforce's nice GUI clients. Not so much with P4V; more with P4Win. But P4Win is discontinued.... Oh well, P4V is still good enough.  Sure, I still use command-line a lot for certain things GUI clients don't support, but I found 90% of time, using GUI clients are much faster and easier.

  • Git(-1): it doesn't have any nice free GUI client as far as I know.  There are some being developed at this moment, but they don't seem to be mature or free enough to use them.  TortoiseGit is good enough most of the time.  But I still prefer P4Win style, real GUI clients. 
  • Perforce(+2): P4Win is awesome. P4V is great, too.
  • Subversion(+1): I found a program called SmartSVN.  It has limited functionalities unless you buy the pro version, but I found the basic free version is good enough for day-to-day operations.  Anything that cannot be done through the free SmartSVN version, I use TortoiseSVN.  Then anything that cannot be done by TortoiseSVN, I use command-line.  
Who doesn't love branching?  It's such a neat tool to fuck around(read it as experiment) your code without ruining your projects.
  • Git(+2): I love the powerful branching feature of Git. You don't need to make a copy in different directories, so it helps a lot with path referencing in the code.  Say you have a program that links with library Awesome, and now you wanna branch library Awesome.  With Git, you simply need to switch to different branch and build.  But with other source control systems like Perforce, you will have to branch the library into a different directory and change the library path in your program code.
  • Perforce(+2): As I just explained in Git section above, branching into a different folder sucks.  Also the speed of branching a large number of files is slow because Perforce server controls everything.  Network speed is slower than your HDD's spin rate. However, if you use streams in P4SandBox the branching almost became Git's branching. Everything works inside your sandbox without connecting to the central server, so it's super fast.  So I changed the score from -2 to 2 here.
  • Subversion(-1): The speed is fast enough.  But still you have to branch into different directory.. uggh.. that bothers me.

Final Score
So final score for me is like this.
Don't forget.  This is the score for my personal need. Not for the big giant game studios.  So if you ever comeback and say "but Perforce is better because it can supports 200 users easily", I'm gonna make you watch this video for 2 hours before you go to bed.