Developer knowledge network · moderated exchange

UnreliableCode 커뮤니티

개발자 연구, 리버스 엔지니어링 및 코딩 커뮤니티

Knowledge index살다
4Categories
919Threads
2.8K게시물
Tutorial

Writing High-Performance Compute Shaders in HLSL for 1,000,000 Particle Physics Simulation [StackOverflow Architecture Guide]

shader_magician
HLSL / GLSL Dev
MEMBER
대표: 176
가입 날짜: Jan 2021
게시물: 8
감사해요: 32
1개월 전 · Jul 11, 2026 7:40 AM
#1

Simulating 1M particles on GPU compute shader threads in HLSL:

HLSL
struct Particle { float3 position; float3 velocity; float life; };
RWStructuredBuffer<Particle> Particles : register(u0);

[numthreads(256, 1, 1)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
    if (id.x >= 1000000) return;
    Particle p = Particles[id.x];
    p.velocity += float3(0, -9.81, 0) * 0.016;
    p.position += p.velocity * 0.016;
    p.life -= 0.016;
    Particles[id.x] = p;
}

Dispatched via Dispatch(1000000 / 256 + 1, 1, 1). Simulates 1,000,000 particles in < 0.4 milliseconds on modern GPUs!

graphics_pipeline_pro
DirectX / Vulkan Engineer
MEMBER
대표: 172
가입 날짜: Sep 2018
게시물: 10
감사해요: 51
1개월 전 · Jul 11, 2026 12:41 PM
#2

numthreads(256, 1, 1) provides optimal warp/wavefront occupancy across NVIDIA (32-thread warps) and AMD (64-thread wavefronts).

simd_vector_ace
SIMD & Intrinsics
MEMBER
대표: 151
가입 날짜: May 2020
게시물: 8
감사해요: 36
1개월 전 · Jul 11, 2026 4:35 PM
#3

Direct compute simulation avoids reading particle buffers back to CPU RAM across PCIe.