Реклама
Fast And Straightforward GPU Random Numbers In D3D11 - Nathan Reed’s Coding Blog
7-04-2023, 09:10 | Автор: KristyOToole | Категория: Книги
Fast And Straightforward GPU Random Numbers In D3D11 - Nathan Reed’s Coding BlogObserve: please see the 2021 replace to this post, here. In video games and graphics one often must generate pseudorandom numbers. Needless to say, PRNGs are an extremely well-researched matter; nonetheless, the vast majority of the literature focuses on purposes with very exacting quality requirements: cryptography, high-dimensional Monte Carlo simulations, and suchlike. These PRNGs are likely to have tons of of bytes of state and take a whole lot of instructions to update.

That’s approach overkill for many extra modest purposes-if you just wish to perform a little random sampling in a recreation context, you'll be able to in all probability get away with much much less. To drive home simply how a lot lower my random number standards can be for this text, I’m not going to run a single statistical check on the numbers I generate-I’m simply going to have a look at them!

The human visual system is pretty good at picking out patterns in what we see, crypto rest client tutorial so if we generate a bitmap with one random bit per pixel, black or white, it’s easy to see if we’re producing "pretty random" numbers-or if something’s going incorrect.

The one on the left is a linear congruential generator (LCG), and on the precise is Xorshift. We’re all the time informed that LCGs are unhealthy news, and now you may see just how dangerous! Xorshift, alternatively, is a lot better.

It’ll actually go some medium-strength statistical tests, and it actually appears random sufficient to the attention. Furthermore, it’s fairly quick in comparison with other PRNGs of related quality. Since D3D11 GPUs support integer operations natively, it’s simple to port these PRNGs to shader code. GPUs do things in parallel, so we’ll create an impartial instance of the PRNG for every work item-vertex, pixel, or compute-shader thread.

Then we just have to seed them with different values, crypto-markets e.g. utilizing the vertex index, pixel screen coordinates, or thread index, and we’ll get different sequences. LCGs are really quick-updating the state takes just one imad instruction (in HLSL meeting, which is just an intermediate language, however still an inexpensive proxy for machine code pace).

Xorshift is a bit slower, requiring six instructions, but that’s not dangerous contemplating the standard of random numbers it provides you.

Determine two or three more instructions to get the quantity into the vary you want, and convert it to a float if obligatory. On a high-end GPU, you can generate tens of billions of random numbers per second with these PRNGs, simple. Once more, on the left is the LCG and on the proper is Xorshift. The LCG doesn’t look too different from before, however Xorshift seems completely terrible! PRNGs are designed to be effectively-distributed when you "go deep"-draw many values from the identical occasion.

Since this includes sequentially updating the state after every value, it doesn’t map well to the GPU.
Скачать Skymonk по прямой ссылке
Просмотров: 19  |  Комментариев: (0)
Уважаемый посетитель, Вы зашли на сайт kopirki.net как незарегистрированный пользователь.
Мы рекомендуем Вам зарегистрироваться либо войти на сайт под своим именем.