Convert Figma logo to code with AI

microsoft logoDirectX-Graphics-Samples

This repo contains the DirectX Graphics samples that demonstrate how to build graphics intensive applications on Windows.

5,962
2,015
5,962
87

Top Related Projects

One stop solution for all Vulkan samples

17,590

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2

14,858

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.

59,344

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

6,830

minimal cross-platform standalone C headers

Quick Overview

The microsoft/DirectX-Graphics-Samples repository is a collection of graphics samples and tools for DirectX 12. It provides developers with practical examples and resources to learn and implement advanced graphics techniques using Microsoft's DirectX 12 API. The repository serves as a valuable resource for game developers and graphics programmers working with modern Windows platforms.

Pros

  • Comprehensive collection of DirectX 12 samples covering various graphics techniques
  • Well-documented code examples with detailed explanations
  • Regular updates to keep up with the latest DirectX 12 features
  • Includes both basic and advanced samples suitable for different skill levels

Cons

  • Primarily focused on Windows platforms, limiting cross-platform development
  • Requires a good understanding of graphics programming concepts
  • Some samples may be complex for beginners to grasp immediately
  • Limited coverage of older DirectX versions (e.g., DirectX 11)

Code Examples

Here are a few short code examples from the repository:

  1. Initializing a Direct3D 12 device:
ComPtr<ID3D12Device> device;
HRESULT hr = D3D12CreateDevice(
    nullptr,
    D3D_FEATURE_LEVEL_11_0,
    IID_PPV_ARGS(&device)
);
  1. Creating a command queue:
ComPtr<ID3D12CommandQueue> commandQueue;
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;

device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&commandQueue));
  1. Creating a root signature:
CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
rootSignatureDesc.Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);

ComPtr<ID3DBlob> signature;
ComPtr<ID3DBlob> error;
D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error);
device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature));

Getting Started

To get started with the DirectX-Graphics-Samples:

  1. Clone the repository:

    git clone https://github.com/microsoft/DirectX-Graphics-Samples.git
    
  2. Open the solution file for the desired sample in Visual Studio.

  3. Build and run the sample project.

  4. Explore the code and comments to understand the implementation details.

  5. Modify the samples or use them as a reference for your own DirectX 12 projects.

Note: Ensure you have the necessary DirectX 12 development tools and SDKs installed on your system before running the samples.

Competitor Comparisons

One stop solution for all Vulkan samples

Pros of Vulkan-Samples

  • Cross-platform compatibility, supporting multiple operating systems and devices
  • More extensive and diverse sample collection, covering a wider range of graphics techniques
  • Active community contributions and regular updates

Cons of Vulkan-Samples

  • Steeper learning curve due to Vulkan's lower-level API
  • Potentially more complex setup and configuration process
  • Less integration with Windows-specific features and optimizations

Code Comparison

DirectX-Graphics-Samples:

ComPtr<ID3D12Device> device;
D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device));

Vulkan-Samples:

VkInstance instance;
vkCreateInstance(&createInfo, nullptr, &instance);
VkPhysicalDevice physicalDevice;
vkEnumeratePhysicalDevices(instance, &deviceCount, &physicalDevice);

Both repositories provide valuable resources for graphics programming, with DirectX-Graphics-Samples focusing on Windows and Xbox platforms, while Vulkan-Samples offers a more versatile, cross-platform approach. The choice between them depends on the target platforms and specific project requirements.

17,590

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2

Pros of Filament

  • Cross-platform support (Android, iOS, Windows, macOS, Linux)
  • Lightweight and optimized for mobile devices
  • Extensive documentation and examples

Cons of Filament

  • Less comprehensive feature set compared to DirectX Graphics Samples
  • Smaller community and ecosystem
  • Limited support for advanced graphics techniques

Code Comparison

Filament (C++):

FilamentApp& app = FilamentApp::get();
Renderer* renderer = app.getRenderer();
Scene* scene = app.getScene();
View* view = app.getView();

renderer->render(view);

DirectX Graphics Samples (C++):

ComPtr<ID3D12GraphicsCommandList> commandList;
device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, commandAllocator.Get(), nullptr, IID_PPV_ARGS(&commandList));

commandList->SetGraphicsRootSignature(rootSignature.Get());
commandList->RSSetViewports(1, &viewport);
commandList->RSSetScissorRects(1, &scissorRect);
commandList->DrawInstanced(3, 1, 0, 0);

Both repositories offer valuable resources for graphics programming, with DirectX Graphics Samples focusing on Microsoft's DirectX API and Filament providing a more portable solution. The choice between them depends on the specific project requirements and target platforms.

14,858

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.

Pros of bgfx

  • Cross-platform support for multiple graphics APIs (DirectX, OpenGL, Vulkan, etc.)
  • Lightweight and modular design, allowing for easy integration into existing projects
  • Active community and frequent updates

Cons of bgfx

  • Steeper learning curve compared to DirectX-specific samples
  • Less comprehensive documentation for DirectX-specific features
  • May require additional setup for DirectX-only projects

Code Comparison

bgfx initialization:

bgfx::Init init;
init.type = bgfx::RendererType::Direct3D11;
bgfx::init(init);

DirectX-Graphics-Samples initialization:

D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&m_device));
m_device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_commandQueue));

Both repositories provide valuable resources for graphics programming. DirectX-Graphics-Samples offers in-depth examples specifically for DirectX, while bgfx provides a more versatile, cross-platform approach. The choice between them depends on project requirements and developer preferences.

