**Wave Intrinsics Hello World** 2020/05/09 After work with DirectX 12 for a while, I need to do some validate on shader using [**Wave Intrinsics**](https://github.com/Microsoft/DirectXShaderCompiler/wiki/Wave-Intrinsics), so I created a playground program. To keep things simple, here are some decisions made in advance, - Wave Intrinsics - DirectX 12 - Shader Model 6.0+ - DirectXShaderCompiler (DXC) - Minimal setup - Console program - No window - No swapchain - No render loop - Compute Shader only - No descriptor heap - Minimum abstraction - No error handling (except shader compilation) - Debugging - Read back output through UAV - printf # Result Here is the repo [ComputeShaderPlayground](https://github.com/silvesthu/ComputeShaderPlayground) on Github. With only a cpp and a hlsl each. Suprisingly, console program run just well. The hlsl is just a placeholder, and structure of cpp is like, - Compile shader file to `IDxcBlob` - Initialize DirectX 12 with `IDXGIFactory4` -> `IDXGIAdapter1` -> `ID3D12Device2` - Create resources with `ID3D12Device2` - `ID3D12CommandQueue` - `ID3D12CommandAllocator` - `ID3D12GraphicsCommandList` - `ID3D12RootSignature` -> `ID3D12PipelineState` - `ID3D12Resource` as UAV - `ID3D12Resource` as Readback - Execute - `SetComputeRootSignature` - `SetPipelineState` - `Dispatch` - Copy UAV to Readback - Print - Wait for GPU with `ID3D12Fence` - Lock Readback and print its content ## Work with debugging tools It's not too surprising that Nsight won't capture this console program. So I created a branch [swap_chain](https://github.com/silvesthu/ComputeShaderPlayground/tree/swap_chain), which has a dummy swap chain on console window, and a loop to presents frames. # Disassembly & Shader Analayzer Not quite related to the hello world itself though, it is rather useful (also fun) to see how code is generated. To be able to throw shader file directly into analyzer, root signature is moved from cpp into HLSL. [Shader Playground](http://shader-playground.timjones.io/) provides most functionalities, however it does not support shader analyzers for Shader Model 6.0+ yet. [Pyramid](https://github.com/jbarczak/pyramid) is another choice. But as RGA requires AMD card for DX12 analysis, it turn to offline mode for Vulkan with HLSL->SPIR-V which may not reflect original code. # Reference - [DirectX-Graphics-Samples](https://github.com/microsoft/DirectX-Graphics-Samples) - Official samples by features - Abstraction and error handling make code difficult to read - [Learning DirectX 12 – Lesson 1 – Initialize DirectX 12](https://www.3dgep.com/learning-directx-12-1) - A thorough tutorial (even topics like resize, fullscreen, dpi are well covered) - A bit too long for lesson 1 - [Two Shader Compilers of Direct3D 12](https://asawicki.info/news_1719_two_shader_compilers_of_direct3d_12) - Usage of dxc and fxc, both online and offline [Back to Index](./../../../../index.html)