Lecture 14: Pipeline setup in DX12

Computer graphics in Game development

Ivan Belyavtsev

24.06.2022

Rendering pipeline

From: https://docs.microsoft.com/en-us/windows/win32/direct3d12/pipelines-and-shaders-with-directx-12

Pipeline state object

PSO keeps a state of the rendering pipeline:

  • Input layout - data layout in vertex buffer
  • Root signature - definition what types of resources are bound to the pipeline
  • Shaders bytecode - compiled shaders
  • State of rasterizer - settings of the rasterizer
  • Blending state - how to blend new triangles with existing
  • Depth/stencil state - setup of depth function and test[1]

PSO doesn’t keep

  • Vertex and index buffers
  • Primitive topology
  • Render target and depth buffer
  • Particular root signature, descriptor heaps and tables [1]

Shaders

cbuffer ConstantBuffer: register(b0)
{
    float4x4 mwpMatrix;
}
struct PSInput
{
    float4 position : SV_POSITION;
    float4 color : COLOR;
};
PSInput VSMain(float4 position : POSITION, float4 normal: NORMAL, float4 ambient : COLOR0, float4 diffuse : COLOR1,  float4 emissive : COLOR2)
{
    PSInput result;
    result.position = mul(mwpMatrix, position);
    result.color = ambient;
    return result;
}
float4 PSMain(PSInput input) : SV_TARGET
{
    return input.color;
}

Descriptor tables and root signature

Root signature links command lists to the resources the shaders require.

Descriptor table hold a range of descriptor heap which is going to be bound to the root signature [1]

Lab: 3.05 load_assets: pipeline state creation

  1. Create a descriptor table and a root signature
  2. Compile shaders
  3. Setup a PSO descriptor and create a PSO

Command queues

Command queue allows to submit commands via command list and make the fence synchronization

  • ExecuteCommandLists for submitting command lists
  • Signal for setting a special value to the fence [1]

Command lists

Command list a set of GPU command which will executed

  • Reset transfers the command list to the record state
  • Close transfers the command list out of the record state [1]

Command allocator

A region of memory to keep a queue GPU commands.

Has one method Reset, which allows to re-use the memory for the next commands [1]

Lab: 3.06 Command list creation and population

  1. Create command allocators and a command list
  2. Implement populate_command_list method
  3. Implement render method

Synchronizations

Fence is an object of GPU-CPU synchronization [1]

command_queue->Signal(fence.Get(), prev_fence_value));

if (fence->GetCompletedValue() < prev_fence_value)
{
    //fence_event is a system handle for the fence
    ThrowIfFailed(fence->SetEventOnCompletion(prev_fence_value, fence_event));
    WaitForSingleObject(fence_event, INFINITE);
}

Lab: 3.07 Synchronization

  1. Implement wait_for_gpu method
  2. Implement move_to_next_frame method

References

1.
Satran M. et al. Direct3D 12 programming guide [Electronic resource]. 2019. URL: https://docs.microsoft.com/en-us/windows/win32/direct3d12/directx-12-programming-guide.
// reveal.js plugins