Why does Direct3D 11 make a distinction between SRVs and UAVs?
Asked Answered
P

1

8

I have been playing with Direct3D 11 and was surprised to discover that an HLSL StructuredBuffer<T> must be bound to a Shader Resource View (SRV) whereas a RWStructuredBuffer<T> must be bound to a Uniform Access View (UAV). Looking deeper into this, it seems like all read-write shader resources require UAVs whereas readonly resources require SRVs.

Comparing the UNORDERED_ACCESS_VIEW_DESC and SHADER_RESOURCE_VIEW_DESC structures, UAVs are described with more or less a subset of the information to describe SRVs. The APIs to set UAVs and SRVs to pipeline stages are also very similar. Even the documentation of the two interfaces look like the same concept explained by two different technical writers:

  • SRV: A shader-resource-view interface specifies the subresources a shader can access during rendering.
  • UAV: A view interface specifies the parts of a resource the pipeline can access during rendering

I'm not very well-versed in D3D11, but it seems to me that the concept of UAVs complicates the API without much benefit. Does the distinction between SRVs and UAVs exist to better map to the hardware or because of technical restrictions? Or was it just an API design decision?

Perigee answered 28/3, 2014 at 18:59 Comment(0)
A
4

The distinction was probably introduced primarily for performance reasons. The performance characteristics of data that is only accessed for read are quite different from data that can be accessed for arbitrary writes combined with reads.

It's likely that on most hardware the memory backing the resources should be allocated in different types of memory for best performance and have different parameters determining things like how it is cached, how it is swizzled / tiled, aligned, etc. By separating the concepts at the API level the driver can be given more information on the intended usage of a resource when it is created and again when it is bound.

Ageratum answered 31/3, 2014 at 20:10 Comment(3)
Hmm... As I understand it, the memory pool a buffer ends up in is based on the flags it was created with, not the views that were created for its data. Views for an existing buffer can be created at any time, so they should not impact where the buffer's memory is.Perigee
The pools are a Direct3D 9 artifact, views are like finer grained control inside those pools. PS : UAVs are the only thing that gets outputed from a compute shader.Pandurate
Apparently also cause UAVs are not supported by tile-baser renderers in vertex shaders: mobile.twitter.com/SebAaltonen/status/1538138059706875906Arvind

© 2022 - 2024 — McMap. All rights reserved.