📜 ⬆️ ⬇️

Finished the game, working on the video card

Finally, I completed the game, which works on a video card. She hung in the early access to the incentive for several months, and now I have finally released it. The main feature of the game is that it is a physical simulation, which is performed on the graphics processor. The main code of the game is a huge compute shader, 6 thousand lines on HLSL. Tens of thousands of interacting particles are processed in parallel, and goes pretty quickly. Everything in the game is made of these particles. Here are some gifs about how this works:

image

image

image
')
I want to sum up the experience of developing this kind of game. What are the advantages and disadvantages of computing on a video card?

Advantages:

1. GPU performance is 10-100 times higher than that of the processor when it comes to parallel computing. This is a lot, so you can make fundamentally different games on the video card than on the processor. My game simply would not work on the CPU (i.e., would be too slow).

Disadvantages:

1. Few tutorials. I spent quite a lot of time to learn everything. And even more - to solve the problems.

2. It is in principle more difficult to program for the graphics core. Habitual for processor computing things may not work. For example, instead of a three-dimensional loop on a three-dimensional array, I had to organize a three-dimensional space of threads that simultaneously process a one-dimensional array (into which the original three-dimensional array had to be expanded). In addition, care must be taken that parallel threads work with shared data in protected mode. In general, all this is solved, but takes more time.

3. Problems arose when reading data from video memory. This had to be done on each cycle, but it worked too slowly. Since there was no asynchronous reading in the unit at a convenient time for the graphics pipeline, it was permanently blocked while reading the data. As a result, fps fell by half. I had to use the native plugin for asynchronous reading from the video memory using directX, but firstly, it did not work outside of windows, and secondly, for unknown reasons, it did not work on some video cards, players complained.

4. Not everyone has enough modern graphics cards that support shaders and have sufficient performance. This limited the number of players who can play my game. And those who were slowed down were not averse to writing negative feedback in Steam.

5. Graphic APIs on different platforms are slightly different from each other. In simple cases, they are compatible with the directX standard, but for me it is not an easy case, I have come close to many limits. For example, in DX11, one kernel can work only with eight buffers. And the Android API has only four. Metal also has its limitations, such as the absence of a protected record in the overall texture for streams, and Vulkan has some other limitations. As a result, the game only works on Windows.

6. It was not possible to make the calculations deterministic, so I had to do without multiplayer. Although, theoretically, it is clear: everything must be done on ints, and the results on each cycle should not depend on the order of the flows (which may differ from time to time under the same conditions). But my experiments have not yet led to deterministic calculations.

But in the end, I'm still pleased that I did what I wanted.

As a player, it was very interesting for me to see what it was like to play a game that is completely physical, so that everything would be destroyed. Perhaps in the future I will try to portray something like this in 3D.

As a game designer, it was interesting to play with physics, try to create a unique gameplay, impossible outside of physical simulation.

And as a programmer it was useful to acquire the skills of computing on the GPU. I think in the future this will be more, too good a performance gain. Although it would be nice to start with, if all graphic APIs were compatible with the standard directx11. It is not necessary to do the whole game on the GPU, you can transfer some parts of the game for processing into a video processor. For example, finding a path in strategies. And now not any developer will be ready to write a compute shader, if you still have to duplicate it, in case the game is running on a platform that does not support computing on a video card.

Well, if someone suddenly wants to try their hand at this area, here are a couple of tutorials, they once opened the way for me in this area:

The first
Second

Source: https://habr.com/ru/post/345104/


All Articles