JavaKazRace - Playable Java racing game demo
PSEmu Pro GPU plug-in
DOSX Utils
SHLight 2004
JavaKazRace DSharingu PSEmuGPU DOSX Utils SHLight 2004

Direct3D 10 Sucks !!!

Davide's picture

It's really fucked up to think that to draw a quad one has to has to create vertex buffer resource, an "input layout" and whatnot.

It's lame but I must do it, but it's really lame !

Fack those ill conceived abortions (oxymoron ?).. started with Direct3D 1.0

Everyday I see the design mistakes I make when I write any code.. and then I think that it's the same mistakes that every programmer does.. only that most of us have to deal with the bullshit of few.

Direct3D 10 is bullshit... and so is Vista.. but that's nothing new 8)

Oh and by the way, I managed to work around the nVidia driver crash bug in Vista... all I had to do was to scale down the geometry 8)
I had position values going beyond 160000.0f, I scaled down to 50000.0f and the crash is gone.

Pretty fucked up 8)

UPDATE: It turns out that the problem arises with the size of the object relative to the far plane. I guess it's basically a far plane clipping issue.
In fact I had the driver crash again when pulling closer the far clipping plane on a scene that would work fine before.
So there you have it, now fix that driver, please !

Pains of memory management and C++

Davide's picture

Recently, I felt the pain of hands-on C++ development again.

Because I use SSE2 instructions and because those need to work on at least 16-bytes aligned memory, using standard "new" and "delete" was out of the question.
I proceeded in overriding them globally and wxWidgets started working funny: it sometimes would use my globally defined "new" and "delete", sometimes it would use the standard Microsoft CRT.
I finally found out that I should have enabled global memory allocation using a specific option in wxWidget's "setup.h" file (a configuration file for compilation).

Next, I decided that I needed memory leak detection. But, because I'm overloading the allocation operator I can't use the MS CRT's leak detection.
For the memory manager to keep track of allocations I decided to use a fixed length STL-like vector. This vector (which basically contains an array) is built as a template class that accepts as parameters the type and the maximum size.

The vector was declared as static and this gave me another big problem that took me a while to track down. At startup my poor vector was actually being used as some other static functions from wxWidgets called "new" and "delete" before the vector was actually initialized.

Basically the issue being lack of dependency between statically allocated items (a well known issue in C++).
One way to fix that was to put the array into a function. Every time a "new" was called, it would call a function which would initialize the static array the first time.
This is called "construct on first use". It worked well to command initialization.. but would leave me in the dark on where the destructor would be called.

I eventually built a separate vector class without constructor and destructor 8)

I've also cleaned up a bit things with smart pointers... but it's really a mess with C++. On the other hand, the approach of languages designed form ground-up with automatic garbage collection doesn't seems like a great thing for performance when seeing how those things work when implemented in C++.. lots of work behind the scenes !
But then, maybe one shouldn't use pointers when performance is of essence.. easier said than done !

Between a driver and an hard place

Davide's picture

Friday I got to test a new model that I'll have to use for my current project.
The unoptimized model had over 1M polys (it's a small one 8). I went on to display it with the DX10-based engine and it crashed the (NVidia) driver.
The model is actually composed of many smaller models, so it's not like there is a huge vertex buffer. It also had no textures and I was using a simple common shader.
The only issue I can think of is the range of coordinates which it's relatively very large. It's a laughable supposition, but everything points to that. I'll have to debug to find a workaround.. but it's not easy considering that those driver crashes force me to reboot almost every time ! (Vista stays up, but I can't do 3D anymore).
This is a really bad setback. For the test I eventually displayed the model with my ultra-basic software renderer... no crashes there ;) ..and if there were, I could have fixed them myself.

Another thing that bothers me about DX10 and drivers in general, is how one has to guess performance, because the internals are obscure.
For example, using an NVidia 8800, I noticed that performance is a lot worse when using buffers flagged as "dynamic".
This whole "static" vs "dynamic" thing is apparently part of DX10 and Vista's driver model. Somebody, somewhere, probably decides to put the buffer in system memory (as opposed to GPU memory) under the assumption that the buffer needs to be touched frequently. Only, I may want to change it rarely, and also I was sort of expecting for the buffer to be allocated directly in the GPU memory and only be mirrored in system memory if I ever tried to read from the buffer (which I wouldn't dare to).

