Pipeline state creation
For example usage of these APIs, see Mesh Shader pipeline usage. The following code example shows the Mesh Shader feature support APIs.typedef enum D3D12_FEATURE {
...
D3D12_FEATURE_D3D12_OPTIONS7,
} D3D12_FEATURE;
typedef enum D3D12_MESH_SHADER_TIER
{
D3D12_MESH_SHADER_TIER_NOT_SUPPORTED,
D3D12_MESH_SHADER_TIER_1
} D3D12_MESH_SHADER_TIER;
typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS7
{
_Out_ D3D12_MESH_SHADER_TIER MeshShaderTier;
_Out_ D3D12_SAMPLER_FEEDBACK_TIER SamplerFeedbackTier;
} D3D12_FEATURE_DATA_D3D12_OPTIONS7;
HRESULT ID3D12Device::CheckFeatureSupport(
D3D12_FEATURE Feature,
void* pFeatureSupportData,
UINT FeatureSupportDataSize
);
typedef struct D3D12_PIPELINE_STATE_STREAM_DESC {
_In_ SIZE_T SizeInBytes;
_In_ void* pPipelineStateSubobjectStream;
} D3D12_PIPELINE_STATE_STREAM_DESC;
HRESULT ID3D12Device2::CreatePipelineState(
const D3D12_PIPELINE_STATE_STREAM_DESC* pDesc,
REFIID riid,
void** ppPipelineState
);
void ID3D12GraphicsCommandList::DispatchMesh(uint groupCountX, uint groupCountY, uint groupCountZ);
typedef enum D3D12_INDIRECT_ARGUMENT_TYPE {
...
D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH
} D3D12_INDIRECT_ARGUMENT_TYPE;
typedef struct D3D12_INDIRECT_ARGUMENT_DESC
{
D3D12_INDIRECT_ARGUMENT_TYPE Type; // = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH
union
{
...
struct
{
UINT ThreadGroupCountX;
UINT ThreadGroupCountY;
UINT ThreadGroupCountZ;
} D3D12_DISPATCH_MESH_ARGUMENTS;
}
} D3D12_INDIRECT_ARGUMENT_DESC;
void ID3D12GraphicsCommandList::ExecuteIndirect(
ID3D12CommandSignature* pCommandSignature,
UINT MaxCommandCount,
ID3D12Resource* pArgumentBuffer,
UINT64 ArgumentBufferOffset,
ID3D12Resource* pCountBuffer,
UINT64 CountBufferOffset
);
struct MyPsoStreamDesc
{
CD3DX12_PIPELINE_STATE_STREAM_ROOT_SIGNATURE pRootSignature;
CD3DX12_PIPELINE_STATE_STREAM_AS AS;
CD3DX12_PIPELINE_STATE_STREAM_MS MS;
CD3DX12_PIPELINE_STATE_STREAM_PS PS;
CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC BlendState;
CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL1 DepthStencilState;
CD3DX12_PIPELINE_STATE_STREAM_RASTERIZER RasterizerState;
CD3DX12_PIPELINE_STATE_STREAM_RENDER_TARGET_FORMATS RTFormats;
CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL_FORMAT DepthFormat;
CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_DESC SampleDesc;
CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_MASK SampleMask;
}
void CreatePipelineState(ID3D12Device* d3dDevice)
{
// Check Mesh Shader pipeline feature support.
D3D12_FEATURE_DATA_D3D12_OPTIONS7 options;
device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &options, sizeof(options));
if (options.MeshShaderTier == D3D12_MESH_SHADER_TIER_NOT_SUPPORTED)
throw std::exception("Mesh Shaders not supported!");
// Set up PSO Stream Desc.
MyPsoStreamDesc psoDesc;
psoDesc.AS = D3D12_SHADER_BYTECODE{ ... };
psoDesc.MS = D3D12_SHADER_BYTECODE{ ... };
...
// Create Pipeline State Object with stream desc.
D3D12_PIPELINE_STATE_STREAM_DESC desc = { sizeof(psoDesc), &psoDesc };
device->CreatePipelineState(&desc, IID_PPV_ARGS(&msPso));
}
void Draw(ID3D12GraphicsCommandList* commandList)
{
// Set up pipeline and root signature parameters.
commandList->SetPipelineState(&msPso);
commandList->SetGraphicsRootSignature(&msRootSig);
...
// Dispatch threadgroups.
commandList->DispatchMesh(someGroupCount, 1, 1);
}
Mesh Shader intrinsics
Attributes
| Name | Description |
|---|---|
| OutputTopology | Specifies the primitive type exported by the shader - either “line” or “triangle.” Must match the indices shared output array type (uint2 for lines or uint3 for triangles). |
Functions
| Name | SetMeshOutputCounts |
| Parameters | uint numVerts uint numPrims |
| Description | Declares the threadgroup’s number of vertices and primitives to export - counts default to zero if not called. Must be less than or equal to the shared output array lengths and called from non-divergent execution context and assumes threadgroup-constant parameter values. Must precede all writes to output arrays. |
Parameters
| Name | Modifier | Description |
|---|---|---|
| payload | in | Custom-typed payload data of up to 16 KB passed from an Amplification Shader to its cluster of Mesh Shader instances. This data is shared among all instances in the cluster. Not applicable if no Amplification Shader stage precedes the Mesh Shader in the pipeline. |
| vertices array | out | The shared output array in which to export vertex attributes. Defines the custom vertex attribute type and the maximum vertex export count by array length. |
| indices array | out | The shared output array in which to export primitive indices. Defines the primitive type to export and the maximum primitive export count by array length. These primitive indices index directly into the vertices array. The type should be uint2 for lines or uint3 for triangles. |
| primitives array | out | The shared output array in which to export primitive attributes. Defines the user-defined primitive attribute type. Its length must be equal to that of the indices array. |
Amplification Shader intrinsics
Functions
| Name | DispatchMesh |
| Parameters | uint groupsX uint groupsY uint groupsZ groupshared payload_t payload |
| Description | Dispatches a cluster of Mesh Shader threadgroups with optional payload data. Can be called at most one time from a non-divergent code path. Zero threadgroups are dispatched if not called. The subsequent Mesh Shader threadgroups have their GroupIDs and DispatchThreadIDs localized to its own cluster. |
