CPU Texture Compositing with InstantAccess



The InstantAccess, also known as Direct Resource Access (DRA), extension that Intel has implemented for 4th Generation Intel® Core™ processors Iris™ and Iris™ Pro graphics allows direct access to memory allocated on the GPU. The extension provides a mechanism for specifying which buffers will be shared and locking the memory for reading and writing from CPU side code. This sample updates the existing CPU Texture Compositing sample to use the InstantAccess extension for the composited textures.


The InstantAccess extension provides a mechanism for directly reading from and writing to buffers that are allocated for the GPU. The extension requires some additional set up code and overrides the D3D functions CopyResource and Map. To utilize the extension, some host-side initialization code is required. Sample code is provided in the IGFXExtensionsHelper.h/cpp files. Before using any extension, the Init function must be called.

To utilize InstantAccess, two buffers are created, each with a call to SetDirectAccessResouceExtension immediately before the buffer creation calls. One buffer is created as a normal, but the call to SetDirectAccessResouceExtension marks it as lockable from the CPU. The other buffer is created as a staging buffer, but the call to SetDirectAccessResouceExtension means that the buffer will be used for InstantAccess. Finally, the D3D CopyResource function is called with the two buffers as parameters to bind them together.

To get CPU-side access to the resource, the application calls the D3D Map function on the staging buffer. The data returned in the D3D11_MAPPED_SUBRESOURCE structure is RESOURCE_SHARED_MAP_DATA structure. This new structure contains information about the GPU resource including the CPU-side pointer to the memory.

Sample Implementation

The terrain is broken into tiles where each tile composites 5 diffuse and 5 normal map textures together based on a blend texture that spans the entire terrain. The 9 tiles that surround the camera will use a one diffuse texture and one normal texture that are pre-composited on the CPU.

The original sample composites textures together asynchronously into staging textures. The main thread maps the staging textures and creates the tasks for compositing. The main thread checks each frame if any textures have finished compositing. The main thread unmaps the staging textures and calls CopyResource to copy the texture from the staging resource to the standard Texture2D resource. The copy uses the graphics execution units to perform a swizzle from the linear memory for mat of the staging buffer to the tiled format used by texture resource.

The new InstantAccess pass is very similar, but instead of writing into a staging buffer, the task copies and swizzles the composited texture directly into the texture memory. This avoids the synchronous copy and performs the swizzle by the CPU saving valuable execution unit time.

Iris is a trademark of Intel Corporation in the U.S. and/or other countries.

Pour de plus amples informations sur les optimisations de compilation, consultez notre Avertissement concernant les optimisations.