From 77d77f0a5c2fa9d4e378dfaa7eccf3a53a3a8f8e Mon Sep 17 00:00:00 2001 From: Andy Hovingh <6198728+AndyHovingh@users.noreply.github.com> Date: Wed, 11 Jun 2025 23:48:55 -0500 Subject: [PATCH] webgpu: fix logging --- filament/backend/src/webgpu/WebGPUStrings.h | 80 ++++--------------- .../backend/src/webgpu/WebGPUSwapChain.cpp | 44 +++------- filament/backend/src/webgpu/WebGPUTexture.cpp | 48 ++++------- .../src/webgpu/WebGPUVertexBufferInfo.cpp | 64 +++++---------- .../src/webgpu/platform/WebGPUPlatform.cpp | 72 ++++++----------- 5 files changed, 89 insertions(+), 219 deletions(-) diff --git a/filament/backend/src/webgpu/WebGPUStrings.h b/filament/backend/src/webgpu/WebGPUStrings.h index aab314acfd..f77eda43cd 100644 --- a/filament/backend/src/webgpu/WebGPUStrings.h +++ b/filament/backend/src/webgpu/WebGPUStrings.h @@ -21,50 +21,27 @@ #include -#include -#include - -#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) #include -#endif #include #include -#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) #include -#endif +#include #include /** * Reusable set of convenience functions for strings -- generally string views, literals, & - * streaming -- used in the WebGPU backend + * strings -- used in the WebGPU backend */ namespace filament::backend { #if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) -/** - * Convenience template to print WGPU types (which don't support Filament's utils::io::ostream) - * @tparam WebGPUPrintable e.g. wgpu::FeatureName type - * @param out stream to print to - * @param printable the instance to print - * @return the stream printed to - * - * Example usage (because including the template operator override itself does not compile): - * #if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) - * utils::io::ostream& operator<<(utils::io::ostream& out, - * const wgpu::FeatureName featureName) noexcept { - * return streamInsertWebGPUPrintable(out, featureName); - * } - * #endif - */ template -utils::io::ostream& streamInsertWebGPUPrintable(utils::io::ostream& out, - const WebGPUPrintable printable) { - std::stringstream printableStream; - printableStream << printable; - out << printableStream.str(); - return out; +[[nodiscard]] inline std::string webGPUPrintableToString(const WebGPUPrintable printable) { + std::stringstream out; + out << printable; + return out.str(); } #endif @@ -115,46 +92,17 @@ utils::io::ostream& streamInsertWebGPUPrintable(utils::io::ostream& out, } } -/** - * Convenience template to print wgpu::RequestAdapterOptions - * @tparam STREAM_TYPE useful namely for streaming to either an utils::io::ostream OR - * utils::details::PanicStream, but also for any kind of stream - * @param out stream to print to - * @param options instance to be printed - * @return stream printed to - * - * Example usage (because including the template operator override itself does not compile): - * template - * STREAM_TYPE& operator<<(STREAM_TYPE& out, wgpu::RequestAdapterOptions const& options) noexcept { - * return streamInsertRequestAdapterOptions(out, options); - * } - */ -template -STREAM_TYPE& streamInsertRequestAdapterOptions(STREAM_TYPE& out, - wgpu::RequestAdapterOptions const& options) noexcept { +[[nodiscard]] inline std::string adapterOptionsToString( + wgpu::RequestAdapterOptions const& options) { + std::stringstream out; out << "power preference " << powerPreferenceToString(options.powerPreference) << " force fallback adapter " << bool(options.forceFallbackAdapter) << " backend type " << backendTypeToString(options.backendType); - return out; + return out.str(); } -/** - * Convenience template to print wgpu::AdapterInfo - * @tparam STREAM_TYPE useful namely for streaming to either an utils::io::ostream OR - * utils::details::PanicStream, but also for any kind of stream - * @param out stream to print to - * @param options instance to be printed - * @return stream printed to - * - * Example usage (because including the template operator override itself does not compile): - * template - * STREAM_TYPE& operator<<(STREAM_TYPE& out, wgpu::AdapterInfo const& info) noexcept { - * return streamInsertRequestAdapterInfo(out, info); - * } - */ -template -STREAM_TYPE& streamInsertRequestAdapterInfo(STREAM_TYPE& out, - wgpu::AdapterInfo const& info) noexcept { +[[nodiscard]] std::string adapterInfoToString(wgpu::AdapterInfo const& info) { + std::stringstream out; out << "vendor (" << info.vendorID << ") '" << info.vendor << "' device (" << info.deviceID << ") '" << info.device << "' adapter " << adapterTypeToString(info.adapterType) @@ -162,7 +110,7 @@ STREAM_TYPE& streamInsertRequestAdapterInfo(STREAM_TYPE& out, << " architecture '" << info.architecture << "' subgroupMinSize " << info.subgroupMinSize << " subgroupMaxSize " << info.subgroupMaxSize; - return out; + return out.str(); } [[nodiscard]] constexpr std::string_view deviceLostReasonToString( @@ -175,7 +123,7 @@ STREAM_TYPE& streamInsertRequestAdapterInfo(STREAM_TYPE& out, } } -[[nodiscard]] constexpr std::string_view filamentShaderStageToString(ShaderStage stage) { +[[nodiscard]] constexpr std::string_view filamentShaderStageToString(const ShaderStage stage) { switch (stage) { case ShaderStage::VERTEX: return "vertex"; case ShaderStage::FRAGMENT: return "fragment"; diff --git a/filament/backend/src/webgpu/WebGPUSwapChain.cpp b/filament/backend/src/webgpu/WebGPUSwapChain.cpp index 77004355a6..3f54cbf0e9 100644 --- a/filament/backend/src/webgpu/WebGPUSwapChain.cpp +++ b/filament/backend/src/webgpu/WebGPUSwapChain.cpp @@ -24,43 +24,25 @@ #include "backend/DriverEnums.h" #include -#include #include #include #include +namespace filament::backend { + namespace { #if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) -utils::io::ostream& operator<<(utils::io::ostream& out, const wgpu::TextureFormat format) noexcept { - return filament::backend::streamInsertWebGPUPrintable(out, format); -} - -utils::io::ostream& operator<<(utils::io::ostream& out, - const wgpu::TextureUsage textureUsage) noexcept { - return filament::backend::streamInsertWebGPUPrintable(out, textureUsage); -} - -utils::io::ostream& operator<<(utils::io::ostream& out, - const wgpu::PresentMode presentMode) noexcept { - return filament::backend::streamInsertWebGPUPrintable(out, presentMode); -} - -utils::io::ostream& operator<<(utils::io::ostream& out, - const wgpu::CompositeAlphaMode alphaMode) noexcept { - return filament::backend::streamInsertWebGPUPrintable(out, alphaMode); -} - void printSurfaceCapabilitiesDetails(wgpu::SurfaceCapabilities const& capabilities) { FWGPU_LOGI << "WebGPU surface capabilities:"; - FWGPU_LOGI << " surface usages: " << capabilities.usages; + FWGPU_LOGI << " surface usages: " << webGPUPrintableToString(capabilities.usages); FWGPU_LOGI << " surface formats (" << capabilities.formatCount << "):"; if (capabilities.formatCount > 0 && capabilities.formats != nullptr) { std::for_each(capabilities.formats, capabilities.formats + capabilities.formatCount, [](wgpu::TextureFormat const format) { - FWGPU_LOGI << " " << format; + FWGPU_LOGI << " " << webGPUPrintableToString(format); }); } FWGPU_LOGI << " surface present modes (" << capabilities.presentModeCount << "):"; @@ -68,7 +50,7 @@ void printSurfaceCapabilitiesDetails(wgpu::SurfaceCapabilities const& capabiliti std::for_each(capabilities.presentModes, capabilities.presentModes + capabilities.presentModeCount, [](wgpu::PresentMode const presentMode) { - FWGPU_LOGI << " " << presentMode; + FWGPU_LOGI << " " << webGPUPrintableToString(presentMode); }); } FWGPU_LOGI << " surface alpha modes (" << capabilities.alphaModeCount << "):"; @@ -76,7 +58,7 @@ void printSurfaceCapabilitiesDetails(wgpu::SurfaceCapabilities const& capabiliti std::for_each(capabilities.alphaModes, capabilities.alphaModes + capabilities.alphaModeCount, [](wgpu::CompositeAlphaMode const alphaMode) { - FWGPU_LOGI << " " << alphaMode; + FWGPU_LOGI << " " << webGPUPrintableToString(alphaMode); }); } } @@ -84,20 +66,20 @@ void printSurfaceCapabilitiesDetails(wgpu::SurfaceCapabilities const& capabiliti void printSurfaceConfiguration(wgpu::SurfaceConfiguration const& config, wgpu::TextureFormat depthFormat) { FWGPU_LOGI << "WebGPU surface configuration:"; - FWGPU_LOGI << " surface format: " << config.format; - FWGPU_LOGI << " surface usage: " << config.usage; + FWGPU_LOGI << " surface format: " << webGPUPrintableToString(config.format); + FWGPU_LOGI << " surface usage: " << webGPUPrintableToString(config.usage); FWGPU_LOGI << " surface view formats (" << config.viewFormatCount << "):"; if (config.viewFormatCount > 0 && config.viewFormats != nullptr) { std::for_each(config.viewFormats, config.viewFormats + config.viewFormatCount, [](wgpu::TextureFormat const viewFormat) { - FWGPU_LOGI << " " << viewFormat; + FWGPU_LOGI << " " << webGPUPrintableToString(viewFormat); }); } - FWGPU_LOGI << " surface alpha mode: " << config.alphaMode; + FWGPU_LOGI << " surface alpha mode: " << webGPUPrintableToString(config.alphaMode); FWGPU_LOGI << " surface width: " << config.width; FWGPU_LOGI << " surface height: " << config.height; - FWGPU_LOGI << " surface present mode: " << config.presentMode; - FWGPU_LOGI << "WebGPU selected depth format: " << depthFormat; + FWGPU_LOGI << " surface present mode: " << webGPUPrintableToString(config.presentMode); + FWGPU_LOGI << "WebGPU selected depth format: " << webGPUPrintableToString(depthFormat); } #endif// FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) @@ -257,8 +239,6 @@ void initConfig(wgpu::SurfaceConfiguration& config, wgpu::Device const& device, }// namespace -namespace filament::backend { - WebGPUSwapChain::WebGPUSwapChain(wgpu::Surface&& surface, wgpu::Extent2D const& surfaceSize, wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags) : mDevice(device), diff --git a/filament/backend/src/webgpu/WebGPUTexture.cpp b/filament/backend/src/webgpu/WebGPUTexture.cpp index cb0d327247..a8922aeaba 100644 --- a/filament/backend/src/webgpu/WebGPUTexture.cpp +++ b/filament/backend/src/webgpu/WebGPUTexture.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) @@ -343,8 +342,7 @@ WebGPUTexture::WebGPUTexture(const SamplerType samplerType, const uint8_t levels std::stringstream textureFormatStream; textureFormatStream << mWebGPUFormat; FWGPU_LOGD << "Texture '" << textureDescriptor.label << "' has view format " - << viewFormatStream.str() << " and texture format " << textureFormatStream.str() - << utils::io::endl; + << viewFormatStream.str() << " and texture format " << textureFormatStream.str(); } #endif } @@ -470,51 +468,43 @@ wgpu::TextureFormat WebGPUTexture::fToWGPUTextureFormat(TextureFormat const& fFo // No direct mapping in wgpu. Could potentially map to RGBA8Unorm // and discard the alpha and lower precision. FWGPU_LOGW << "Requested Filament texture format RGB565 but getting " - "wgpu::TextureFormat::Undefined (no direct mapping in wgpu)" - << utils::io::endl; + "wgpu::TextureFormat::Undefined (no direct mapping in wgpu)"; return wgpu::TextureFormat::Undefined; case TextureFormat::RGB9_E5: return wgpu::TextureFormat::RGB9E5Ufloat; case TextureFormat::RGB5_A1: // No direct mapping in wgpu. Could potentially map to RGBA8Unorm // and handle the packing/unpacking in shaders. FWGPU_LOGW << "Requested Filament texture format RGB5_A1 but getting " - "wgpu::TextureFormat::Undefined (no direct mapping in wgpu)" - << utils::io::endl; + "wgpu::TextureFormat::Undefined (no direct mapping in wgpu)"; return wgpu::TextureFormat::Undefined; case TextureFormat::RGBA4: // No direct mapping in wgpu. Could potentially map to RGBA8Unorm // and handle the packing/unpacking in shaders. FWGPU_LOGW << "Requested Filament texture format RGBA4 but getting " - "wgpu::TextureFormat::Undefined (no direct mapping in wgpu)" - << utils::io::endl; + "wgpu::TextureFormat::Undefined (no direct mapping in wgpu)"; return wgpu::TextureFormat::Undefined; case TextureFormat::RGB8: FWGPU_LOGW << "Requested Filament texture format RGB8 but getting " "wgpu::TextureFormat::RGBA8Unorm (no direct sRGB equivalent in wgpu " - "without alpha)" - << utils::io::endl; + "without alpha)"; return wgpu::TextureFormat::RGBA8Unorm; case TextureFormat::SRGB8: FWGPU_LOGW << "Requested Filament texture format SRGB8 but getting " "wgpu::TextureFormat::RGBA8UnormSrgb (no direct sRGB equivalent in wgpu " - "without alpha)" - << utils::io::endl; + "without alpha)"; return wgpu::TextureFormat::RGBA8UnormSrgb; case TextureFormat::RGB8_SNORM: FWGPU_LOGW << "Requested Filament texture format RGB8_SNORM but getting " - "wgpu::TextureFormat::RGBA8Snorm (no direct mapping in wgpu without alpha)" - << utils::io::endl; + "wgpu::TextureFormat::RGBA8Snorm (no direct mapping in wgpu without alpha)"; return wgpu::TextureFormat::RGBA8Snorm; case TextureFormat::RGB8UI: FWGPU_LOGW << "Requested Filament texture format RGB8UI but getting " - "wgpu::TextureFormat::RGBA8Uint (no direct mapping in wgpu without alpha)" - << utils::io::endl; + "wgpu::TextureFormat::RGBA8Uint (no direct mapping in wgpu without alpha)"; return wgpu::TextureFormat::RGBA8Uint; case TextureFormat::RGB8I: FWGPU_LOGW << "Requested Filament texture format RGB8I but getting " - "wgpu::TextureFormat::RGBA8Sint (no direct mapping in wgpu without alpha)" - << utils::io::endl; + "wgpu::TextureFormat::RGBA8Sint (no direct mapping in wgpu without alpha)"; return wgpu::TextureFormat::RGBA8Sint; case TextureFormat::R11F_G11F_B10F: return wgpu::TextureFormat::RG11B10Ufloat; case TextureFormat::UNUSED: return wgpu::TextureFormat::Undefined; @@ -522,38 +512,32 @@ wgpu::TextureFormat WebGPUTexture::fToWGPUTextureFormat(TextureFormat const& fFo case TextureFormat::RGB16F: FWGPU_LOGW << "Requested Filament texture format RGB16F but getting " - "wgpu::TextureFormat::RGBA16Float (no direct mapping in wgpu without alpha)" - << utils::io::endl; + "wgpu::TextureFormat::RGBA16Float (no direct mapping in wgpu without alpha)"; return wgpu::TextureFormat::RGBA16Float; case TextureFormat::RGB16UI: FWGPU_LOGW << "Requested Filament texture format RGB16UI but getting " - "wgpu::TextureFormat::RGBA16Uint (no direct mapping in wgpu without alpha)" - << utils::io::endl; + "wgpu::TextureFormat::RGBA16Uint (no direct mapping in wgpu without alpha)"; return wgpu::TextureFormat::RGBA16Uint; case TextureFormat::RGB16I: FWGPU_LOGW << "Requested Filament texture format RGB16I but getting " - "wgpu::TextureFormat::RGBA16Sint (no direct mapping in wgpu without alpha)" - << utils::io::endl; + "wgpu::TextureFormat::RGBA16Sint (no direct mapping in wgpu without alpha)"; return wgpu::TextureFormat::RGBA16Sint; case TextureFormat::RGB32F: FWGPU_LOGW << "Requested Filament texture format RGB32F but getting " - "wgpu::TextureFormat::RGBA32Float (no direct mapping in wgpu without alpha)" - << utils::io::endl; + "wgpu::TextureFormat::RGBA32Float (no direct mapping in wgpu without alpha)"; return wgpu::TextureFormat::RGBA32Float; case TextureFormat::RGB32UI: FWGPU_LOGW << "Requested Filament texture format RGB32UI but getting " - "wgpu::TextureFormat::RGBA32Uint (no direct mapping in wgpu without alpha)" - << utils::io::endl; + "wgpu::TextureFormat::RGBA32Uint (no direct mapping in wgpu without alpha)"; return wgpu::TextureFormat::RGBA32Uint; case TextureFormat::RGB32I: FWGPU_LOGW << "Requested Filament texture format RGB32I but getting " - "wgpu::TextureFormat::RGBA32Sint (no direct mapping in wgpu without alpha)" - << utils::io::endl; + "wgpu::TextureFormat::RGBA32Sint (no direct mapping in wgpu without alpha)"; return wgpu::TextureFormat::RGBA32Sint; case TextureFormat::DXT1_RGB: return wgpu::TextureFormat::BC1RGBAUnorm; case TextureFormat::DXT1_RGBA: return wgpu::TextureFormat::BC1RGBAUnorm; @@ -573,7 +557,7 @@ wgpu::TextureView WebGPUTexture::makeTextureView(const uint8_t& baseLevel, if (baseLevel > 0 && !mSupportsMultipleMipLevels) { FWGPU_LOGW << "Trying to make a texture view into a level (" << static_cast(baseLevel) - << ") for which we cannot generate mip levels." << utils::io::endl; + << ") for which we cannot generate mip levels."; } #endif const wgpu::TextureViewDescriptor textureViewDescriptor{ diff --git a/filament/backend/src/webgpu/WebGPUVertexBufferInfo.cpp b/filament/backend/src/webgpu/WebGPUVertexBufferInfo.cpp index d4f280b49d..795cf2c36a 100644 --- a/filament/backend/src/webgpu/WebGPUVertexBufferInfo.cpp +++ b/filament/backend/src/webgpu/WebGPUVertexBufferInfo.cpp @@ -22,7 +22,6 @@ #include #include -#include #include @@ -57,26 +56,22 @@ namespace { case ElementType::BYTE3: FWGPU_LOGW << "Requested Filament vertex format BYTE3 (normalized) but getting " - "wgpu::VertexFormat::Snorm8x4 (no direct mapping in wgpu for x3 byte)" - << utils::io::endl; + "wgpu::VertexFormat::Snorm8x4 (no direct mapping in wgpu for x3 byte)"; return VertexFormat::Snorm8x4; // NOT MINSPEC case ElementType::UBYTE3: FWGPU_LOGW << "Requested Filament vertex format UBYTE3 (normalized) but getting " - "wgpu::VertexFormat::Unorm8x4 (no direct mapping in wgpu for x3 byte)" - << utils::io::endl; + "wgpu::VertexFormat::Unorm8x4 (no direct mapping in wgpu for x3 byte)"; return VertexFormat::Unorm8x4; // NOT MINSPEC case ElementType::SHORT3: FWGPU_LOGW << "Requested Filament vertex format SHORT3 (normalized) but getting " "wgpu::VertexFormat::Snorm16x4 (no direct mapping in wgpu for x3 " - "half/short)" - << utils::io::endl; + "half/short)"; return VertexFormat::Snorm16x4; // NOT MINSPEC case ElementType::USHORT3: FWGPU_LOGW << "Requested Filament vertex format USHORT3 (normalized) but getting " "wgpu::VertexFormat::Unorm16x4 (no direct mapping in wgpu for x3 " - "half/short)" - << utils::io::endl; + "half/short)"; return VertexFormat::Unorm16x4; // NOT MINSPEC // Four Component Types case ElementType::BYTE4: return VertexFormat::Snorm8x4; @@ -97,26 +92,22 @@ namespace { case ElementType::BYTE: if (integer) return VertexFormat::Sint8; FWGPU_LOGW << "Requested Filament vertex format BYTE (float) but getting " - "wgpu::VertexFormat::Float16 (no direct mapping in wgpu for 8 bit float)" - << utils::io::endl; + "wgpu::VertexFormat::Float16 (no direct mapping in wgpu for 8 bit float)"; return wgpu::VertexFormat::Float16; case ElementType::UBYTE: if (integer) return VertexFormat::Uint8; FWGPU_LOGW << "Requested Filament vertex format UBYTE (float) but getting " - "wgpu::VertexFormat::Float16 (no direct mapping in wgpu for 8 bit float)" - << utils::io::endl; + "wgpu::VertexFormat::Float16 (no direct mapping in wgpu for 8 bit float)"; return VertexFormat::Float16; case ElementType::SHORT: if (integer) return VertexFormat::Sint16; FWGPU_LOGW << "Requested Filament vertex format SHORT (float) and getting " - "wgpu::VertexFormat::Float16 (potential loss of precision?)" - << utils::io::endl; + "wgpu::VertexFormat::Float16 (potential loss of precision?)"; return VertexFormat ::Float16; case ElementType::USHORT: if (integer) return VertexFormat::Uint16; FWGPU_LOGW << "Requested Filament vertex format USHORT (float) and getting " - "wgpu::VertexFormat::Float16 (potential loss of precision?)" - << utils::io::endl; + "wgpu::VertexFormat::Float16 (potential loss of precision?)"; return VertexFormat::Float16; case ElementType::HALF: return VertexFormat::Float16; case ElementType::INT: return VertexFormat::Sint32; @@ -127,58 +118,49 @@ namespace { if (integer) return VertexFormat::Sint8x2; FWGPU_LOGW << "Requested Filament vertex format BYTE2 (float) but getting " - "wgpu::VertexFormat::Float16x2 (no direct mapping in wgpu for 8 bit float)" - << utils::io::endl; + "wgpu::VertexFormat::Float16x2 (no direct mapping in wgpu for 8 bit float)"; return VertexFormat::Float16x2; case ElementType::UBYTE2: if (integer) return VertexFormat::Uint8x2; FWGPU_LOGW << "Requested Filament vertex format UBYTE2 (float) but getting " - "wgpu::VertexFormat::Float16x2 (no direct mapping in wgpu for 8 bit float)" - << utils::io::endl; + "wgpu::VertexFormat::Float16x2 (no direct mapping in wgpu for 8 bit float)"; return VertexFormat::Float16x2; case ElementType::SHORT2: if (integer) return VertexFormat::Sint16x2; FWGPU_LOGW << "Requested Filament vertex format SHORT2 (float) but getting " - "wgpu::VertexFormat::Float16x2 (potential loss of precision?)" - << utils::io::endl; + "wgpu::VertexFormat::Float16x2 (potential loss of precision?)"; return VertexFormat::Float16x2; case ElementType::USHORT2: if (integer) return VertexFormat::Uint16x2; FWGPU_LOGW << "Requested Filament vertex format USHORT2 (float) but getting " - "wgpu::VertexFormat::Float16x2 (potential loss of precision?)" - << utils::io::endl; + "wgpu::VertexFormat::Float16x2 (potential loss of precision?)"; return VertexFormat::Float16x2; case ElementType::HALF2: return VertexFormat::Float16x2; case ElementType::FLOAT2: return VertexFormat::Float32x2; // Three Component Types case ElementType::BYTE3: FWGPU_LOGW << "Requested Filament vertex format BYTE3 but getting " - "wgpu::VertexFormat::Sint8x4 (no direct mapping in wgpu for x3 byte)" - << utils::io::endl; + "wgpu::VertexFormat::Sint8x4 (no direct mapping in wgpu for x3 byte)"; return VertexFormat::Sint8x4; // NOT MINSPEC case ElementType::UBYTE3: FWGPU_LOGW << "Requested Filament vertex format UBYTE3 but getting " - "wgpu::VertexFormat::Uint8x4 (no direct mapping in wgpu for x3 byte)" - << utils::io::endl; + "wgpu::VertexFormat::Uint8x4 (no direct mapping in wgpu for x3 byte)"; return VertexFormat::Uint8x4; // NOT MINSPEC case ElementType::SHORT3: FWGPU_LOGW << "Requested Filament vertex format SHORT3 but getting " - "wgpu::VertexFormat::Sint16x4 (no direct mapping in wgpu for x3 half/short)" - << utils::io::endl; + "wgpu::VertexFormat::Sint16x4 (no direct mapping in wgpu for x3 half/short)"; return VertexFormat::Sint16x4; // NOT MINSPEC case ElementType::USHORT3: FWGPU_LOGW << "Requested Filament vertex format USHORT3 but getting " - "wgpu::VertexFormat::Uint16x4 (no direct mapping in wgpu for x3 half/short)" - << utils::io::endl; + "wgpu::VertexFormat::Uint16x4 (no direct mapping in wgpu for x3 half/short)"; return VertexFormat::Uint16x4; // NOT MINSPEC case ElementType::HALF3: FWGPU_LOGW << "Requested Filament vertex format HALF3 but getting " - "wgpu::VertexFormat::Float16x4 (no direct mapping in wgpu for x3 half/short)" - << utils::io::endl; + "wgpu::VertexFormat::Float16x4 (no direct mapping in wgpu for x3 half/short)"; return VertexFormat::Float16x4; // NOT MINSPEC case ElementType::FLOAT3: return VertexFormat::Float32x3; // Four Component Types @@ -186,27 +168,23 @@ namespace { if (integer) return VertexFormat::Sint8x4; FWGPU_LOGW << "Requested Filament vertex format BYTE4 (float) but getting " - "wgpu::VertexFormat::Float16x4 (no direct mapping in wgpu for 8 bit float)" - << utils::io::endl; + "wgpu::VertexFormat::Float16x4 (no direct mapping in wgpu for 8 bit float)"; return VertexFormat::Float16x4; case ElementType::UBYTE4: if (integer) return VertexFormat::Uint8x4; FWGPU_LOGW << "Requested Filament vertex format UBYTE4 (float) but getting " - "wgpu::VertexFormat::Float16x4 (no direct mapping in wgpu for 8 bit float)" - << utils::io::endl; + "wgpu::VertexFormat::Float16x4 (no direct mapping in wgpu for 8 bit float)"; return VertexFormat::Float16x4; case ElementType::SHORT4: if (integer) return VertexFormat::Sint16x4; FWGPU_LOGW << "Requested Filament vertex format SHORT4 (float) but getting " - "wgpu::VertexFormat::Float16x4 (potential loss of precision?)" - << utils::io::endl; + "wgpu::VertexFormat::Float16x4 (potential loss of precision?)"; return VertexFormat::Float16x4; case ElementType::USHORT4: if (integer) return VertexFormat::Uint16x4; FWGPU_LOGW << "Requested Filament vertex format USHORT4 (float) but getting " - "wgpu::VertexFormat::Float16x4 (potential loss of precision?)" - << utils::io::endl; + "wgpu::VertexFormat::Float16x4 (potential loss of precision?)"; return VertexFormat::Float16x4; case ElementType::HALF4: return VertexFormat::Float16x4; case ElementType::FLOAT4: return VertexFormat::Float32x4; diff --git a/filament/backend/src/webgpu/platform/WebGPUPlatform.cpp b/filament/backend/src/webgpu/platform/WebGPUPlatform.cpp index dc86c6f227..85d3203027 100644 --- a/filament/backend/src/webgpu/platform/WebGPUPlatform.cpp +++ b/filament/backend/src/webgpu/platform/WebGPUPlatform.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -39,6 +38,7 @@ #include #include #if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) +#include #include #include #endif @@ -117,28 +117,6 @@ constexpr void forEachLimitToValidate(std::function } } -#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) -utils::io::ostream& operator<<(utils::io::ostream& out, - const wgpu::WGSLLanguageFeatureName languageFeatureName) noexcept { - return streamInsertWebGPUPrintable(out, languageFeatureName); -} - -utils::io::ostream& operator<<(utils::io::ostream& out, - const wgpu::FeatureName featureName) noexcept { - return streamInsertWebGPUPrintable(out, featureName); -} -#endif - -template -STREAM_TYPE& operator<<(STREAM_TYPE& out, wgpu::RequestAdapterOptions const& options) noexcept { - return streamInsertRequestAdapterOptions(out, options); -} - -template -STREAM_TYPE& operator<<(STREAM_TYPE& out, wgpu::AdapterInfo const& info) noexcept { - return streamInsertRequestAdapterInfo(out, info); -} - constexpr bool isDefined(uint32_t limit) { return limit < wgpu::kLimitU32Undefined; } [[maybe_unused]] constexpr bool isDefined(uint64_t limit) { @@ -259,7 +237,7 @@ void printInstanceDetails(wgpu::Instance const& instance) { supportedWGSLLanguageFeatures.features + supportedWGSLLanguageFeatures.featureCount, [](wgpu::WGSLLanguageFeatureName const featureName) { - FWGPU_LOGI << " " << featureName; + FWGPU_LOGI << " " << webGPUPrintableToString(featureName); }); } } @@ -299,23 +277,22 @@ void printInstanceDetails(wgpu::Instance const& instance) { #if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) void printLimit(std::string_view name, const std::variant value) { - FWGPU_LOGI << " " << name.data() << ": "; + static constexpr std::string_view indent = " "; bool undefined = true; if (std::holds_alternative(value)) { if (std::get(value) != WGPU_LIMIT_U32_UNDEFINED) { undefined = false; - FWGPU_LOGI << std::get(value); + FWGPU_LOGI << indent << name.data() << ": " << std::get(value); } } else if (std::holds_alternative(value)) { if (std::get(value) != WGPU_LIMIT_U64_UNDEFINED) { undefined = false; - FWGPU_LOGI << std::get(value); + FWGPU_LOGI << indent << name.data() << ": " << std::get(value); } } if (undefined) { - FWGPU_LOGI << "UNDEFINED"; + FWGPU_LOGI << indent << name.data() << ": UNDEFINED"; } - FWGPU_LOGI << ""; } #endif// FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) @@ -393,16 +370,16 @@ struct AdapterDetails final { } }; -template -STREAM_TYPE& operator<<(STREAM_TYPE& out, AdapterDetails const& details) noexcept { - out << details.info +[[nodiscard]] std::string toString(AdapterDetails const& details) { + std::stringstream out; + out << adapterInfoToString(details.info) << " power preference " << powerPreferenceToString(details.powerPreference); - return out; + return out.str(); } #if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) void printAdapterDetails(AdapterDetails const& details) { - FWGPU_LOGI << "Selected WebGPU adapter info: " << details; + FWGPU_LOGI << "Selected WebGPU adapter info: " << toString(details); wgpu::SupportedFeatures supportedFeatures{}; details.adapter.GetFeatures(&supportedFeatures); FWGPU_LOGI << "WebGPU adapter supported features (" << supportedFeatures.featureCount @@ -411,7 +388,7 @@ void printAdapterDetails(AdapterDetails const& details) { std::for_each(supportedFeatures.features, supportedFeatures.features + supportedFeatures.featureCount, [](wgpu::FeatureName const featureName) { - FWGPU_LOGI << " " << featureName; + FWGPU_LOGI << " " << webGPUPrintableToString(featureName); }); } wgpu::Limits supportedLimits{}; @@ -444,12 +421,12 @@ struct AdapterDetailsHash final { return details.adapter.HasFeature(featureName); })) { #if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) - FWGPU_LOGI << "WebGPU adapter " << details + FWGPU_LOGI << "WebGPU adapter " << toString(details) << " does not have the minimum required features."; FWGPU_LOGI << "Missing required feature(s): "; for (wgpu::FeatureName const& requiredFeature: REQUIRED_FEATURES) { if (!details.adapter.HasFeature(requiredFeature)) { - FWGPU_LOGI << requiredFeature; + FWGPU_LOGI << webGPUPrintableToString(requiredFeature); } } FWGPU_LOGI << ""; @@ -458,10 +435,10 @@ struct AdapterDetailsHash final { } wgpu::Limits supportedLimits {}; FILAMENT_CHECK_POSTCONDITION(details.adapter.GetLimits(&supportedLimits)) - << "Failed to get limits for WebGPU adapter: " << details; + << "Failed to get limits for WebGPU adapter: " << toString(details); if (!satisfiesLimits(supportedLimits)) { #if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) - FWGPU_LOGI << " (for WebGPU adapter " << details << ")"; + FWGPU_LOGI << " (for WebGPU adapter " << toString(details) << ")"; #endif return false; } @@ -487,14 +464,15 @@ struct AdapterDetailsHash final { status != wgpu::RequestAdapterStatus::CallbackCancelled) << "Failed to request a WebGPU adapter due to the request callback " "being cancelled? Options: " - << options << " " << message.data; + << adapterOptionsToString(options) << " " << message.data; FILAMENT_CHECK_POSTCONDITION(status != wgpu::RequestAdapterStatus::Error) << "Failed to request a WebGPU adapter due to an error. Options: " - << options << " Error: " << message.data; + << adapterOptionsToString(options) << " Error: " << message.data; if (status == wgpu::RequestAdapterStatus::Success) { AdapterDetails details = AdapterDetails(readyAdapter); FILAMENT_CHECK_POSTCONDITION(readyAdapter.GetInfo(&details.info)) - << "Failed to get info for adapter (options: " << options << ")"; + << "Failed to get info for adapter (options: " + << adapterOptionsToString(options) << ")"; const std::lock_guard lock(adaptersMutex); compatibleAdapters.emplace(std::move(details.info), details.powerPreference, std::move(details.adapter)); @@ -509,9 +487,11 @@ struct AdapterDetailsHash final { wgpu::Future& future = futures[i]; wgpu::WaitStatus status = instance.WaitAny(future, REQUEST_ADAPTER_TIMEOUT_NANOSECONDS); FILAMENT_CHECK_POSTCONDITION(status != wgpu::WaitStatus::TimedOut) - << "Timed out requesting a WebGPU adapter with options " << options; + << "Timed out requesting a WebGPU adapter with options " + << adapterOptionsToString(options); FILAMENT_CHECK_POSTCONDITION(status != wgpu::WaitStatus::Error) - << "Failed to request a WebGPU adapter with options " << options + << "Failed to request a WebGPU adapter with options " + << adapterOptionsToString(options) << " due to an error (as request was made synchronous)"; assert_invariant(status == wgpu::WaitStatus::Success); } @@ -519,7 +499,7 @@ struct AdapterDetailsHash final { #if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM) FWGPU_LOGI << compatibleAdapters.size() << " WebGPU adapter(s) found:"; for (auto& details: compatibleAdapters) { - FWGPU_LOGI << " WebGPU adapter: " << details; + FWGPU_LOGI << " WebGPU adapter: " << toString(details); } #endif return compatibleAdapters; @@ -586,7 +566,7 @@ void printDeviceDetails(wgpu::Device const& device) { std::for_each(supportedFeatures.features, supportedFeatures.features + supportedFeatures.featureCount, [](wgpu::FeatureName const featureName) { - FWGPU_LOGI << " " << featureName; + FWGPU_LOGI << " " << webGPUPrintableToString(featureName); }); } wgpu::Limits supportedLimits{};