So, I have to be really careful and only use the "dynamic" flag for things that change frequently.. and possibly forget about building a flexible system that uploads textures and geometry on-demand.. which is otherwise theoretically very possible with no (not much ?) performance degradation.
As it stands, it seems almost that dynamic buffers are being uploaded per-frame, regardless of the fact that they aren't being modified per-frame.
..this is all speculation of course.. but that's what I really don't like about this: having to spend time trying to guess what those drivers do behind my back.. and hope that different drivers on different card will behave similarly (crashes aside ;).

For this reason I hope that the time will come when game companies can write complete graphics pipelines again. Either in-house or licensing code, but staying away from closed-source drivers, so that one won't have to debug and profile in the dark.

Some are worried that they couldn't possibly do much better than what card manufacturers already do with those drivers.. I think that there is plenty to improve by just getting rid of those fat drivers that have been plaguing PCs ever since 3D cards came out.

ole'

April in Japan: Cherry business and quickies.

Davide's picture

In Japan the fiscal year starts in April. Newly graduated students start officially working on the 1st. Contracts are renewed or not renewed on the 1st. People go picnic under blossoming cherry trees in parks (花見, hanami).

A few things have changed in my company. I can't say about others publicly, but personally I still work there, which is nice 8)
I was offered to become a full-time employee, but other than the prestige of receiving the offer, if I had accepted I would have taken the pay cut on the first year !
The way it works is that when one becomes a full-time employee, he or she gets less monthly salary but overall more by way of 2 yearly bonuses.
However the bonus starts counting from January, while job positions change in April. So, one ends up with a lower salary to be compensated by a first-year-crippled bonus (!)
So, I signed (actually, stamped) another yearly contract and I'm looking forward to get some good work done.

I've been already working pretty long hours. Generally over 10 hours per day, towards 12, 14, sometimes more.
I wasn't specifically asked to, but I've been doing some interesting stuff and I like to hurry up at first to get to a point where I'm comfortable. Basically, I want to get good tangible results fast, so that the project picks momentum with the coworkers on board.
This is all the more true as a team leader, because I'm responsible for setting the groundwork for other people to work as smoothly as possible.. (basically trying to keep people happy with their tasks 8).
Most people mood about things can turn on a dime. Sometimes there are internal power struggles. Sometimes power struggles are out in th wild, sometimes are half concealed and fermenting in the background.
As criticism came form lack of sharing of information, I proposed daily morning meetings. Conceptually, 5 minutes standing meetings.
Though one can and will definitely sit, and sit for more than 5 minutes, the idea is to routinely update each other every morning. This beats longer more formal weekly meetings as much happens in a week and by the time one has to report, a lot gets forgotten. Generally it's just hard to get good feedback once per week.
Ideally people would work along and consult each other frequently during the day, but not everyone works with everybody else and it's nice to get a light update on things every day.
Also, because the meeting is meant to be brief and informal, one doesn't have to stick around and go too much in deep about other people's work (possibly the principal component of boredom in meetings).

Let's get busy !!!

P.S. I guess we're using a Agile software development practice without knowing it explicitly 8) ..but frequent updates are really just common sense (and I must have heard about stand-up meetings somewhere already).

Vista BSOD and NVidia drivers

Davide's picture

It looks like NVidia drivers are famous for crashing Vista.
I can believe that, considering all those Blue Screens Of Death I've been getting.
Also I think I can regularly get NVidia drivers to crash and stop providing 3D rendering until I reboot. Specifically very large polygons seem to be a cause of those crashes... ..umm perhaps some faulty clipping ;)  read more »

More on software rendering and Direct3D 10

Davide's picture

