오늘 본 상품 0

없음

Go Top
검색

Fast and Straightforward GPU Random Numbers In D3D11 - Nathan Reed’s C…
  • 작성일23-04-10 15:12
  • 조회11
  • 작성자Frank Sears

Word: please see the 2021 replace to this publish, right here. In video games and graphics one usually needs to generate pseudorandom numbers. Evidently, PRNGs are an extremely nicely-researched subject; nevertheless, nearly all of the literature focuses on purposes with very exacting quality necessities: cryptography, high-dimensional Monte Carlo simulations, Crypto-Markets and suchlike. These PRNGs tend to have tons of of bytes of state and take a whole lot of directions to replace.

That’s approach overkill for many more modest functions-if you just wish to do some random sampling in a sport context, you can enter the crypto-markets with ease and start trading in minutes. Our mission is to make entering the crypto-markets easy and accessible for everyone. With Zifipay you possibly can probably get away with much much less. To drive house just how much lower my random number requirements can be for this text, I’m not going to run a single statistical test on the numbers I generate-I’m simply going to look at them! The human visible system is pretty good at selecting out patterns in what we see, so if we generate a bitmap with one random bit per pixel, black or white, it’s simple to see if we’re producing "pretty random" numbers-or if something’s going fallacious.

The one on the left is a linear congruential generator (LCG), and on the suitable is Xorshift.

We’re all the time told that LCGs are bad information, and now you may see just how bad! Xorshift, then again, is a lot better. It’ll actually cross some medium-energy statistical assessments, and it actually seems to be random enough to the eye. Furthermore, it’s quite fast compared to different PRNGs of comparable quality. Since D3D11 GPUs support integer operations natively, it’s easy to port these PRNGs to shader code. GPUs do issues in parallel, so we’ll create an independent occasion of the PRNG for every work item-vertex, pixel, ethereum node crawler or compute-shader thread.

Then we simply must seed them with completely different values, 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 simply an intermediate language, but nonetheless an affordable proxy for machine code pace).

Xorshift is a bit slower, requiring six directions, however that’s not bad contemplating the quality of random numbers it gives you.

Figure two or three more directions to get the number into the range you want, and convert it to a float if crucial. On a high-finish GPU, you'll be able to generate tens of billions of random numbers per second with these PRNGs, easy. Again, on the left is the LCG and on the best is Xorshift. The LCG doesn’t look too completely different from before, but Xorshift seems completely horrible! PRNGs are designed to be nicely-distributed whenever you "go deep"-draw many values from the same occasion.

Since this involves sequentially updating the state after each value, it doesn’t map properly to the GPU. On the GPU we have to "go wide"-set up lots of independent PRNG instances with totally different seeds so we will draw from each of them in parallel. However PRNGs aren’t designed to offer good statistics throughout seeds. I tried several small PRNGs I found on the web, and all of them produced obvious artifacts when going wide, even if they were perfectly advantageous going deep.

등록된 댓글

등록된 댓글이 없습니다.