Skip to content

Add --screenshot option to all D3D12 examples#151

Open
loosche wants to merge 1 commit intomainfrom
feature/screenshot-d3d12
Open

Add --screenshot option to all D3D12 examples#151
loosche wants to merge 1 commit intomainfrom
feature/screenshot-d3d12

Conversation

@loosche
Copy link
Copy Markdown
Collaborator

@loosche loosche commented Apr 13, 2026

Summary

  • Adds SaveDxTextureAsPNG() to projects/common/dx_renderer.h/.cpp — reads back the swapchain buffer via a D3D12 READBACK heap, converts BGRA→RGBA, forces alpha=255, and saves via BitmapRGBA8u::Save(). Mirrors the existing SaveMetalTextureAsPNG() helper.
  • Wires --screenshot <path> [frameN] into all 48 D3D12 example main loops, matching the Metal behavior exactly: frameN omitted takes a screenshot on frame 0 and continues; frameN specified waits for that frame then auto-exits.
  • Screenshot block is correctly placed inside nested swapchain-buffer scopes for raytracing and path-trace examples (where swapchainBuffer is block-scoped).
  • Updates CMakeLists for projects missing bitmap.h/bitmap.cpp or the stb include path.

Test plan

  • Build all D3D12 projects: cmake --build build --config Release --parallel
  • Spot-check first-frame screenshot: 101_color_cube_d3d12.exe --screenshot out.png 0
  • Spot-check specific frame + auto-exit: 030_raytracing_path_trace_d3d12.exe --screenshot out.png 100
  • Verify PNG is written and non-empty after each run

🤖 Generated with Claude Code

Adds SaveDxTextureAsPNG() to the common D3D12 renderer library and
wires it into all 48 D3D12 examples, matching the existing Metal
screenshot behavior.

- projects/common/dx_renderer.h/.cpp: Add SaveDxTextureAsPNG() which
  reads back the swapchain buffer via a READBACK heap, converts BGRA
  to RGBA, forces alpha=255, and saves via BitmapRGBA8u::Save()
- All D3D12 example main loops: add frameIndex tracking, update
  auto-exit guard to respect --screenshot frame targeting, insert
  screenshot block after WaitForGpu (correctly scoped for nested
  swapchain-buffer blocks in raytracing/path-trace examples)
- CMakeLists: add bitmap.h/bitmap.cpp and stb include path to projects
  that were missing them

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant