Quick Reference
b# -> constant buffer
t# -> shader resource view
s# -> sampler state
u# -> unordered access viewRegister 번호는 shader stage마다 별도 namespace입니다. HLSL Texture2D albedo : register(t0)는 해당 stage의 *SetShaderResources(0, ...)와 맞춰야 합니다.
UAV 범위는 feature level에 따라 다릅니다. Direct3D 11.0의 Feature Level 11_0에서는 pixel·compute shader에서 최대 8개를 사용합니다. Feature Level 11_1은 모든 shader stage와 64개 UAV slot을 지원합니다. Device 생성 결과의 feature level을 확인한 뒤 이 범위를 선택하며, graphics UAV는 OMSetRenderTargetsAndUnorderedAccessViews, compute UAV는 CSSetUnorderedAccessViews로 연결합니다.
Material 바인딩
context->PSSetShaderResources(0, 1, albedoSrv.GetAddressOf());
context->PSSetSamplers(0, 1, sampler.GetAddressOf());
context->PSSetConstantBuffers(1, 1, materialBuffer.GetAddressOf());Frame·camera·light는 frame 단위, material은 material 변경 단위, object transform은 draw 단위처럼 갱신 빈도별 constant buffer를 나누면 불필요한 upload를 줄이기 쉽습니다. Slot 표는 C++과 HLSL이 함께 공유하는 header·reflection·검증 코드 중 하나로 관리합니다.
Hazard와 해제
같은 subresource를 SRV로 읽으면서 RTV·DSV·UAV로 쓰도록 동시에 묶을 수 없습니다. Pass 전환 때 이전 SRV를 null로 해제하고 output view를 연결합니다. Debug Layer의 automatic nulling 경고에 의존하지 않고 의도한 수명을 명시합니다.
자주 틀리는 점
- Texture를 binding하고 sampler를 빠뜨리지 않습니다.
- VS와 PS의 같은
t0을 같은 binding이라고 가정하지 않습니다. - Feature Level 11_0 장치에서 전 stage UAV나 64개 slot을 사용할 수 있다고 가정하지 않습니다.
- 선택 기능을 끈 draw에서 이전 object의 texture가 남지 않게 기본 resource를 연결합니다.
- UAV initial count가 counter resource에 미치는 영향을 확인합니다.
참고 링크
3 sources