Writing a software renderer is quickly associated with revolutionizing things, but on the more conservative side, one advantage would really be that one has the freedom to optimize things as needed rather than having to try and guess what a driver is doing behind the scenes (maybe write your own driver ?!).
Graphics drivers do a great deal of work, they can make a big differences, they can be quite smart at guessing resources usage, what to prioritize on which basis, but they can't be smarter than a whole application.

APIs such as Direct3D and OpenGL don't have a concept of object (ok, OpenGL supports "lists" at least). So, they miss potentially useful hints. For example, if you know your object bounding box, you can tell right away whether or not the object requires clipping and you can tell in advance which textures you need, and what's the maximum level of detail that is needed for textures (if the bounding box is 512x512, you can't possibly need a 1024x1024 texture 8).
Based on that knowledge, one could completely avoid having to perform per-polygon clipping test and could also avoid loading full size textures in video RAM.. because a smaller mip-level would be sufficient.

Another big problem in dealing with a separate hardware graphics system is communication. Every state change can be a big deal. Drivers will probably cache things, but not necessarily.
Recently, I wrote an immediate rendering library to draw debug primitives. I had a small pool of vertex buffers that I would rotate as I called Draw() several times per frame. It turned out to be a big slowdown, so big that I had to switch to use one vertex buffer per frame (actually 2/3 to rotate at each frame, not at each Draw()).
To do that of course I had to keep track of logical draw calls issued by the application program, so that I could finally unmap/unlock the vertex buffer at the end and call all the Draw() at once.. remembering of which primitive type it was, how many vertices and which draw state was associated with that draw call.

This all comes down to having to deal with separate architectures. I have my vertex buffer, the card has its vertex buffer.. collect here, copy there, avoid touching this buffer or that buffer.
Small things that show the cat and mouse kind of job of having to optimize rendering using an API such as Direct3D 10.

Lastly, recently I managed to crash nVidia's driver on Vista 8)
I think it has to do with.. big polygons, or polygons going way off.. possibly a clipping bug ? All I know is that my screen goes blank and boom !
The window comes back and it's all black, while I get a balloon message from the sys-tray that says that the driver's process has crashed. From then on I can't do 3D unless I reboot 8)

ehhhhhhhhhhh

Game graphics superheroes bring some sense into future of real-time

Davide's picture

I'm glad that Carmack spoke out on ray-tracing for real-time. More precisely against the approach that Intel as been semi-officially following.
Shooting at triangle soups with cosmic rays is hardly efficient.
Predictably, Carmack has mentioned a possible evolution from 3D worlds made of very many unique texels to 3D worlds made of very many unique texels in 3D space.. basically voxels in sparse matrices (using run length compression for hollow spaces inside objects (assuming that one doesn't want to render actual solids 8)).

Using voxels (in sparse matrices) is definitely attractive, but the transition from 2D textures isn't so straightforward. Good resolution textures are only efficient because of mip-mapping. Mip-mapping is largely based on a static pre-process (creating smaller resolution copies of a texture).
When animating a model, one easily moves vertices that define polygons, while the heavy details are in textures that are based on static mip-maps.
If polygons go away, and there are only voxels (fat points) available, one would still need to do subsampling somehow, depending on the size of an object.. or else aliasing artifacts and terrible cache trashing would become major problems.

Anyway, today (Saturday) I went to work and I started writing a software renderer.. nothing new, and very very basic so far (one point per vertex !), but it's a good time to start, especially now with that I have a better understanding of hardware shaders.

..I think I agree on software renderers having a future, but I'll write more on that later.

zzzzzzzzzzz

Busy Man: Google Sites and points in DX 10

Davide's picture

I've been busy between work and not work !

Recently I tried Google Apps for my father's web site. I like the Google Sites thing which is an evolution of JotSpot, a company that Google bought over a year ago.
Very easy to set things up, yet I still have to change th HTML to do certain things. All those WYSIWYG editors seem broken to me. It's usually very hard to place a cursor when one really wants, or to get rid of some formatting. Very hard to get rid of a link being assigned as text is typed and incredibly complicated to extend an hyperlink effect to text added before an existing hyperlink.
I also never quite understood the logic by which things get selected. For example even in MS Word, when I go select a line of text, the selection will snap to include the newline character. Or sometimes I select some text from bottom to top and a whole chunk of text gets selected !

In Google Sites I can't find a way to select a whole table while changing hyperlinks for a picture it doesn't really work with what I have.
Still it's nice to setup sites quickly, though I wish Google Apps would allow Google Sites to take over the domain, rather than redirecting to some complicated URLs.

Speaking of Direct3D 10, I've been using it for a while now. Nothing too special, but it's interesting the tendency to shift rendering properties, such as texture sampling and blending from the engine to the HLSL code. On one side it's a pain to try take over those stats over the shader (see Shader Reflection). Some complex passages need to be done to for example replace texture addressing.. but then again, maybe those things should be translated into shader permutations: even when starting from one generic shader, perhaps different shaders should be created depending on the material properties.

Recently I also tried to render a scene using points rather than triangles. Much to my surprise, points rendering (on NVIDIA GT8800 Ultra) was about 3 times slower.
I'm told that moder graphics cards are optimized for triangles but still.. rendering points should be so much faster !!
My goal was to speedup rendering of objects that are rather complex but that are being projected distant enough so that triangles are no bigger than one pixel.
Ideally then one would also take into account camera focus to use larger points in place of triangles when they are going to be smoothed by out of focus post processing.

mumble mumble

Last day at GDC and some graphics thoughts

Davide's picture
GDC 2008

Today is the last day of GDC. In the past two days food quality has slightly improved. Though after the 1st day, the less expensive pass holders started coming: a lot more people !
There are very long lines to get the lunch boxes, but luckily they go pretty smooth.

A combination of jet-lag and night coding sessions brought me to a completely screwed schedule, with the advantage of not having problems waking up in the morning.. because by 4 am I'm already up (whether I slept 10 or 3 hours 8).

Some lectures were pretty interesting. I've been going to multi-core programming lectures (lots of them, sponsored by Intel) rather than more traditional lectures.. and completely avoided most non-technical lectures.

I bought a RenderMan book and I started writing a simple RenderMan interface !
There is a lot of talk about off-line rendering going real-time, but I don't think that OpenGL and Direct3D 10, 11, 12 are the right way to go about it. There are a lot of things that we 3D programmers on the real-time side have to learn from the pre-rendered world if we don't want to be always lagging behind the pre-rendered movies.

Of course pre-rendered will always win in terms of quality, but it's important to embrace the off-line rendering systems build pipeline and then go on about tricks to scale quality down without having to rebuild models, textures and shaders from scratch.

I see RenderMan the way I saw OpenGL 10 years ago. OpenGL was considered overkill for games, until Carmack started using it with the support of 3Dfx.
If Carmack today said we should be using RenderMan, I bet everyone would rush to it.. but it's me the one that is saying it.. 8)

Food at GDC 2008

Davide's picture
GDC 2008

Same crappy sandwiches as last year.

I just coughed and felt like the shit was coming up out of my mouth...

Yesterday for lunch I went to this "Lori's Diner" in downtown. Supposed to be famous, pretty crappy indeed.
The floor was filthy, the service non-existent: the waitress didn't acknowledge us as we got in. Didn't bother to give extra silverware as the table had only 2 sets and we were a party of 3.
She gave us the burgers in a hurry and disappeared, other people went to pick up their orders from the cook 8)

The all-Mexican staff off duty kept playing around. One guy was counting money on a table and some other coworker jumping around, actually standing on the sofa with his shoes on at once.

Also, funny how the waitress on the check wrote "service not included" below the amount.. as to demand for a tip.
It was $29, we gave her $32. A 10% tip ought to be enough for a service that actually deserved a -10% tip !

The burgers were average to insipid. Do not go to "Lori's Diner", it stinks big time !!

In the evening however, we had crab for dinner (company dinner). Pretty good, and so was the service ..though a cleaner managed to drop some crab on the boss of my boss 8)

ole'

Syndicate content