The First Pixels
After successfully initializing DirectX 12 and establishing native resource ownership, the next milestone was getting Donatello to render its first image. The result is simple: a solid fuchsia viewport.

Although there is no geometry, lighting, or camera yet, this image is generated through a working DirectX 12 rendering path, with commands recorded in C++, executed by the GPU, and presented inside the WPF application. This marks the transition from initializing graphics resources to actually using them for rendering.
Hosting a Native Viewport in WPF
Integrating DirectX 12 into Donatello's WPF interface was the first challenge of this milestone. Since the application is written in C# while the rendering backend runs in a native C++ library, I needed a way to provide the renderer with a native window where it could present its output.
To solve this, I introduced ViewportHost, a WPF component that creates and embeds a native child window within the application's interface. Its window handle (HWND) is passed through the native API to the C++ backend, which uses it to create the swap chain and associated presentation resources. This approach keeps the editor layout under WPF's control while the native backend handles rendering and presentation.
Creating the Swap Chain and Render Targets
With ViewportHost providing a valid native window, I could move on to setting up the resources required for rendering and presentation. I created a DXGI swap chain configured with two back buffers, which provide the images used to render and display frames.
To make these buffers accessible as rendering destinations, I created a Render Target View (RTV) for each one and stored their descriptors in a dedicated descriptor heap. This allows the renderer to identify and bind the current back buffer as a render target, while the swap chain manages which buffer is used for presentation.
An RTV does not duplicate the image's contents; it describes how DirectX 12 should access the underlying resource when using it as a rendering destination.
Recording the First Rendering Commands
With the swap chain and render targets in place, the next step was recording the commands required to produce the first image. DirectX 12 follows an explicit command submission model, where rendering operations are recorded by the CPU and later submitted to the GPU for execution. To organize this process, I introduced CommandContext to manage the command allocator and command list, while CommandQueue handles submission and tracks GPU execution progress.
For this initial rendering test, the command list performs three operations: transitioning the current back buffer from PRESENT to RENDER_TARGET, clearing it to a solid fuchsia color using ClearRenderTargetView, and transitioning it back to PRESENT. These state changes require resource barriers to ensure the GPU accesses the back buffer correctly during rendering and presentation.

Once the commands have been recorded, the command list is closed and submitted to the queue for execution. Although the result is only a solid color, this establishes Donatello's first working DirectX 12 rendering path.

CPU and GPU Synchronization
Once the renderer could submit commands, I had to account for one of the fundamental aspects of DirectX 12: CPU and GPU execution is asynchronous. Submitting a command list does not guarantee that the GPU has finished processing it, so reusing command memory or releasing resources too early could cause problems. To handle this, I introduced fence-based synchronization, using a DirectX 12 fence to track GPU progress and a Windows event to let the CPU wait for a specific fence value.
For this first implementation, I chose a conservative approach that waits before reusing command memory and again after submitting the rendering commands, before presenting the image. While this introduces CPU stalls and prevents the renderer from taking full advantage of asynchronous execution, it makes the rendering sequence easier to understand and validate. More advanced synchronization, including multiple frames in flight, can be introduced as the rendering pipeline evolves.
Debugging the Rendering Pipeline
Bringing the first rendering pipeline to life also exposed a few debugging issues. At one point, Visual Studio stopped hitting breakpoints inside the native C++ code because the loaded DLL no longer matched its debugging symbols. Refreshing the build outputs resolved the problem, and I took the opportunity to improve the diagnostic messages produced during graphics initialization.
Donatello now logs the main stages of the setup process, from device and command queue creation to viewport initialization, swap-chain configuration, and command-context setup. Together with the DirectX 12 debug layer, these messages make it easier to identify where something goes wrong and understand what the graphics backend is doing as the renderer becomes more complex.
Results
By the end of this milestone, Donatello could:
Create and host a native rendering viewport within WPF.
Initialize a double-buffered DXGI swap chain with RTV descriptors.
Record and execute rendering commands through DirectX 12.
Manage resource transitions and GPU synchronization using barriers and fences.
Clear a render target and present the resulting image inside the application.
The final result is a working fuchsia viewport rendered through DirectX 12. For now, rendering occurs only once when the viewport is initialized, without a continuous render loop, camera, geometry, or automatic resize handling.
Nevertheless, the complete rendering path for a single frame is now operational, from the WPF interface and native API to GPU execution and presentation.
Key Takeaways
Getting the first pixels on screen required bringing together several systems that had previously been implemented or studied separately. Beyond creating a graphics device, I had to understand how swap chains, render targets, command submission, resource states, and synchronization interact to produce a frame.
One of the most important decisions was prioritizing correctness and predictability over performance during this initial implementation. Using explicit GPU waits and detailed diagnostics made the rendering sequence easier to follow and helped me establish a reliable starting point before introducing more complex frame management.
This milestone also reinforced the importance of keeping the graphics backend independent from the desktop interface, with both communicating through the native API.
What's Next?
The next step is to extend this initial rendering path into a continuous render loop and introduce proper viewport resizing.
These improvements will allow Donatello to render frames continuously, respond to changes in the editor layout, and provide the foundation for future viewport functionality.



Comments