Graphics Reference
In-Depth Information
d3dApp = new D3DApp(this);
d3dApp.Initialize();
}
3.
Within the D3DApp class, we update the CreateDeviceDependentResources
signature to include the async keyword as shown in the following snippet:
protected async override void
CreateDeviceDependentResources(Common.DeviceManager
deviceManager)
{
...
}
4.
Now when we compile our shaders, load our meshes, or initialize our renderer
instances, we can do something like the following code snippet:
// Compile shader, the event caller will continue executing
using (var bytecode = await HLSLCompiler.
CompileFromFileAsync (@"Shaders\VS.hlsl", "VSMain", "vs_5_0"))
{ ... }
// Load mesh
var meshes = await Mesh. LoadFromFileAsync ("Character.cmo");
// Other CPU-bound work
await Task.Run(() =>
{
... (e.g. initialize renderers)
});
Awaiting an asynchronous operation means that although our event
handler runs on a background thread, the logic within it still runs
in a synchronous manner. Where appropriate, we can also start
multiple tasks to take advantage of parallel processing (for example,
to initialize multiple renderers upon separate threads).
5.
A full example of the CompileFromFileAsync function from the previous snippet is
shown in the following code snippet:
public static async Task<ShaderBytecode>
CompileFromFileAsync(string hlslFile, string entryPoint,
string profile, ShaderMacro[] defines = null)
{
if (!Path.IsPathRooted(hlslFile))
hlslFile = Path.Combine(Windows.ApplicationModel
.Package.Current.InstalledLocation.Path,
 
Search WWH ::




Custom Search