Skip to content

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

Description

@freeDiving

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:

failed to open file!

The target loads its shader using a relative path:

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:

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

However, the generated debugger working directory is:

build/09_shader_modules

Consequently, the application looks for:

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:
cmake -S attachments -B build -G "Visual Studio 18 2026" -A x64 `
  -DCMAKE_TOOLCHAIN_FILE="C:\path\to\vcpkg\scripts\buildsystems\vcpkg.cmake"
  1. Open build/VulkanTutorial.slnx.
  2. Set 09_shader_modules as the startup project.
  3. Build and run any configuration.

Suspected regression

This appears to have been introduced by commit 7e49123. It changed SHADERS_DIR at lines 88–90 and 112–114 to include $<CONFIG>,

  if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*" OR 
      ${CMAKE_GENERATOR} MATCHES "Ninja Multi-Config")
    set (SHADERS_DIR ${CMAKE_BINARY_DIR}/${SHADER_CHAPTER_NAME}/$<CONFIG>/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 "$<TARGET_FILE_DIR:${CHAPTER_NAME}>"
)

I tested this change locally. CMake generates the correct configuration-specific working directory, and 09_shader_modules runs successfully from Visual Studio.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions