From 973dfcf9ea280e12b8e7e8ef6886fca0c8ca7c16 Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Wed, 7 Jan 2026 22:04:26 +0000 Subject: [PATCH] fix(shader): Update integer uniform mapping to Vec4 and add verbose logging for better debugging --- VULKAN_SHADER_LINKING_PROBLEM.md | 22 ++++++++++++++++------ src/bgfx_tools/shaderc/shaderc_spirv.cpp | 17 +++++++++++++---- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/VULKAN_SHADER_LINKING_PROBLEM.md b/VULKAN_SHADER_LINKING_PROBLEM.md index 5577913..92c58b4 100644 --- a/VULKAN_SHADER_LINKING_PROBLEM.md +++ b/VULKAN_SHADER_LINKING_PROBLEM.md @@ -30,12 +30,23 @@ case 0x8B55: // GL_INT_VEC4: // Integer uniforms are data uniforms, not texture samplers. // Map to Vec4 to match bgfx's data-uniform layout rules. un.type = UniformType::Vec4; // ✅ CORRECT - BX_TRACE("shaderc_spirv: int uniform mapped to Vec4 (%s, glType=0x%X, offset=%u)", - un.name.c_str(), - uniformType, - offset); + if (bgfx::g_verbose) + { + BX_TRACE("shaderc_spirv: int uniform mapped to Vec4 (%s, glType=0x%X, offset=%u)", + un.name.c_str(), + uniformType, + offset); + } break; ... +default: + if (bgfx::g_verbose) + { + BX_TRACE("shaderc_spirv: skipping uniform %s (glType=0x%X)", + un.name.c_str(), + uniformType); + } + continue; } ``` @@ -61,7 +72,7 @@ The shader creation path already uses `bgfx::copy(...)` before `bgfx::createShad ./scripts/dev_commands.py build --build-dir build-ninja --target sdl3_app ``` 2. Run with trace logs and verify: - - `shaderc_spirv: int uniform mapped to Vec4 ...` appears for the int uniforms + - With verbose enabled, `shaderc_spirv: int uniform mapped to Vec4 ...` appears for the int uniforms - The shader uniform list no longer shows those ints as samplers - The Vulkan SIGSEGV no longer occurs @@ -243,4 +254,3 @@ This fix addresses: - "No valid uniforms" warnings for shaders with integer uniforms - Malformed descriptor layouts in Vulkan backend - Use-after-free-like symptoms (though actual cause was malformed metadata) - diff --git a/src/bgfx_tools/shaderc/shaderc_spirv.cpp b/src/bgfx_tools/shaderc/shaderc_spirv.cpp index fb0aec6..94b3005 100644 --- a/src/bgfx_tools/shaderc/shaderc_spirv.cpp +++ b/src/bgfx_tools/shaderc/shaderc_spirv.cpp @@ -689,10 +689,13 @@ namespace bgfx { namespace spirv case 0x8B54: // GL_INT_VEC3: case 0x8B55: // GL_INT_VEC4: un.type = UniformType::Vec4; - BX_TRACE("shaderc_spirv: int uniform mapped to Vec4 (%s, glType=0x%X, offset=%u)", - un.name.c_str(), - uniformType, - offset); + if (bgfx::g_verbose) + { + BX_TRACE("shaderc_spirv: int uniform mapped to Vec4 (%s, glType=0x%X, offset=%u)", + un.name.c_str(), + uniformType, + offset); + } break; case 0x8B52: // GL_FLOAT_VEC4: @@ -710,6 +713,12 @@ namespace bgfx { namespace spirv break; default: + if (bgfx::g_verbose) + { + BX_TRACE("shaderc_spirv: skipping uniform %s (glType=0x%X)", + un.name.c_str(), + uniformType); + } continue; }