diff --git a/core/include/internal/gpu.h b/core/include/internal/gpu.h index 6fdbd2a40..c615c8633 100644 --- a/core/include/internal/gpu.h +++ b/core/include/internal/gpu.h @@ -127,7 +127,7 @@ class GPU { for (uint32_t i = 0; i < info->messageCount; ++i) { const auto& msg = info->messages[i]; - IMG2NUM_LOG_INFO( + IMG2NUM_LOG_ERROR( "Shader Error [{}] Line {}:{} - {}", msg.type == wgpu::CompilationMessageType::Error ? "ERR" : "WARN", msg.lineNum, msg.linePos, @@ -149,7 +149,7 @@ class GPU { instance = wgpu::CreateInstance(&instanceDesc); if (!instance) { - IMG2NUM_LOG_INFO("Fatal: WebGPU instance creation failed. Falling back to CPU."); + IMG2NUM_LOG_WARN("Fatal: WebGPU instance creation failed. Falling back to CPU."); cleanup(); return; } @@ -157,7 +157,7 @@ class GPU { // --------------------------------------------------------- // 1. Get Adapter // --------------------------------------------------------- - IMG2NUM_LOG_INFO("Requesting Adapter..."); + IMG2NUM_LOG_DEBUG("Requesting Adapter..."); adapter_ready = false; instance.RequestAdapter( @@ -168,7 +168,7 @@ class GPU { adapter = std::move(a); IMG2NUM_LOG_INFO("Adapter Acquired"); } else { - IMG2NUM_LOG_INFO( + IMG2NUM_LOG_WARN( "Adapter Failed: {}", std::string_view(msg.data ? msg.data : "", msg.length) ); } @@ -185,13 +185,13 @@ class GPU { } if (!adapter) { - IMG2NUM_LOG_INFO("Fatal: Could not get WebGPU Adapter. Falling back to CPU."); + IMG2NUM_LOG_WARN("Fatal: Could not get WebGPU Adapter. Falling back to CPU."); cleanup(); return; } if (wgpu::AdapterInfo info; adapter.GetInfo(&info) != wgpu::Status::Success || info.backendType == wgpu::BackendType::Null) { - IMG2NUM_LOG_INFO("No usable WebGPU adapter found. Falling back to CPU."); + IMG2NUM_LOG_WARN("No usable WebGPU adapter found. Falling back to CPU."); cleanup(); return; } @@ -199,7 +199,7 @@ class GPU { // --------------------------------------------------------- // 2. Get Device // --------------------------------------------------------- - IMG2NUM_LOG_INFO("Requesting Device..."); + IMG2NUM_LOG_DEBUG("Requesting Device..."); device_ready = false; wgpu::DeviceDescriptor deviceDesc = {}; @@ -210,7 +210,7 @@ class GPU { : "Unknown Error (Null message)"; // 2. Print it safely - IMG2NUM_LOG_INFO( + IMG2NUM_LOG_ERROR( "\n[WEBGPU FATAL ERROR] Type: {} | Msg: {}\n", static_cast(type), err_str ); }); @@ -224,7 +224,7 @@ class GPU { if (reason == wgpu::DeviceLostReason::CallbackCancelled) { return; } - IMG2NUM_LOG_INFO( + IMG2NUM_LOG_ERROR( "[DEVICE LOST] Reason: {} Msg: {}", static_cast(reason), err_msg ); } @@ -239,8 +239,8 @@ class GPU { // Copy the adapter's physical limits over to your requested limits requiredLimits = supportedLimits; - IMG2NUM_LOG_INFO("maxBufferSize: {}", requiredLimits.maxBufferSize); - IMG2NUM_LOG_INFO( + IMG2NUM_LOG_DEBUG("maxBufferSize: {}", requiredLimits.maxBufferSize); + IMG2NUM_LOG_DEBUG( "maxStorageBufferBindingSize: {}", requiredLimits.maxStorageBufferBindingSize ); @@ -255,7 +255,7 @@ class GPU { device = std::move(d); IMG2NUM_LOG_INFO("Device Acquired"); } else { - IMG2NUM_LOG_INFO( + IMG2NUM_LOG_WARN( "Device Failed: {}", msg.data && msg.length > 0 ? std::string(msg.data, msg.length) : "Unknown error" @@ -274,13 +274,13 @@ class GPU { } if (!device) { - IMG2NUM_LOG_INFO("Fatal: Could not get WebGPU Device. Falling back to CPU."); + IMG2NUM_LOG_WARN("Fatal: Could not get WebGPU Device. Falling back to CPU."); cleanup(); return; } if (!validate_device()) { - IMG2NUM_LOG_INFO("Fatal: Could not get WebGPU Device. Falling back to CPU."); + IMG2NUM_LOG_WARN("Fatal: Could not get WebGPU Device. Falling back to CPU."); cleanup(); return; } diff --git a/core/include/internal/log.h b/core/include/internal/log.h index 03c27266a..3139b1a2b 100644 --- a/core/include/internal/log.h +++ b/core/include/internal/log.h @@ -8,7 +8,7 @@ namespace img2num::third_party_wrappers { // Lazily-created library logger. inline spdlog::logger& logger() { static const auto instance = [] { - auto l = spdlog::stdout_color_mt("img2num"); + auto l = spdlog::stderr_color_mt("img2num"); // Sync runtime filtering with compile-time stripping l->set_level(static_cast(SPDLOG_ACTIVE_LEVEL)); return l; diff --git a/core/src/internal/bilateral_filter_gpu.cpp b/core/src/internal/bilateral_filter_gpu.cpp index af6b2bdfa..e8e7cd916 100644 --- a/core/src/internal/bilateral_filter_gpu.cpp +++ b/core/src/internal/bilateral_filter_gpu.cpp @@ -56,7 +56,7 @@ void bilateral_filter_gpu( const uint32_t h = static_cast(height); constexpr uint32_t bpp = 4; // RGBA8 = 4 bytes per pixel - IMG2NUM_LOG_INFO("begin wgpu portion"); + IMG2NUM_LOG_DEBUG("begin wgpu portion"); // 1. Create textures (RAII — destroyed automatically on scope exit) gpu::Texture inputTexture( @@ -64,10 +64,10 @@ void bilateral_filter_gpu( wgpu::TextureUsage::TextureBinding | wgpu::TextureUsage::CopyDst ); - IMG2NUM_LOG_INFO("upload texture"); + IMG2NUM_LOG_DEBUG("upload texture"); inputTexture.write(image, bpp * width * height, bpp); - IMG2NUM_LOG_INFO("create output texture"); + IMG2NUM_LOG_DEBUG("create output texture"); gpu::Texture outputTexture( w, h, wgpu::TextureFormat::RGBA8Unorm, wgpu::TextureUsage::StorageBinding | wgpu::TextureUsage::CopySrc @@ -83,7 +83,7 @@ void bilateral_filter_gpu( wgpu::TextureUsage::StorageBinding | wgpu::TextureUsage::TextureBinding ); - IMG2NUM_LOG_INFO("create buffer"); + IMG2NUM_LOG_DEBUG("create buffer"); // 2. Create uniform buffer with filter parameters gpu::Buffer paramBuffer( 1, wgpu::BufferUsage::Uniform | wgpu::BufferUsage::CopyDst @@ -169,12 +169,12 @@ void bilateral_filter_gpu( wgpu::CommandBuffer commands = encoder.Finish(); GPU::getClassInstance().get_queue().Submit(1, &commands); - IMG2NUM_LOG_INFO("queue submit"); + IMG2NUM_LOG_DEBUG("queue submit"); // 6. Readback — handles staging buffer, MapAsync, alignment stripping automatically std::vector result = outputTexture.read(bpp); std::memcpy(image, result.data(), result.size()); - IMG2NUM_LOG_INFO("done memcpy"); + IMG2NUM_LOG_DEBUG("done memcpy"); // All textures and buffers are destroyed automatically by RAII destructors #if defined(__EMSCRIPTEN__) diff --git a/core/src/internal/kmeans_gpu.cpp b/core/src/internal/kmeans_gpu.cpp index 7c320fd62..825110eee 100644 --- a/core/src/internal/kmeans_gpu.cpp +++ b/core/src/internal/kmeans_gpu.cpp @@ -248,7 +248,7 @@ void kmeans_gpu( } } - IMG2NUM_LOG_INFO("starting"); + IMG2NUM_LOG_DEBUG("starting"); // Step 2: Initialize centroids via K-Means++ switch (color_space) { @@ -260,7 +260,7 @@ void kmeans_gpu( break; } - IMG2NUM_LOG_INFO("kmeans++ init done"); + IMG2NUM_LOG_DEBUG("kmeans++ init done"); // ========================================================================= // GPU resource setup (previously in setup() function) @@ -377,7 +377,7 @@ void kmeans_gpu( // ========================================================================= // Main K-Means loop — all iterations batched into one submission // ========================================================================= - IMG2NUM_LOG_INFO("start iterations"); + IMG2NUM_LOG_DEBUG("start iterations"); uint32_t wgX = gpu::workgroup_count(w); uint32_t wgY = gpu::workgroup_count(h); @@ -388,17 +388,17 @@ void kmeans_gpu( } wgpu::CommandBuffer commands = encoder.Finish(); GPU::getClassInstance().get_queue().Submit(1, &commands); - IMG2NUM_LOG_INFO("done iterations"); + IMG2NUM_LOG_DEBUG("done iterations"); // ========================================================================= // Readback — alignment stripping handled automatically // ========================================================================= // Read labels (RGBA32Uint, 16 bytes/pixel — extract R channel as label) - IMG2NUM_LOG_INFO("read out"); + IMG2NUM_LOG_DEBUG("read out"); std::vector labelData = labelTexture.read(bpp); - IMG2NUM_LOG_INFO("mapping labels"); + IMG2NUM_LOG_DEBUG("mapping labels"); for (int32_t i = 0; i < num_pixels; ++i) { uint32_t r = 0; std::memcpy(&r, &labelData[i * bpp], sizeof(uint32_t)); @@ -409,7 +409,7 @@ void kmeans_gpu( std::vector centroidData = centroidTexture.read(bpp); const float* centroidFloats = reinterpret_cast(centroidData.data()); - IMG2NUM_LOG_INFO("mapping centroids"); + IMG2NUM_LOG_DEBUG("mapping centroids"); for (int i = 0; i < k; i++) { float cr = centroidFloats[i * 4]; float cg = centroidFloats[i * 4 + 1]; @@ -445,7 +445,7 @@ void kmeans_gpu( } // Write labels to out_labels - IMG2NUM_LOG_INFO("copying labels out"); + IMG2NUM_LOG_DEBUG("copying labels out"); std::memcpy(out_labels, labels.data(), labels.size() * sizeof(int32_t)); #if defined(__EMSCRIPTEN__)