Skip to content

Commit 483706a

Browse files
committed
Work Graph Playground v1.1.0
- Add support for the experimental Mesh Node preview feature - Add HelloMeshNodes tutorial - Extend command line argument parsing - Add support for opening external .hlsl files
1 parent 616e78b commit 483706a

37 files changed

+2674
-862
lines changed

CMakeLists.txt

Lines changed: 100 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is part of the AMD & HSC Work Graph Playground.
22
#
3-
# Copyright (C) 2024 Advanced Micro Devices, Inc. and Coburg University of Applied Sciences and Arts.
3+
# Copyright (C) 2025 Advanced Micro Devices, Inc. and Coburg University of Applied Sciences and Arts.
44
# All rights reserved.
55
#
66
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -22,7 +22,7 @@
2222
# THE SOFTWARE.
2323

2424
cmake_minimum_required(VERSION 3.17)
25-
project(WorkGraphPlayground VERSION 0.1)
25+
project(WorkGraphPlayground VERSION 1.1)
2626

2727
set(CMAKE_CXX_STANDARD 20)
2828
set(CMAKE_CXX_STANDARD_REQUIRED True)
@@ -35,23 +35,28 @@ add_compile_definitions(UNICODE _UNICODE)
3535

3636
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
3737

38+
option(PLAYGROUND_ENABLE_MESH_NODES "Enable experimental mesh node support" OFF)
39+
set(PLAYGROUND_COPY_TUTORIAL_MODE "none" CACHE STRING "Mode for copying tutorial files to output bin folder.\n none: do not copy tutorial files.\n copy: copy tutorial files after build step.\n symlink: create symlinks for tutorial folder to bin folder.")
40+
set_property(CACHE PLAYGROUND_COPY_TUTORIAL_MODE PROPERTY STRINGS none copy symlink)
41+
3842
add_subdirectory(imported)
3943

44+
add_executable(${PROJECT_NAME})
45+
46+
if (PLAYGROUND_ENABLE_MESH_NODES)
47+
target_compile_definitions(${PROJECT_NAME} PRIVATE ENABLE_MESH_NODES)
48+
endif()
4049

