vulkan: add 1.1 shader compatibility mode

if GGML_VULKAN_MIN_1_1 is defined:

 - rte shaders will be built with 1.1 API and "SPV_KHR_float_controls"
   spirv extension.
 - all no _cm2 shaders will be built with 1.1 API

No changes if GGML_VULKAN_MIN_1_1 is not defined (default).
This commit is contained in:
Thomas Guillem 2026-01-19 13:25:52 +01:00
parent 95fa09250d
commit b95296c4e0
5 changed files with 41 additions and 3 deletions

View File

@ -222,6 +222,7 @@ option(GGML_VULKAN_MEMORY_DEBUG "ggml: enable Vulkan memory debug ou
option(GGML_VULKAN_SHADER_DEBUG_INFO "ggml: enable Vulkan shader debug info" OFF)
option(GGML_VULKAN_VALIDATE "ggml: enable Vulkan validation" OFF)
option(GGML_VULKAN_RUN_TESTS "ggml: run Vulkan tests" OFF)
option(GGML_VULKAN_MIN_1_1 "ggml: target Vulkan 1.1 minimum (SPIR-V 1.3)" OFF)
option(GGML_WEBGPU "ggml: use WebGPU" OFF)
option(GGML_WEBGPU_DEBUG "ggml: enable WebGPU debug output" OFF)
option(GGML_WEBGPU_CPU_PROFILE "ggml: enable WebGPU profiling (CPU)" OFF)

View File

@ -112,6 +112,11 @@ if (Vulkan_FOUND)
list(APPEND VULKAN_SHADER_GEN_CMAKE_ARGS -DGGML_VULKAN_SHADER_DEBUG_INFO=ON)
endif()
if (GGML_VULKAN_MIN_1_1)
add_compile_definitions(GGML_VULKAN_MIN_1_1)
list(APPEND VULKAN_SHADER_GEN_CMAKE_ARGS -DGGML_VULKAN_MIN_1_1=ON)
endif()
if (GGML_VULKAN_VALIDATE)
add_compile_definitions(GGML_VULKAN_VALIDATE)
endif()

View File

@ -23,6 +23,9 @@ if (GGML_VULKAN_SHADER_DEBUG_INFO)
add_compile_definitions(GGML_VULKAN_SHADER_DEBUG_INFO)
message(STATUS "Enabling shader debug info")
endif()
if (GGML_VULKAN_MIN_1_1)
add_compile_definitions(GGML_VULKAN_MIN_1_1)
endif()
set(TARGET vulkan-shaders-gen)
add_executable(${TARGET} vulkan-shaders-gen.cpp)

View File

@ -1,5 +1,9 @@
#if RTE16
#extension GL_EXT_spirv_intrinsics : enable
spirv_execution_mode(capabilities = [4467], 4462, 16); // RoundingModeRTE, 16 bits
spirv_execution_mode(
#ifdef VULKAN11_RTE
extensions = ["SPV_KHR_float_controls"],
#endif
capabilities = [4467], 4462, 16); // RoundingModeRTE, 16 bits
#endif // RTE16

View File

@ -322,7 +322,21 @@ compile_count_guard acquire_compile_slot() {
}
void string_to_spv_func(std::string name, std::string in_path, std::string out_path, std::map<std::string, std::string> defines, bool coopmat, bool dep_file, compile_count_guard slot) {
std::string target_env = (name.find("_cm2") != std::string::npos) ? "--target-env=vulkan1.3" : "--target-env=vulkan1.2";
std::string target_env;
bool is_vulkan11;
#ifdef GGML_VULKAN_MIN_1_1
// Vulkan 1.1 compatibility mode
if (name.find("_cm2") != std::string::npos) {
target_env = "--target-env=vulkan1.3";
is_vulkan11 = false;
} else {
target_env = "--target-env=vulkan1.1";
is_vulkan11 = true;
}
#else
target_env = (name.find("_cm2") != std::string::npos) ? "--target-env=vulkan1.3" : "--target-env=vulkan1.2";
is_vulkan11 = false;
#endif
#ifdef _WIN32
std::vector<std::string> cmd = {GLSLC, "-fshader-stage=compute", target_env, "\"" + in_path + "\"", "-o", "\"" + out_path + "\""};
@ -333,7 +347,13 @@ void string_to_spv_func(std::string name, std::string in_path, std::string out_p
// disable spirv-opt for coopmat shaders for https://github.com/ggerganov/llama.cpp/issues/10734
// disable spirv-opt for bf16 shaders for https://github.com/ggml-org/llama.cpp/issues/15344
// disable spirv-opt for rope shaders for https://github.com/ggml-org/llama.cpp/issues/16860
if (!coopmat && name.find("bf16") == std::string::npos && name.find("rope") == std::string::npos) {
// disable spirv-opt for RTE shaders with vulkan1.1: spirv-opt rejects RoundingModeRTE with vulkan1.1 target
bool has_rte = (name.find("_rte") != std::string::npos) ||
(defines.find("RTE16") != defines.end() && defines.at("RTE16") == "1");
if (!coopmat &&
name.find("bf16") == std::string::npos &&
name.find("rope") == std::string::npos &&
!(has_rte && is_vulkan11)) {
cmd.push_back("-O");
}
@ -351,6 +371,11 @@ void string_to_spv_func(std::string name, std::string in_path, std::string out_p
cmd.push_back("-g");
#endif
// Need SPV_KHR_float_controls extension for Vulkan 1.1 RTE shaders
if (is_vulkan11 && has_rte) {
cmd.push_back("-DVULKAN11_RTE=1");
}
for (const auto& define : defines) {
cmd.push_back("-D" + define.first + "=" + define.second);
}