Reputation: 605
Reading the book: "Practical Rendering and Computation with Direct3D 11", and looking for a definition online: https://learn.microsoft.com/en-us/windows/uwp/graphics-concepts/shader-resource-view--srv-
I am still confused on what a ID3D11ShaderResourceView is.
Keep in mind, that I am learning DirectX 11 to create a video game. With that in mind ...
What is a Shader Resource View? In what situations would you use a Shader Resource View? And most importantly, how do you use a Shader Resource View?
I am assuming you can use this resource inside your HLSL Code, but in the book I have not seen an example yet on how to do this, and in what generic way it is used for video game engines.
Thank you!
Upvotes: 4
Views: 8378
Reputation: 41067
In older version such as Direct3D 9, you had as single interface such as IDirect3DTexture9
, IDirect3DCubeTexture9
, or IDirect3DVolumeTexture9
which encapsulated both the image bits themselves and expected semantics of usage. This had special logic to make it work as a render target as well.
In Direct3D 10, this was split into two elements:
The resource (i.e. the image bits) like ID3DxxTexture1D
, ID3DxxTexture2D
, and ID3DxxTexture3D
The semantics of usage which is either a ID3DxxShaderResourceView
which is used to read a texture in a shader -or- ID3DxxRenderTargetView
which is used to render to a texture. There is also a ID3D11UnorderedAccessView
for working with DirectCompute.
The advantage of the newer design is that you can have a single ID3DxxTexture2D
resource and have a SRV when using it to render, and a RTV when you are using it as a render texture. You can treat a cubemap as a 2D texture with an array size of 6.
You might find the older documentation on Microsoft Docs helpful.
You should take a look at the DirectX Tool Kit tutorials
Upvotes: 9
Reputation: 349
So the real-life example would be shadows - basically you go through your geometry from lights position filling Depth Buffer, and then go through geometry from camera position and using data from Depth Buffer to calculate if pixel is in shadow or not. So *View in DirectX could be translated into "treat this resource as". In the first part, you will use the Texture as DepthStencilView ("treat this texture as Depth Stencil") and in the next part, you will use the same texture as input to the shader (ShaderResourceView, "treat this texture as Shader Resource).
This "transition" is very important in terms of resource synchronization. In DX11 this is done for you by the driver, in DX12 however you have to take care of this.
Upvotes: 4