Direct3D 12 on Xbox One (D3D12.x) has some notable differences from Direct3D 12 on Windows PC (D3D12/PC).
typedef for the copy command list interface, which would be defined as ID3D12XboxDmaCommandList on Xbox One and defined as ID3D12GraphicsCommandList on PC.With the XDK, there are three drivers that can be used to help test and debug a title:
Retail driver
Optimized for performance, not instrumentation or debugging. Doesn’t check the correctness of parameters; incorrect parameters passed to the retail driver are likely to cause corruption, crashes, or GPU hangs. Titles can only ship on the retail driver; the other drivers (instrumented and debug) are only present on development kits.
Instrumented driver
Enables PIX instrumentation. Fairly lightweight. Can be used to help debug sync and other timing issues. Doesn’t check the correctness of parameters.
Debug driver
Performs validation testing on parameters that are passed to the API calls, which can help debug correctness and performance issues. However, timing bugs might not be reproduced when using the debug driver, because the validation processing affects runtime performance. To adjust the level of validation, call ID3D12Device::SetDebugFlagsX.
To select which driver is used, call one of the following methods:
An offline PSO enables considerable performance improvements over runtime creation of pipeline state, by encapsulating the pipeline state (including shaders) into a single object that can be loaded and set quickly. An offline PSO stores state for precompiled shaders, render target, and depth stencil.
Offline PSO objects are stored on disk and are later loaded by the app when needed. On the PC, there is a similar but not identical system called PSO caching.
To create offline PSO objects, either use the PhSO tool (which is provided as an XDK sample located in the XDK \bin folder), or write your own tool that uses the pipeline state serialization APIs, which are listed below.
The following APIs manipulate offline PSOs:
umd12_pc.dll) and is not intended to be called at run-time of a title.Given the larger number of changes of pipeline state than an app will probably require, it does not make sense to create offline PSOs for each variation. Instead, create an offline PSO for a commonly used basic state, then use Derived PSOs to make limited modifications to the offline PSO. The modifications made to the offline PSO cannot involve changes to the shader or render target.
For a typical game, the majority of PSO objects should be created offline, with permutations made at run-time using the following APIs.
If the source PSO was created by calling ID3D12Device::DeserializeGraphicsPipelineStateX, it is the app’s responsibility to ensure that the GPU instructions persist for the lifetime of both the original object and the derived object. If the source PSO was created using the standard D3D12 method ID3D12Device::CreateGraphicsPipelineState, D3D12.x automatically adds a reference count to the source object to ensure that its GPU instructions persist for the lifetime of the derived object.
The following D3D12.x sample uses offline PSOs and derived PSOs:
The following D3D12.x samples use offline PSOs:
See Graphics Samples or Running the XDK Samples.
On the Windows PC, descriptor heaps created with D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE cannot be used as the source for descriptor copies.
On Xbox One, descriptor copies that are created with ID3D12Device::CopyDescriptors and ID3D12Device::CopyDescriptorsSimple support all descriptor heaps for the source heap, and the copy is performed via an efficient cached read-only view for the source heap.
Indirect arguments resources can specify D3D12XBOX_RESOURCE_FLAG_ALLOW_INDIRECT_BUFFER at resource creation time. Resources with this flag can be transitioned into the D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT resource state. D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT is not included in the D3D12_RESOURCE_STATE_GENERIC_READ combination resource state on Xbox One.
On Xbox One, D3D12_RESOURCE_STATE_GENERIC_READ is declared as follows:
D3D12_RESOURCE_STATE_GENERIC_READ =
D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER |
D3D12_RESOURCE_STATE_INDEX_BUFFER |
D3D12_RESOURCE_STATE_COPY_SOURCE |
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE |
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE
In contrast, on D3D12/PC, D3D12_RESOURCE_STATE_GENERIC_READ is declared to include D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT, in addition to the above values.
See D3D12_RESOURCE_FLAGS and D3D12_RESOURCE_STATES.
A resource barrier notifies the driver that synchronization of multiple accesses to a single resource may be required, such as synchronizing reading and writing to the same texture.
The Xbox One XDK version of ID3D12GraphicsCommandList::ResourceBarrier supports the combination of D3D12_RESOURCE_STATE_COPY_SOURCE and D3D12_RESOURCE_STATE_COPY_DEST flags, so that intra-resource copies are supported. Intra-resource copies are where the source and destination are in the same subresource of the same resource.
On Xbox One, resource barriers are implemented by calling the following methods:
On Windows PC, resource barriers can perform conservative GPU idles and flushing/invalidation of caches. In contrast, on Xbox One, resource barriers perform conservative synchronization, invalidation, and decompression on usage transitions.
As part of this difference, there are recommended, but not essential, Xbox-specific resource creation flags:
These flags are Xbox One D3D12.x extensions, as D3D12_RESOURCE_FLAGS enumeration constants.
The following resource usage types inhibit decompression on resource barrier transitions, and allow resources to be consumed in a compressed state:
There is a corresponding set of PRESERVE_EXPANDED flags which, as counterparts to the PRESERVE_COMPRESSED flags, serve to keep resources in decompressed state after a transition that would ordinarily re-enable compression on them:
As an example, D3D12XBOX_RESOURCE_STATE_PRESERVE_EXPANDED_COLOR could be used when switching from a read state on a multisampled resource to a D3D12_RESOURCE_STATE_RENDER_TARGET state as a means of preventing new writes to the target being stored compressed.
Both these sets of flags are Xbox One D3D12.x extensions, as Xbox-specific D3D12_RESOURCE_STATES enumeration constants.
On Xbox One, the recommended approach to performing barrier transitions, beyond the D3D12/PC approach, is to identify barriers which involve transition from usage states which include write access, to usage states which do not include write access. These barriers, when performed on D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES should be divided into a split barrier, with a BEGIN_ONLY and END_ONLY call, when independent GPU work is available for execution, as follows.
BEGIN/END flags can be used with the D3D12_RESOURCE_BARRIER_TYPE_UAV type.
D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, mentioned above, is a #define value, for D3D12.x and D3D12/PC.
See D3D12_RESOURCE_BARRIER_FLAGS.
The row pitch alignment on the Xbox is 1024 bytes, not 512 as on the PC (this is defined by setting D3D12XBOX_TEXTURE_DATA_PITCH_ALIGNMENT to 1024). Also the requirement of the PC for buffers to be 64KB/4MB aligned does not apply to the Xbox, even though validation code might still show an error if these alignments are not adhered to.