59,344

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

Pros of ImGui

  • Lightweight and easy to integrate into existing projects
  • Cross-platform compatibility with multiple rendering backends
  • Immediate mode GUI, allowing for rapid prototyping and development

Cons of ImGui

  • Limited built-in styling options compared to DirectX-Graphics-Samples
  • Lacks advanced 3D rendering capabilities and shader examples
  • May require more manual work for complex UI layouts

Code Comparison

ImGui (basic window creation):

ImGui::Begin("Hello, world!");
ImGui::Text("This is some useful text.");
ImGui::End();

DirectX-Graphics-Samples (basic window creation):

ComPtr<ID3D12Device> device;
D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device));
// Additional setup code for window creation and rendering

ImGui focuses on simplicity and ease of use for creating user interfaces, while DirectX-Graphics-Samples provides comprehensive examples of advanced graphics techniques using DirectX. ImGui is better suited for quick UI prototyping and cross-platform development, whereas DirectX-Graphics-Samples is ideal for learning and implementing complex graphics rendering techniques specific to DirectX.

6,830

minimal cross-platform standalone C headers

Pros of sokol

  • Cross-platform support (Windows, macOS, Linux, iOS, Android, web)
  • Lightweight and minimal API, easier to learn and use
  • Single-header library design for simple integration

Cons of sokol

  • Less comprehensive feature set compared to DirectX samples
  • Limited to basic graphics functionality, may require additional libraries for advanced features
  • Smaller community and ecosystem

Code Comparison

sokol:

#include "sokol_gfx.h"

sg_pipeline pip;
sg_bindings bind;

void init(void) {
    sg_setup(&(sg_desc){0});
    // ... pipeline and buffer setup
}

DirectX-Graphics-Samples:

#include <d3d12.h>

ComPtr<ID3D12Device> device;
ComPtr<ID3D12CommandQueue> commandQueue;

void Init()
{
    D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device));
    // ... command queue and other resource setup
}

Summary

sokol offers a simpler, cross-platform approach to graphics programming with a minimal API, making it easier for beginners or small projects. DirectX-Graphics-Samples provides more comprehensive examples and features specific to Microsoft's DirectX ecosystem, better suited for advanced Windows graphics development.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

DirectX-Graphics-Samples

This repo contains the DirectX 12 Graphics samples that demonstrate how to build graphics intensive applications for Windows 10.

We invite you to join us at our discord server. See our YouTube channel for tutorials, our spec repo for engineering specs of our features and devblogs for blog posts. Follow us on Twitter @DirectX12 for the latest! See the related links section for our full list of DX12-related links.

Finally, make sure that you visit the DirectX Landing Page for more resources for DirectX developers.

API Samples

In the Samples directory, you will find samples that attempt to break off specific features and specific usage scenarios into bite-sized chunks. For example, the ExecuteIndirect sample will show you just enough about execute indirect to get started with that feature without diving too deep into multiengine whereas the nBodyGravity sample will delve into multiengine without touching on the execute indirect feature etc. By doing this, we hope to make it easier to get started with DirectX 12.

DirectX 12 Ultimate samples

  1. D3D12 Mesh Shaders: This sample demonstrates how Mesh shaders can be used to increase the flexibility and performance of the geometry pipeline.

    D3D12 Meshlet Render preview
  2. D3D12 Variable Rate Shading: This sample demonstrates how shading rate can be reduced with little or no reduction in visual quality, leading to “free” performance.

    D3D12 Variable Rate Shading GUI
  3. D3D12 Raytracing: This sample demonstrates how DirectX Raytracing (DXR) brings a new level of graphics realism to video games, previously only achievable in the movie industry.

    D3D12 Raytracing Real-Time Denoised Ambient Occlusion preview

MiniEngine: A DirectX 12 Engine Starter Kit

In addition to the samples, we are announcing the first DirectX 12 preview release of the MiniEngine.

It came from a desire to quickly dive into graphics and performance experiments. We knew we would need some basic building blocks whenever starting a new 3D app, and we had already written these things at countless previous gigs. We got tired of reinventing the wheel, so we established our own core library of helper classes and platform abstractions. We wanted to be able to create a new app by writing just the Init(), Update(), and Render() functions and leveraging as much reusable code as possible. Today our core library has been redesigned for DirectX 12 and aims to serve as an example of efficient API usage. It is obviously not exhaustive of what a game engine needs, but it can serve as the cornerstone of something new. You can also borrow whatever useful code you find.

Some features of MiniEngine

  • High-quality anti-aliased text rendering
  • Real-time CPU and GPU profiling
  • User-controlled variables
  • Game controller, mouse, and keyboard input
  • A friendly DirectXMath wrapper
  • Perspective camera supporting traditional and reversed Z matrices
  • Asynchronous DDS texture loading and ZLib decompression
  • Large library of shaders
  • Easy shader embedding via a compile-to-header system
  • Easy render target, depth target, and unordered access view creation
  • A thread-safe GPU command context system (WIP)
  • Easy-to-use dynamic constant buffers and descriptor tables

Requirements

Some samples require support for DirectX 12 Ultimate, see this post for details.

Master branch

This branch is intended for the latest released Windows 10 version.

Develop branch

This branch is intended for features available in the latest Windows Insider Preview

Contributing

We're always looking for your help to fix bugs and improve the samples. File those pull requests and we'll be happy to take a look.

Troubleshooting information for this repository can be found in the site Wiki.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Related links