From dd41b296f9299ce1269005452d5db8d2854ac61b Mon Sep 17 00:00:00 2001 From: skal Date: Mon, 9 Feb 2026 14:01:28 +0100 Subject: fix(3d): VisualDebug uniform buffer size mismatch Fixed validation error in test_3d_render: - Uniform buffer was 64 bytes (mat4) but bind group expected 176 bytes (GlobalUniforms) - Updated buffer creation to use sizeof(GlobalUniforms) - Updated bind group entry size to match - Updated update_buffers to write full GlobalUniforms struct Error was: Binding size 64 of Buffer with '' label is less than minimum 176 Root cause: VisualDebug uses same GlobalUniforms structure as main renderer but was only allocating/binding mat4 portion. Testing: - All 34 tests passing (100%) - test_3d_render runs without validation errors - GPU procedural textures working (noise, perlin, grid) Co-Authored-By: Claude Sonnet 4.5 --- src/3d/visual_debug.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/3d') diff --git a/src/3d/visual_debug.cc b/src/3d/visual_debug.cc index 77311f6..cd4ccce 100644 --- a/src/3d/visual_debug.cc +++ b/src/3d/visual_debug.cc @@ -26,7 +26,7 @@ void VisualDebug::init(WGPUDevice device, WGPUTextureFormat format) { WGPUBufferDescriptor ub_desc = {}; ub_desc.usage = WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst; - ub_desc.size = sizeof(mat4); + ub_desc.size = sizeof(GlobalUniforms); uniform_buffer_ = wgpuDeviceCreateBuffer(device_, &ub_desc); } @@ -340,9 +340,12 @@ void VisualDebug::add_trajectory(const std::vector& points, } void VisualDebug::update_buffers(const mat4& view_proj) { - // Update Uniforms + // Update Uniforms - fill entire GlobalUniforms structure + GlobalUniforms uniforms = {}; + uniforms.view_proj = view_proj; + // Other fields zeroed (not used by visual debug shader) wgpuQueueWriteBuffer(wgpuDeviceGetQueue(device_), uniform_buffer_, 0, - &view_proj, sizeof(mat4)); + &uniforms, sizeof(GlobalUniforms)); // Update Vertices size_t required_size = lines_.size() * 2 * sizeof(float) * 6; @@ -385,7 +388,7 @@ void VisualDebug::update_buffers(const mat4& view_proj) { WGPUBindGroupEntry bg_entry = {}; bg_entry.binding = 0; bg_entry.buffer = uniform_buffer_; - bg_entry.size = sizeof(mat4); + bg_entry.size = sizeof(GlobalUniforms); WGPUBindGroupDescriptor bg_desc = {}; bg_desc.layout = bind_group_layout_; -- cgit v1.2.3