KhronosGroup / KhronosGroup/Vulkan-Tutorial

Visual Studio debugger working directory does not match the configuration-specific output directory

Open Beginner friendly
#507 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
418
Forks
126
Avg merge
11d 6h
Merged PRs (30d)
31

Description

This issue probably affects all tutorials that use shaders. When running `09_shader_modules`—the first tutorial target that uses shaders—from Visual Studio, the application exits with:

```text
failed to open file!
```

The target loads its shader using a relative path:

```cpp
readFile("shaders/slang.spv")
```

With a Visual Studio multi-config generator, CMake places the executable and shader under the active configuration directory. For example, a Debug build produces:

```text
build/09_shader_modules/Debug/09_shader_modules.exe
build/09_shader_modules/Debug/shaders/slang.spv
```

However, the generated debugger working directory is:

```text
build/09_shader_modules
```

Consequently, the application looks for:

```text
build/09_shader_modules/shaders/slang.spv
```

which does not exist.

All Visual Studio build configurations are affected, including `Debug`, `Release`, `MinSizeRel`, and `RelWithDebInfo`, because their executables and shaders are placed in separate configuration-specific directories while the debugger working directory remains their common parent directory.

### Environment

- Windows
- Visual Studio Community 2026
- CMake generator: `Visual Studio 18 2026`
- Vulkan SDK 1.4.357
- Repository revision: `a762d8a`

This likely affects all Visual Studio multi-config generators, not only Visual Studio 2026.

### Steps to reproduce

1. Configure the attachment projects:

```powershell
cmake -S attachments -B build -G "Visual Studio 18 2026" -A x64 `
-DCMAKE_TOOLCHAIN_FILE="C:\path\to\vcpkg\scripts\buildsystems\vcpkg.cmake"
```

2. Open `build/VulkanTutorial.slnx`.
3. Set `09_shader_modules` as the startup project.
4. Build and run any configuration.

### Suspected regression
This appears to have been introduced by commit 7e491239328213e4186704cc5ef597a95a34f4dc. It changed SHADERS_DIR at lines 88–90 and 112–114 to include `$`,
```
if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*" OR
${CMAKE_GENERATOR} MATCHES "Ninja Multi-Config")
set (SHADERS_DIR ${CMAKE_BINARY_DIR}/${SHADER_CHAPTER_NAME}/$/shaders)
```

while `VS_DEBUGGER_WORKING_DIRECTORY` at line 157 continued to use the parent chapter directory.
```
if(WIN32)
if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
set_target_properties(${CHAPTER_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/${CHAPTER_NAME}")
endif()
endif()
```

### Proposed fix
Use the target’s executable directory as the debugger working directory:
```
set_target_properties(${CHAPTER_NAME} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "$"
)
```
I tested this change locally. CMake generates the correct configuration-specific working directory, and 09_shader_modules runs successfully from Visual Studio.

Contributor guide

Open the contributing guide

Research direction

Start in the CMake logic for the attachment projects, especially the target setup for 09_shader_modules and the VS_DEBUGGER_WORKING_DIRECTORY property described in the issue. Configure attachments with a Visual Studio multi-config generator, build a configuration, and run 09_shader_modules from the generated solution. Done means the debugger working directory matches the configuration-specific executable and shader directory, and the tutorial starts successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.