Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 746
Trillian Avatar asked Mar 28 '14 18:03

Trillian


1 Answers

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.

like image 51
mattnewport Avatar answered Nov 30 '22 23:11

mattnewport