Skip to content

Commit 77d77f0

Browse files
committed
webgpu: fix logging
1 parent 0aabd3d commit 77d77f0

File tree

5 files changed

+89
-219
lines changed

5 files changed

+89
-219
lines changed

filament/backend/src/webgpu/WebGPUStrings.h

Lines changed: 14 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,50 +21,27 @@
2121

2222
#include <backend/DriverEnums.h>
2323

24-
#include <utils/Panic.h>
25-
#include <utils/ostream.h>
26-
27-
#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
2824
#include <dawn/webgpu_cpp_print.h>
29-
#endif
3025
#include <webgpu/webgpu_cpp.h>
3126

3227
#include <cstdint>
33-
#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
3428
#include <sstream>
35-
#endif
29+
#include <string>
3630
#include <string_view>
3731

3832
/**
3933
* Reusable set of convenience functions for strings -- generally string views, literals, &
40-
* streaming -- used in the WebGPU backend
34+
* strings -- used in the WebGPU backend
4135
*/
4236

4337
namespace filament::backend {
4438

4539
#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
46-
/**
47-
* Convenience template to print WGPU types (which don't support Filament's utils::io::ostream)
48-
* @tparam WebGPUPrintable e.g. wgpu::FeatureName type
49-
* @param out stream to print to
50-
* @param printable the instance to print
51-
* @return the stream printed to
52-
*
53-
* Example usage (because including the template operator override itself does not compile):
54-
* #if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
55-
* utils::io::ostream& operator<<(utils::io::ostream& out,
56-
* const wgpu::FeatureName featureName) noexcept {
57-
* return streamInsertWebGPUPrintable(out, featureName);
58-
* }
59-
* #endif
60-
*/
6140
template<typename WebGPUPrintable>
62-
utils::io::ostream& streamInsertWebGPUPrintable(utils::io::ostream& out,
63-
const WebGPUPrintable printable) {
64-
std::stringstream printableStream;
65-
printableStream << printable;
66-
out << printableStream.str();
67-
return out;
41+
[[nodiscard]] inline std::string webGPUPrintableToString(const WebGPUPrintable printable) {
42+
std::stringstream out;
43+
out << printable;
44+
return out.str();
6845
}
6946
#endif
7047

@@ -115,54 +92,25 @@ utils::io::ostream& streamInsertWebGPUPrintable(utils::io::ostream& out,
11592
}
11693
}
11794

118-
/**
119-
* Convenience template to print wgpu::RequestAdapterOptions
120-
* @tparam STREAM_TYPE useful namely for streaming to either an utils::io::ostream OR
121-
* utils::details::PanicStream, but also for any kind of stream
122-
* @param out stream to print to
123-
* @param options instance to be printed
124-
* @return stream printed to
125-
*
126-
* Example usage (because including the template operator override itself does not compile):
127-
* template<typename STREAM_TYPE>
128-
* STREAM_TYPE& operator<<(STREAM_TYPE& out, wgpu::RequestAdapterOptions const& options) noexcept {
129-
* return streamInsertRequestAdapterOptions(out, options);
130-
* }
131-
*/
132-
template<typename STREAM_TYPE>
133-
STREAM_TYPE& streamInsertRequestAdapterOptions(STREAM_TYPE& out,
134-
wgpu::RequestAdapterOptions const& options) noexcept {
95+
[[nodiscard]] inline std::string adapterOptionsToString(
96+
wgpu::RequestAdapterOptions const& options) {
97+
std::stringstream out;
13598
out << "power preference " << powerPreferenceToString(options.powerPreference)
13699
<< " force fallback adapter " << bool(options.forceFallbackAdapter) << " backend type "
137100
<< backendTypeToString(options.backendType);
138-
return out;
101+
return out.str();
139102
}
140103

141-
/**
142-
* Convenience template to print wgpu::AdapterInfo
143-
* @tparam STREAM_TYPE useful namely for streaming to either an utils::io::ostream OR
144-
* utils::details::PanicStream, but also for any kind of stream
145-
* @param out stream to print to
146-
* @param options instance to be printed
147-
* @return stream printed to
148-
*
149-
* Example usage (because including the template operator override itself does not compile):
150-
* template<typename STREAM_TYPE>
151-
* STREAM_TYPE& operator<<(STREAM_TYPE& out, wgpu::AdapterInfo const& info) noexcept {
152-
* return streamInsertRequestAdapterInfo(out, info);
153-
* }
154-
*/
155-
template<class STREAM_TYPE>
156-
STREAM_TYPE& streamInsertRequestAdapterInfo(STREAM_TYPE& out,
157-
wgpu::AdapterInfo const& info) noexcept {
104+
[[nodiscard]] std::string adapterInfoToString(wgpu::AdapterInfo const& info) {
105+
std::stringstream out;
158106
out << "vendor (" << info.vendorID << ") '" << info.vendor
159107
<< "' device (" << info.deviceID << ") '" << info.device
160108
<< "' adapter " << adapterTypeToString(info.adapterType)
161109
<< " backend " << backendTypeToString(info.backendType)
162110
<< " architecture '" << info.architecture
163111
<< "' subgroupMinSize " << info.subgroupMinSize
164112
<< " subgroupMaxSize " << info.subgroupMaxSize;
165-
return out;
113+
return out.str();
166114
}
167115

168116
[[nodiscard]] constexpr std::string_view deviceLostReasonToString(
@@ -175,7 +123,7 @@ STREAM_TYPE& streamInsertRequestAdapterInfo(STREAM_TYPE& out,
175123
}
176124
}
177125

178-
[[nodiscard]] constexpr std::string_view filamentShaderStageToString(ShaderStage stage) {
126+
[[nodiscard]] constexpr std::string_view filamentShaderStageToString(const ShaderStage stage) {
179127
switch (stage) {
180128
case ShaderStage::VERTEX: return "vertex";
181129
case ShaderStage::FRAGMENT: return "fragment";

filament/backend/src/webgpu/WebGPUSwapChain.cpp

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,80 +24,62 @@
2424
#include "backend/DriverEnums.h"
2525

2626
#include <utils/Panic.h>
27-
#include <utils/ostream.h>
2827

2928
#include <webgpu/webgpu_cpp.h>
3029

3130
#include <algorithm>
3231
#include <cstdint>
3332

33+
namespace filament::backend {
34+
3435
namespace {
3536

3637
#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
37-
utils::io::ostream& operator<<(utils::io::ostream& out, const wgpu::TextureFormat format) noexcept {
38-
return filament::backend::streamInsertWebGPUPrintable(out, format);
39-
}
40-
41-
utils::io::ostream& operator<<(utils::io::ostream& out,
42-
const wgpu::TextureUsage textureUsage) noexcept {
43-
return filament::backend::streamInsertWebGPUPrintable(out, textureUsage);
44-
}
45-
46-
utils::io::ostream& operator<<(utils::io::ostream& out,
47-
const wgpu::PresentMode presentMode) noexcept {
48-
return filament::backend::streamInsertWebGPUPrintable(out, presentMode);
49-
}
50-
51-
utils::io::ostream& operator<<(utils::io::ostream& out,
52-
const wgpu::CompositeAlphaMode alphaMode) noexcept {
53-
return filament::backend::streamInsertWebGPUPrintable(out, alphaMode);
54-
}
55-
5638
void printSurfaceCapabilitiesDetails(wgpu::SurfaceCapabilities const& capabilities) {
5739
FWGPU_LOGI << "WebGPU surface capabilities:";
58-
FWGPU_LOGI << " surface usages: " << capabilities.usages;
40+
FWGPU_LOGI << " surface usages: " << webGPUPrintableToString(capabilities.usages);
5941
FWGPU_LOGI << " surface formats (" << capabilities.formatCount << "):";
6042
if (capabilities.formatCount > 0 && capabilities.formats != nullptr) {
6143
std::for_each(capabilities.formats, capabilities.formats + capabilities.formatCount,
6244
[](wgpu::TextureFormat const format) {
63-
FWGPU_LOGI << " " << format;
45+
FWGPU_LOGI << " " << webGPUPrintableToString(format);
6446
});
6547
}
6648
FWGPU_LOGI << " surface present modes (" << capabilities.presentModeCount << "):";
6749
if (capabilities.presentModeCount > 0 && capabilities.presentModes != nullptr) {
6850
std::for_each(capabilities.presentModes,
6951
capabilities.presentModes + capabilities.presentModeCount,
7052
[](wgpu::PresentMode const presentMode) {
71-
FWGPU_LOGI << " " << presentMode;
53+
FWGPU_LOGI << " " << webGPUPrintableToString(presentMode);
7254
});
7355
}
7456
FWGPU_LOGI << " surface alpha modes (" << capabilities.alphaModeCount << "):";
7557
if (capabilities.alphaModeCount > 0 && capabilities.alphaModes != nullptr) {
7658
std::for_each(capabilities.alphaModes,
7759
capabilities.alphaModes + capabilities.alphaModeCount,
7860
[](wgpu::CompositeAlphaMode const alphaMode) {
79-
FWGPU_LOGI << " " << alphaMode;
61+
FWGPU_LOGI << " " << webGPUPrintableToString(alphaMode);
8062
});
8163
}
8264
}
8365

8466
void printSurfaceConfiguration(wgpu::SurfaceConfiguration const& config,
8567
wgpu::TextureFormat depthFormat) {
8668
FWGPU_LOGI << "WebGPU surface configuration:";
87-
FWGPU_LOGI << " surface format: " << config.format;
88-
FWGPU_LOGI << " surface usage: " << config.usage;
69+
FWGPU_LOGI << " surface format: " << webGPUPrintableToString(config.format);
70+
FWGPU_LOGI << " surface usage: " << webGPUPrintableToString(config.usage);
8971
FWGPU_LOGI << " surface view formats (" << config.viewFormatCount << "):";
9072
if (config.viewFormatCount > 0 && config.viewFormats != nullptr) {
9173
std::for_each(config.viewFormats, config.viewFormats + config.viewFormatCount,
9274
[](wgpu::TextureFormat const viewFormat) {
93-
FWGPU_LOGI << " " << viewFormat;
75+
FWGPU_LOGI << " " << webGPUPrintableToString(viewFormat);
9476
});
9577
}
96-
FWGPU_LOGI << " surface alpha mode: " << config.alphaMode;
78+
FWGPU_LOGI << " surface alpha mode: " << webGPUPrintableToString(config.alphaMode);
9779
FWGPU_LOGI << " surface width: " << config.width;
9880
FWGPU_LOGI << " surface height: " << config.height;
99-
FWGPU_LOGI << " surface present mode: " << config.presentMode;
100-
FWGPU_LOGI << "WebGPU selected depth format: " << depthFormat;
81+
FWGPU_LOGI << " surface present mode: " << webGPUPrintableToString(config.presentMode);
82+
FWGPU_LOGI << "WebGPU selected depth format: " << webGPUPrintableToString(depthFormat);
10183
}
10284
#endif// FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
10385

@@ -257,8 +239,6 @@ void initConfig(wgpu::SurfaceConfiguration& config, wgpu::Device const& device,
257239

258240
}// namespace
259241

260-
namespace filament::backend {
261-
262242
WebGPUSwapChain::WebGPUSwapChain(wgpu::Surface&& surface, wgpu::Extent2D const& surfaceSize,
263243
wgpu::Adapter const& adapter, wgpu::Device const& device, uint64_t flags)
264244
: mDevice(device),

filament/backend/src/webgpu/WebGPUTexture.cpp

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <utils/BitmaskEnum.h>
2626
#include <utils/Panic.h>
2727
#include <utils/debug.h>
28-
#include <utils/ostream.h>
2928

3029
#include <webgpu/webgpu_cpp.h>
3130
#if FWGPU_ENABLED(FWGPU_PRINT_SYSTEM)
@@ -343,8 +342,7 @@ WebGPUTexture::WebGPUTexture(const SamplerType samplerType, const uint8_t levels
343342
std::stringstream textureFormatStream;
344343
textureFormatStream << mWebGPUFormat;
345344
FWGPU_LOGD << "Texture '" << textureDescriptor.label << "' has view format "
346-
<< viewFormatStream.str() << " and texture format " << textureFormatStream.str()
347-
<< utils::io::endl;
345+
<< viewFormatStream.str() << " and texture format " << textureFormatStream.str();
348346
}
349347
#endif
350348
}
@@ -470,90 +468,76 @@ wgpu::TextureFormat WebGPUTexture::fToWGPUTextureFormat(TextureFormat const& fFo
470468
// No direct mapping in wgpu. Could potentially map to RGBA8Unorm
471469
// and discard the alpha and lower precision.
472470
FWGPU_LOGW << "Requested Filament texture format RGB565 but getting "
473-
"wgpu::TextureFormat::Undefined (no direct mapping in wgpu)"
474-
<< utils::io::endl;
471+
"wgpu::TextureFormat::Undefined (no direct mapping in wgpu)";
475472
return wgpu::TextureFormat::Undefined;
476473
case TextureFormat::RGB9_E5: return wgpu::TextureFormat::RGB9E5Ufloat;
477474
case TextureFormat::RGB5_A1:
478475
// No direct mapping in wgpu. Could potentially map to RGBA8Unorm
479476
// and handle the packing/unpacking in shaders.
480477
FWGPU_LOGW << "Requested Filament texture format RGB5_A1 but getting "
481-
"wgpu::TextureFormat::Undefined (no direct mapping in wgpu)"
482-
<< utils::io::endl;
478+
"wgpu::TextureFormat::Undefined (no direct mapping in wgpu)";
483479
return wgpu::TextureFormat::Undefined;
484480
case TextureFormat::RGBA4:
485481
// No direct mapping in wgpu. Could potentially map to RGBA8Unorm
486482
// and handle the packing/unpacking in shaders.
487483
FWGPU_LOGW << "Requested Filament texture format RGBA4 but getting "
488-
"wgpu::TextureFormat::Undefined (no direct mapping in wgpu)"
489-
<< utils::io::endl;
484+
"wgpu::TextureFormat::Undefined (no direct mapping in wgpu)";
490485
return wgpu::TextureFormat::Undefined;
491486
case TextureFormat::RGB8:
492487
FWGPU_LOGW << "Requested Filament texture format RGB8 but getting "
493488
"wgpu::TextureFormat::RGBA8Unorm (no direct sRGB equivalent in wgpu "
494-
"without alpha)"
495-
<< utils::io::endl;
489+
"without alpha)";
496490
return wgpu::TextureFormat::RGBA8Unorm;
497491
case TextureFormat::SRGB8:
498492
FWGPU_LOGW << "Requested Filament texture format SRGB8 but getting "
499493
"wgpu::TextureFormat::RGBA8UnormSrgb (no direct sRGB equivalent in wgpu "
500-
"without alpha)"
501-
<< utils::io::endl;
494+
"without alpha)";
502495
return wgpu::TextureFormat::RGBA8UnormSrgb;
503496
case TextureFormat::RGB8_SNORM:
504497
FWGPU_LOGW
505498
<< "Requested Filament texture format RGB8_SNORM but getting "
506-
"wgpu::TextureFormat::RGBA8Snorm (no direct mapping in wgpu without alpha)"
507-
<< utils::io::endl;
499+
"wgpu::TextureFormat::RGBA8Snorm (no direct mapping in wgpu without alpha)";
508500
return wgpu::TextureFormat::RGBA8Snorm;
509501
case TextureFormat::RGB8UI:
510502
FWGPU_LOGW << "Requested Filament texture format RGB8UI but getting "
511-
"wgpu::TextureFormat::RGBA8Uint (no direct mapping in wgpu without alpha)"
512-
<< utils::io::endl;
503+
"wgpu::TextureFormat::RGBA8Uint (no direct mapping in wgpu without alpha)";
513504
return wgpu::TextureFormat::RGBA8Uint;
514505
case TextureFormat::RGB8I:
515506
FWGPU_LOGW << "Requested Filament texture format RGB8I but getting "
516-
"wgpu::TextureFormat::RGBA8Sint (no direct mapping in wgpu without alpha)"
517-
<< utils::io::endl;
507+
"wgpu::TextureFormat::RGBA8Sint (no direct mapping in wgpu without alpha)";
518508
return wgpu::TextureFormat::RGBA8Sint;
519509
case TextureFormat::R11F_G11F_B10F: return wgpu::TextureFormat::RG11B10Ufloat;
520510
case TextureFormat::UNUSED: return wgpu::TextureFormat::Undefined;
521511
case TextureFormat::RGB10_A2: return wgpu::TextureFormat::RGB10A2Unorm;
522512
case TextureFormat::RGB16F:
523513
FWGPU_LOGW
524514
<< "Requested Filament texture format RGB16F but getting "
525-
"wgpu::TextureFormat::RGBA16Float (no direct mapping in wgpu without alpha)"
526-
<< utils::io::endl;
515+
"wgpu::TextureFormat::RGBA16Float (no direct mapping in wgpu without alpha)";
527516
return wgpu::TextureFormat::RGBA16Float;
528517
case TextureFormat::RGB16UI:
529518
FWGPU_LOGW
530519
<< "Requested Filament texture format RGB16UI but getting "
531-
"wgpu::TextureFormat::RGBA16Uint (no direct mapping in wgpu without alpha)"
532-
<< utils::io::endl;
520+
"wgpu::TextureFormat::RGBA16Uint (no direct mapping in wgpu without alpha)";
533521
return wgpu::TextureFormat::RGBA16Uint;
534522
case TextureFormat::RGB16I:
535523
FWGPU_LOGW
536524
<< "Requested Filament texture format RGB16I but getting "
537-
"wgpu::TextureFormat::RGBA16Sint (no direct mapping in wgpu without alpha)"
538-
<< utils::io::endl;
525+
"wgpu::TextureFormat::RGBA16Sint (no direct mapping in wgpu without alpha)";
539526
return wgpu::TextureFormat::RGBA16Sint;
540527
case TextureFormat::RGB32F:
541528
FWGPU_LOGW
542529
<< "Requested Filament texture format RGB32F but getting "
543-
"wgpu::TextureFormat::RGBA32Float (no direct mapping in wgpu without alpha)"
544-
<< utils::io::endl;
530+
"wgpu::TextureFormat::RGBA32Float (no direct mapping in wgpu without alpha)";
545531
return wgpu::TextureFormat::RGBA32Float;
546532
case TextureFormat::RGB32UI:
547533
FWGPU_LOGW
548534
<< "Requested Filament texture format RGB32UI but getting "
549-
"wgpu::TextureFormat::RGBA32Uint (no direct mapping in wgpu without alpha)"
550-
<< utils::io::endl;
535+
"wgpu::TextureFormat::RGBA32Uint (no direct mapping in wgpu without alpha)";
551536
return wgpu::TextureFormat::RGBA32Uint;
552537
case TextureFormat::RGB32I:
553538
FWGPU_LOGW
554539
<< "Requested Filament texture format RGB32I but getting "
555-
"wgpu::TextureFormat::RGBA32Sint (no direct mapping in wgpu without alpha)"
556-
<< utils::io::endl;
540+
"wgpu::TextureFormat::RGBA32Sint (no direct mapping in wgpu without alpha)";
557541
return wgpu::TextureFormat::RGBA32Sint;
558542
case TextureFormat::DXT1_RGB: return wgpu::TextureFormat::BC1RGBAUnorm;
559543
case TextureFormat::DXT1_RGBA: return wgpu::TextureFormat::BC1RGBAUnorm;
@@ -573,7 +557,7 @@ wgpu::TextureView WebGPUTexture::makeTextureView(const uint8_t& baseLevel,
573557
if (baseLevel > 0 && !mSupportsMultipleMipLevels) {
574558
FWGPU_LOGW << "Trying to make a texture view into a level ("
575559
<< static_cast<uint32_t>(baseLevel)
576-
<< ") for which we cannot generate mip levels." << utils::io::endl;
560+
<< ") for which we cannot generate mip levels.";
577561
}
578562
#endif
579563
const wgpu::TextureViewDescriptor textureViewDescriptor{

0 commit comments

Comments
 (0)