UAV
UAV (Unordered Access View) is a mechanism in the Direct3D and Vulkan APIs that allows shaders to write data to GPU memory resources without a strict access sequence. Unlike traditional buffers and textures, which are read-only in pixel and vertex shaders, UAVs support simultaneous reading and writing from multiple shader threads.
Key Features of UAV
- Arbitrary Access – Data can be read and written in any order, making UAVs ideal for parallel computations.
- Support for Multiple Resource Types – UAVs can be applied to textures, buffers, and other GPU memory resources.
- Usage in Compute Shaders – UAVs are widely used in Compute Shaders where large-scale data writes are required without a strict access structure.
- Compatibility with Different Pipeline Stages – In Direct3D 12 and Vulkan, UAVs can be used not only in Compute Shaders but also in Pixel and even Geometry Shaders.
Where Are UAVs Used?
- Physically-Based Lighting – Allows shaders to store intermediate global illumination calculations.
- Post-Processing – Effects such as Gaussian blur or depth of field can leverage UAVs to speed up computations.
- Texture Generation and Mapping – Used in techniques like Screen Space Reflections (SSR) or voxelization.
- Physics Simulations – Applied in processing dynamic systems such as particles or fluid dynamics.
Code Example
An example of creating a UAV for a buffer in Direct3D 12:
D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
uavDesc.Format = DXGI_FORMAT_UNKNOWN;
uavDesc.Buffer.FirstElement = 0;
uavDesc.Buffer.NumElements = elementCount;
uavDesc.Buffer.StructureByteStride = sizeof(MyStruct);
uavDesc.Buffer.CounterOffsetInBytes = 0;
device->CreateUnorderedAccessView(buffer, nullptr, &uavDesc, uavHandle);
Conclusion
UAV (Unordered Access View) is a crucial tool for GPU memory operations, providing flexibility in data writing and processing. Due to their power and versatility, UAVs are actively used in rendering, simulations, and other computationally intensive tasks.