Vulkan-Tutorial icon indicating copy to clipboard operation
Vulkan-Tutorial copied to clipboard

Lesson 9, I like to whine

Open TomServeaux opened this issue 5 months ago • 1 comments

This bit of text is odd:

The built-in annotation SV_Position functions as the output. Within the VertexOutput struct. Something worth mentioning if you’re familiar with other shading languages like GLSL or HLSL, there are no instructions for bindings.

Is this three sentences or two?

Not an error but a suggestion: stick with Slang throughout as far as compilation goes (you can keep the GLSL files as examples). Trying to reverse-engineer the existing CMakeLists.txt in the attachments directory for one's own code is complicated by trying to account for both.

Text says SV_TARGET, code says SV_Target.

There's a mention of location directives, which seems to be a remnant of the original vulkan-tutorial.com version of this lesson that used GLSL fragment shaders.

Also not an error, but there is a paragraph starting with "At the time of writing..." justifying the use of SPIR-V 1.4, which wikipedia says was released 5 years ago.

In this code block:

add_slang_shader_target( foo SOURCES ${SHADER_SLANG_SOURCES})
target_add_dependencies(bar PUBLIC foo)

It's not clear to me what the second line means. And should it be target_add_dependencies or add_dependencies which is closer to what's in the sample code's CMakeLists.txt?

Anyway, I had trouble getting the code to compile using the add_slang_shader_target function in the tutorial until I added a dummy variable and passed a dummy string to it, because cmake was complaining that I'd defined the keyword "SOURCE" more than once. Apparently cmake_parse_arguments needs at least four arguments and I think if you pass it fewer then it just doubles one of the parameters? The Cmake documentation says up front that the implementation of cmake_parse_arguments is "naive". Anyway, I had to do this:

function(add_slang_shader_target TARGET)
  cmake_parse_arguments("SHADER" "" "SOURCES" "POINTLESS" ${ARGN})
  set(SHADERS_DIR ${CMAKE_CURRENT_BINARY_DIR}/shader)
  set(ENTRY_POINTS -entry vertMain -entry fragMain)
  add_custom_command(
    OUTPUT ${SHADERS_DIR}
    COMMAND ${CMAKE_COMMAND} -E make_directory ${SHADERS_DIR}
  )
  add_custom_command(
    OUTPUT ${SHADERS_DIR}/slang.spv
    COMMAND ${SLANGC_EXECUTABLE} ${SHADER_SOURCES} -target spirv -profile spirv_1_4 -emit-spirv-directly -fvk-use-entrypoint-name ${ENTRY_POINTS} -o slang.spv
    WORKING_DIRECTORY ${SHADERS_DIR}
    DEPENDS ${SHADERS_DIR} ${SHADER_SOURCES}
    COMMENT "Compiling Slang Shaders"
    VERBATIM
  )
  add_custom_target(${TARGET} DEPENDS ${SHADERS_DIR}/slang.spv)
endfunction()

And then this:

add_slang_shader_target(${SLANG_SHADER_TARGET} SOURCES ${SHADER_SOURCE_FILES} POINTLESS "FOO")
add_dependencies(${PROJECT_NAME} ${SLANG_SHADER_TARGET})

And that worked.

In the function readFile if you're trying to keep the C++20 thing going then you might switch from raw string paths to std::filesystem

More C API references in multiple places (e.g. VkFoo instead of vk::foo).

TomServeaux avatar Jul 25 '25 05:07 TomServeaux

Text says SV_TARGET, code says SV_Target.

We can actually omit SV_Target all along with slang (unlike HLSL).

SaschaWillems avatar Jul 25 '25 08:07 SaschaWillems