50+
# collect & add C++ source files
4151
file(GLOB PROJECT_SOURCE_FILES
4252
${CMAKE_CURRENT_SOURCE_DIR}/include/*.h
4353
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
44-
file(GLOB_RECURSE PROJECT_SHADER_FILES
45-
${CMAKE_CURRENT_SOURCE_DIR}/tutorials/*.md
46-
${CMAKE_CURRENT_SOURCE_DIR}/tutorials/*.png
47-
${CMAKE_CURRENT_SOURCE_DIR}/tutorials/*.h
48-
${CMAKE_CURRENT_SOURCE_DIR}/tutorials/*.hlsl)
49-
set_source_files_properties(${PROJECT_SHADER_FILES} PROPERTIES VS_TOOL_OVERRIDE "Text")
50-
51-
add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_FILES} ${PROJECT_SHADER_FILES})
54+
target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_FILES})
55+
5256
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
57+
# link NuGet packages and ImGui
5358
target_link_libraries(${PROJECT_NAME} PRIVATE
54-
Microsoft.Direct3D.D3D12
59+
Microsoft.Direct3D.D3D12
5560
Microsoft.Direct3D.DXC
5661
Microsoft.Direct3D.WARP
5762
d3d12
@@ -60,36 +65,92 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
6065
dxguid
6166
imgui)
6267

63-
set_target_properties(${PROJECT_NAME} PROPERTIES
68+
set_target_properties(${PROJECT_NAME} PROPERTIES
69+
# set playground app to be DPI aware, i.e. disable scaling in Windows compositor
6470
VS_DPI_AWARE "PerMonitor"
65-
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>")
71+
# set working directory to current directory
72+
VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
73+
74+
# set playground as startup project
6675
set_property(DIRECTORY "." PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
6776

68-
# set source group for shader files & link to bin folder
69-
set(SHADER_BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tutorials)
70-
foreach(SHADER ${PROJECT_SHADER_FILES})
71-
get_filename_component(SHADER_FILE_DIRECTORY ${SHADER} DIRECTORY)
72-
get_filename_component(SHADER_FILE_NAME ${SHADER} NAME)
73-
file(RELATIVE_PATH SHADER_FILE_DIRECTORY_RELATIVE_PATH ${SHADER_BASE_DIRECTORY} ${SHADER_FILE_DIRECTORY})
74-
75-
if ("${SHADER_FILE_DIRECTORY_RELATIVE_PATH}" STREQUAL "")
76-
source_group("Shader Source Files" FILES ${SHADER})
77-
else()
78-
source_group("Shader Source Files/${SHADER_FILE_DIRECTORY_RELATIVE_PATH}" FILES ${SHADER})
77+
set(TUTORIAL_FOLDER_LIST "")
78+
function(add_tutorial_folder TUTORIAL_FOLDER PREFIX SOURCE_GROUP)
79+
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${TUTORIAL_FOLDER})
80+
message(FATAL "Tutorial folder ${TUTORIAL_FOLDER} not found in current source directory!")
7981
endif()
8082

81-
# to enable shader hot-reloading, instead of copying the shaders to the bin output folder at the end of the build,
82-
# we create hardlinks between a file in the bin folder and the shader source file.
83-
# This way, updates to the shader source file are automatically propagated to the bin folder,
84-
# and - unlike symlinks - the hardlinks allow copying/moving/compressing the bin folder without having broken links.
85-
86-
# create parent folder
87-
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
88-
COMMAND ${CMAKE_COMMAND} -E make_directory
89-
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/tutorials/${SHADER_FILE_DIRECTORY_RELATIVE_PATH})
90-
# create hardlink
91-
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
92-
COMMAND ${CMAKE_COMMAND} -E create_hardlink
93-
${SHADER}
94-
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/tutorials/${SHADER_FILE_DIRECTORY_RELATIVE_PATH}/${SHADER_FILE_NAME})
95-
endforeach()
83+
# collect tutorial source files
84+
file(GLOB_RECURSE TUTORIAL_FILES
85+
${CMAKE_CURRENT_SOURCE_DIR}/${TUTORIAL_FOLDER}/*.md
86+
${CMAKE_CURRENT_SOURCE_DIR}/${TUTORIAL_FOLDER}/*.png
87+
${CMAKE_CURRENT_SOURCE_DIR}/${TUTORIAL_FOLDER}/*.h
88+
${CMAKE_CURRENT_SOURCE_DIR}/${TUTORIAL_FOLDER}/*.hlsl)
89+
90+
# add tutorial source files and disable compilation of HLSL files
91+
target_sources(${PROJECT_NAME} PRIVATE ${TUTORIAL_FILES})
92+
set_source_files_properties(${TUTORIAL_FILES} PROPERTIES VS_TOOL_OVERRIDE "Text")
93+
94+
if ("${PLAYGROUND_COPY_TUTORIAL_MODE}" STREQUAL "copy")
95+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
96+
COMMAND ${CMAKE_COMMAND} -E copy_directory
97+
${CMAKE_CURRENT_SOURCE_DIR}/${TUTORIAL_FOLDER}
98+
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/${TUTORIAL_FOLDER})
99+
elseif("${PLAYGROUND_COPY_TUTORIAL_MODE}" STREQUAL "symlink")
100+
# To allow for easy copying of the playground and all tutorials, we support creating symlinks for all
101+
# tutorial folders to the bin output folder. As shader source files are not part of the build process
102+
# changes to these files are not tracked by the build system.
103+
# To still keep all the shader source files in the bin folder up-to-date, we create a symlink for each folder.
104+
# This way, updates to the shader source file are automatically propagated to the bin folder,
105+
# allowing you to copy/move/compress the bin folder with the latest version of your shader file.
106+
107+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
108+
COMMAND ${CMAKE_COMMAND} -E create_symlink
109+
${CMAKE_CURRENT_SOURCE_DIR}/${TUTORIAL_FOLDER}
110+
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/${TUTORIAL_FOLDER})
111+
endif()
112+
113+
# set source group for shader files & link to bin folder
114+
foreach(TUTORIAL_FILE ${TUTORIAL_FILES})
115+
get_filename_component(TUTORIAL_FILE_DIRECTORY ${TUTORIAL_FILE} DIRECTORY)
116+
get_filename_component(TUTORIAL_FILE_NAME ${TUTORIAL_FILE} NAME)
117+
file(RELATIVE_PATH TUTORIAL_FILE_DIRECTORY_RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${TUTORIAL_FOLDER} ${TUTORIAL_FILE_DIRECTORY})
118+
119+
if ("${TUTORIAL_FILE_DIRECTORY_RELATIVE_PATH}" STREQUAL "")
120+
source_group("${SOURCE_GROUP}" FILES ${TUTORIAL_FILE})
121+
else()
122+
source_group("${SOURCE_GROUP}/${TUTORIAL_FILE_DIRECTORY_RELATIVE_PATH}" FILES ${TUTORIAL_FILE})
123+
endif()
124+
endforeach()
125+
126+
set(TUTORIAL_FOLDER_LIST "${TUTORIAL_FOLDER_LIST}std::make_pair(\"${TUTORIAL_FOLDER}\", \"${PREFIX}\")," PARENT_SCOPE)
127+
endfunction(add_tutorial_folder)
128+
129+
add_tutorial_folder(tutorials "Tutorial" "Shader Source Files")
130+
131+
if (PLAYGROUND_ENABLE_MESH_NODES)
132+
# Add mesh node tutorials. These are only included if mesh nodes are enabled.
133+
add_tutorial_folder(mesh-node-tutorials "Mesh Node Tutorial" "Shader Source Files/Mesh Nodes")
134+
endif()
135+
136+
########################################################################################################
137+
# Add new tutorial folders here
138+
#
139+
# Example:
140+
# add_tutorial_folder(./path/to/your/folder "My Tutorial Prefix" "Shader Source Files/My New Tutorials")
141+
#
142+
# Tutorials in this folder will show up in the UI as "My Tutorial Prefix #: Tutorial Name" and
143+
# show up in the solution under "Shader Source Files/My New Tutorials"
144+
#
145+
146+
147+
148+
########################################################################################################
149+
150+
# Once all tutorials are added, set define for app to scan all tutorial folders at runtime
151+
target_compile_definitions(${PROJECT_NAME} PRIVATE TUTORIAL_FOLDER_LIST=${TUTORIAL_FOLDER_LIST})
152+
153+
154+
155+
156+

imported/CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is part of the AMD & HSC Work Graph Playground.
22
#
3-
# Copyright (C) 2024 Advanced Micro Devices, Inc. and Coburg University of Applied Sciences and Arts.
3+
# Copyright (C) 2025 Advanced Micro Devices, Inc. and Coburg University of Applied Sciences and Arts.
44
# All rights reserved.
55
#
66
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -23,17 +23,27 @@
2323

2424
include(nuget.cmake)
2525

26+
if (PLAYGROUND_ENABLE_MESH_NODES)
27+
set(NUGET_D3D12_VERSION 1.715.1-preview)
28+
set(NUGET_DXC_VERSION 1.8.2404.55-mesh-nodes-preview)
29+
set(NUGET_WARP_VERSION 1.0.14.1-preview)
30+
else()
31+
set(NUGET_D3D12_VERSION 1.613.3)
32+
set(NUGET_DXC_VERSION 1.8.2403.18)
33+
set(NUGET_WARP_VERSION 1.0.14.2)
34+
endif()
35+
2636
fetch_nuget_package(
2737
PACKAGE Microsoft.Direct3D.D3D12
28-
VERSION 1.613.3
38+
VERSION ${NUGET_D3D12_VERSION}
2939
)
3040
fetch_nuget_package(
3141
PACKAGE Microsoft.Direct3D.DXC
32-
VERSION 1.8.2403.18
42+
VERSION ${NUGET_DXC_VERSION}
3343
)
3444
fetch_nuget_package(
3545
PACKAGE Microsoft.Direct3D.WARP
36-
VERSION 1.0.13
46+
VERSION ${NUGET_WARP_VERSION}
3747
)
3848

3949
file(GLOB IMGUI_SOURCES

imported/nuget.cmake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is part of the AMD & HSC Work Graph Playground.
22
#
3-
# Copyright (C) 2024 Advanced Micro Devices, Inc. and Coburg University of Applied Sciences and Arts.
3+
# Copyright (C) 2025 Advanced Micro Devices, Inc. and Coburg University of Applied Sciences and Arts.
44
# All rights reserved.
55
#
66
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -35,8 +35,8 @@ function(fetch_nuget_package)
3535
endif()
3636

3737
set(DOWNLOAD_URL "https://www.nuget.org/api/v2/package/${FETCH_NUGET_PACKAGE_PACKAGE}/${FETCH_NUGET_PACKAGE_VERSION}")
38-
set(DOWNLOAD_FILE ${CMAKE_CURRENT_BINARY_DIR}/nuget/${FETCH_NUGET_PACKAGE_PACKAGE}.zip)
39-
set(PACKAGE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/nuget/${FETCH_NUGET_PACKAGE_PACKAGE})
38+
set(DOWNLOAD_FILE ${CMAKE_CURRENT_BINARY_DIR}/nuget/${FETCH_NUGET_PACKAGE_PACKAGE}-${FETCH_NUGET_PACKAGE_VERSION}.zip)
39+
set(PACKAGE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/nuget/${FETCH_NUGET_PACKAGE_PACKAGE}-${FETCH_NUGET_PACKAGE_VERSION})
4040

4141
if (NOT EXISTS ${DOWNLOAD_FILE})
4242
message(STATUS "Downloading NuGet package \"${FETCH_NUGET_PACKAGE_PACKAGE}\" from \"${DOWNLOAD_URL}\".")
@@ -68,7 +68,6 @@ function(fetch_nuget_package)
6868
message("Generating custom command for ${PACKAGE_BIN_FILE_NAME}")
6969
add_custom_command(
7070
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>/${PACKAGE_BIN_FILE_NAME}
71-
PRE_BUILD
7271
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>
7372
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PACKAGE_BIN_FILE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<CONFIG>
7473
MAIN_DEPENDENCY ${PACKAGE_BIN_FILE}

include/Application.h

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of the AMD & HSC Work Graph Playground.
22
//
3-
// Copyright (C) 2024 Advanced Micro Devices, Inc. and Coburg University of Applied Sciences and Arts.
3+
// Copyright (C) 2025 Advanced Micro Devices, Inc. and Coburg University of Applied Sciences and Arts.
44
// All rights reserved.
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -24,6 +24,7 @@
2424
#pragma once
2525

2626
#include <chrono>
27+
#include <vector>
2728

2829
#include "Device.h"
2930
#include "ShaderCompiler.h"
@@ -38,6 +39,15 @@ class Application {
3839
std::uint32_t windowWidth = 1280;
3940
std::uint32_t windowHeight = 720;
4041

42+
std::vector<WorkGraph::WorkGraphTutorial> tutorials;
43+
44+
std::optional<WorkGraph::WorkGraphTutorial> tutorial;
45+
46+
#ifdef ENABLE_MESH_NODES
47+
// MSAA sample count for render target
48+
std::uint32_t renderTargetSampleCount = 1;
49+
#endif
50+
4151
bool forceWarpAdapter = false;
4252
bool enableDebugLayer = false;
4353
bool enableGpuValidationLayer = false;
@@ -48,8 +58,6 @@ class Application {
4858

4959
void Run();
5060

51-
static std::span<const WorkGraph::WorkGraphTutorial> GetTutorials();
52-
5361
private:
5462
void OnRender(ID3D12GraphicsCommandList10* commandList, const Swapchain::RenderTarget& renderTarget);
5563
void OnRenderUserInterface(ID3D12GraphicsCommandList10* commandList, const Swapchain::RenderTarget& renderTarget);
@@ -69,6 +77,15 @@ class Application {
6977
void CreatePersistentScratchBuffer();
7078
void ClearShaderResources(ID3D12GraphicsCommandList10* commandList);
7179

80+
// Util methods for MSAA
81+
void CreateMsaaResources(std::uint32_t width,
82+
std::uint32_t height,
83+
std::uint32_t sampleCount,
84+
std::uint32_t sampleQuality);
85+
void ResolveMsaaRenderTarget(ID3D12GraphicsCommandList* commandList,
86+
const Swapchain::RenderTarget& swapchainRenderTarget,
87+
const Swapchain::RenderTarget& msaaRenderTarget);
88+
7289
void CreateFontBuffer();
7390

7491
std::unique_ptr<Window> window_;
@@ -84,6 +101,12 @@ class Application {
84101
ComPtr<ID3D12DescriptorHeap> clearDescriptorHeap_;
85102
ComPtr<ID3D12DescriptorHeap> resourceDescriptorHeap_;
86103

104+
// Multi-sample resources
105+
ComPtr<ID3D12Resource> msaaColorResource_;
106+
ComPtr<ID3D12DescriptorHeap> msaaColorDescriptorHeap_;
107+
ComPtr<ID3D12Resource> msaaDepthResource_;
108+
ComPtr<ID3D12DescriptorHeap> msaaDepthDescriptorHeap_;
109+
87110
// Shader resources
88111
ComPtr<ID3D12Resource> writableBackbuffer_;
89112
ComPtr<ID3D12Resource> scratchBuffer_;
@@ -100,10 +123,12 @@ class Application {
100123
// Start time of current tutorial. Delta to current time is available in the shader as "Time"
101124
std::chrono::high_resolution_clock::time_point startTime_ = std::chrono::high_resolution_clock::now();
102125

126+
std::vector<WorkGraph::WorkGraphTutorial> workGraphTutorials_;
127+
103128
// Work Graph resources
104-
ShaderCompiler shaderCompiler_;
105-
ComPtr<ID3D12RootSignature> workGraphRootSignature_;
106-
std::uint32_t workGraphTutorialIndex_ = 0;
107-
bool workGraphUseSampleSolution_ = false;
108-
std::unique_ptr<WorkGraph> workGraph_;
129+
std::unique_ptr<ShaderCompiler> shaderCompiler_;
130+
ComPtr<ID3D12RootSignature> workGraphRootSignature_;
131+
WorkGraph::WorkGraphTutorial workGraphTutorial_;
132+
bool workGraphUseSampleSolution_ = false;
133+
std::unique_ptr<WorkGraph> workGraph_;
109134
};

include/Device.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of the AMD & HSC Work Graph Playground.
22
//
3-
// Copyright (C) 2024 Advanced Micro Devices, Inc. and Coburg University of Applied Sciences and Arts.
3+
// Copyright (C) 2025 Advanced Micro Devices, Inc. and Coburg University of Applied Sciences and Arts.
44
// All rights reserved.
55
//
66
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -62,18 +62,22 @@ class Device {
6262
ID3D12Device9* GetDevice() const;
6363
ID3D12CommandQueue* GetCommandQueue() const;
6464

65+
bool IsSoftwareAdapter() const;
6566
const std::string& GetAdapterDescription() const;
6667

68+
D3D12_WORK_GRAPHS_TIER GetSupportedWorkGraphsTier() const;
69+
6770
private:
68-
void CreateDXGIFactory(bool enableDebugLayer, bool enableGpuValidationLayer);
69-
ComPtr<ID3D12Device9> CreateDevice(IDXGIAdapter1* adapter) const;
70-
bool CheckDeviceFeatures(ID3D12Device9* device) const;
71-
void CreateDeviceResources();
71+
void CreateDXGIFactory(bool enableDebugLayer, bool enableGpuValidationLayer);
72+
ComPtr<ID3D12Device9> CreateDevice(IDXGIAdapter1* adapter) const;
73+
D3D12_WORK_GRAPHS_TIER GetSupportedWorkGraphsTier(ID3D12Device9* device) const;
74+
void CreateDeviceResources();
7275

7376
void RegisterDebugMessageCallback();
7477

75-
ComPtr<IDXGIFactory4> dxgiFactory_;
78+
ComPtr<IDXGIFactory6> dxgiFactory_;
7679

80+
bool softwareAdapter_ = false;
7781
std::string adapterDescription_ = "Unknown Adapter";
7882

7983
ComPtr<ID3D12Device9> device_;

0 commit comments

Comments
 (0)