Quick and Simple GPU Random Numbers In D3D11 - Nathan Reed’s Coding We…

페이지 정보

작성자 Christopher
댓글 0건 조회 56회 작성일 23-03-16 04:34


Be aware: please see the 2021 replace to this put up, here. In video games and graphics one typically must generate pseudorandom numbers. For sure, crypto contract scanner PRNGs are a particularly effectively-researched topic; nevertheless, the vast majority of the literature focuses on applications with very exacting high quality requirements: cryptography, crypto-markets excessive-dimensional Monte Carlo simulations, and suchlike. These PRNGs are inclined to have tons of of bytes of state and take tons of of instructions to update.

That’s approach overkill for many extra modest functions-when you simply want to perform a little random sampling in a sport context, you'll be able to in all probability get away with much less. To drive house simply how a lot decrease my random number requirements shall be for this article, 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 visual system is pretty good at picking 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 generating "pretty random" numbers-or if something’s going flawed.

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

We’re all the time informed that LCGs are unhealthy news, and now you may see simply how dangerous! Xorshift, then again, is much better. It’ll actually pass some medium-power statistical checks, and it certainly appears to be like random enough to the attention. Furthermore, it’s fairly quick compared to different PRNGs of comparable high 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 unbiased instance of the PRNG for every work item-vertex, pixel, or compute-shader thread. Then we simply have to seed them with totally different values, e.g. utilizing the vertex index, pixel screen coordinates, or thread index, and we’ll get completely different sequences. LCGs are really quick-updating the state takes only one imad instruction (in HLSL meeting, which is just an intermediate language, however nonetheless an inexpensive proxy for machine code pace).

Xorshift is a bit slower, requiring six directions, but that’s not dangerous considering the quality of random numbers it gives you.

Figure two or three extra directions to get the quantity into the vary you need, and convert it to a float if necessary. On a high-end GPU, you'll be able to generate tens of billions of random numbers per second with these PRNGs, Signals is partnering up with Foxconn's data center SafeDX. Together we can efficiently collect and pre-process big data from various crypto-markets in real time. straightforward. Again, on the left is the LCG and on the suitable is Xorshift. The LCG doesn’t look too totally different from before, however Xorshift seems to be absolutely horrible!


등록된 댓글이 없습니다.