From f014bfef8b0870f257abcbceb9d8d2c4f2c684d7 Mon Sep 17 00:00:00 2001 From: miyan <1138989048@qq.com> Date: Tue, 8 Sep 2026 15:34:12 +0800 Subject: [PATCH] Fix Vulkan-Hpp handle usage on 32-bit targets. (#22892) On 32-bit platforms, Vulkan non-dispatchable handles such as VkBuffer are represented as uint64_t, and Vulkan-Hpp disables implicit conversions for type safety. This exposes two issues in ggml-vulkan: 1. vk::Buffer is streamed directly into std::ostream in debug/memory logs. 2. vk::Buffer is cast to VkBuffer before being passed to Vulkan-Hpp CommandBuffer::copyBuffer APIs. Fix these by add the operator<< for vk::Buffer, and by passing vk::Buffer directly to Vulkan-Hpp copyBuffer calls. --- ggml/src/ggml-vulkan/ggml-vulkan.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp index 75132c0b5..738e7cd92 100644 --- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp +++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp @@ -95,6 +95,14 @@ typedef struct VkPhysicalDeviceCooperativeMatrixDecodeVectorFeaturesNV { #include "ggml-vulkan-shaders.hpp" +// On 32-bit platforms, Vulkan non-dispatchable handles such as VkBuffer are represented as uint64_t, +// and Vulkan-Hpp disables implicit conversions for type safety. +namespace { +inline std::ostream & operator<<(std::ostream & os, vk::Buffer buffer) { + return os << static_cast(buffer); +} +} + // remove this once it's more widely available in the SDK #if !defined(VK_KHR_shader_bfloat16) @@ -8742,7 +8750,7 @@ static bool ggml_vk_buffer_write_2d_async(vk_context subctx, vk_buffer& dst, siz } ggml_vk_sync_buffers(nullptr, subctx); - subctx->s->buffer->buf.copyBuffer((VkBuffer)staging_buffer->buffer, (VkBuffer)dst->buffer, slices); + subctx->s->buffer->buf.copyBuffer(staging_buffer->buffer, dst->buffer, slices); if (width == spitch) { deferred_memcpy((uint8_t *)staging_buffer->ptr, src, staging_size, &subctx->in_memcpys);