2

In Vulkan, a memory resource is accessed via "pointer-like" metadata contained in a "view", which describes how the memory resource should be interpreted. A descriptor is data which specifies to a shader "where" this memory will be located.

In DirectX 12, a resource is short for "memory resource" (see: https://www.3dgep.com/learning-directx12-1/). A resource view is a wrapping around a resource which allows specific usage. For instance, a "shader resource view" (SRV) allows the resource to be accessed by a shader, while a "unordered access view" is similar to a SRV, except it allows for the data to be accessed in any order.

A "constant buffer view" (CBV) allows shaders to access data which will be more persistent/constant than usual. The DirectX 12 docs don't seem to differentiate between a CBV and a constant buffer. For example, the article titled "Constant Buffer View" says:

Constant buffers contain shader constant data. The value of them is that the data persists, and can be accessed by any GPU shader, until it is necessary to change the data.

The word "view" is not mentioned anywhere, almost as if there is no difference between a resource, and a resource view. Another place where this happens in the docs is in the article on resource bindings:

The most common resources are:

  • Constant buffer views (CBVs)
  • Unordered access views (UAVs)
  • Shader resource views (SRVs)
  • Samplers

When listing common resources, the article mentions resource views, again as if they are the same thing.

What is the difference between a resource, and a resource view in DirectX 12?

bzm3r
  • 3,113
  • 6
  • 34
  • 67

2 Answers2

5

In DirectX, a resource is the data that you'll be using to render. For example a texture or a buffer (like a vertex buffer). Then, similar to Vulkan, you have to let the graphics driver know how to interpret these resources. For instance, you can store 4-byte chunks into a buffer and then read from it as if it where a buffer of float values. This is where "views" come in. A view (in DX12 also called a descriptor) is a pointer-like description of the way the resource it's pointing to will be bound to the pipeline. Except vertex-buffers and index-buffers (and constant buffers in some cases), you pretty much always have to bind a resource by using a view (descriptor). This process is called resource binding.

It's important to know that the same resource can be bound (i.e described) by different views. For example, you can define a SRV for a texture and another for one of its Mipmaps, and a UAV to the same texture for writing to it in a compute shader.

Resource binding is the main process by which resources are used/manipulated in D3D11/12. It's not that difficult to wrap your head around, but is too lengthy to describe in its entirety here. You can read more about it in MS documentation.

rashmatash
  • 1,699
  • 13
  • 23
0

It's analogous to std::vector vs std::span.

A resource is memory on the heap. A view interprets a given resource.

Its about the architecture. DX12 works with arrays of views called descriptor heaps (i.e. std::array<std::span>). Its like working with an array of pointers rather than working an array of objects (std::array<std::variant<A*, B*, C*>> vs std::array<std::variant<A, B, C>>) so that rearrangement is cheap and resources can be vastly different sizes.

Tom Huntington
  • 2,260
  • 10
  • 20