Accessing Resources
There are several ways to access resources. Regardless, Direct3D guarantees to return zero for any resource that is accessed out of bounds.
Access By Byte Offset
Two new buffer types can be accessed using a byte offset:
- ByteAddressBuffer is a read-only buffer.
- RWByteAddressBuffer is a read or write buffer.
Access By Index
Resource types can use an index to reference a specific location in the resource. Consider this example:
uint2 pos; Texture2D<float4> myTexture; float4 myVar = myTexture[pos];
This example assigns the 4 float values that are stored at the texel located at the pos position in the myTexture 2D texture resource to the myVar variable.
Access By Mips Method
Texture objects have a mips method (for example, Texture2D.mips), which you can use to specify the mipmap level. This example reads the color stored at (7,16) on mipmap level 2 in a 2D texture:
uint x = 7; uint y = 16; float4 myColor = myTexture.mips[2][uint2(x,y)];
This is an enhancement from the June 2010 compiler and later. The "myTexture.mips[2][uint2(x,y)]" expression is equivalent to "myTexture.Load(uint3(x,y,2))".
Related topics