Skip to content

Commit 36da5fe

Browse files
committed
SSPDLOG
1 parent 492d1c8 commit 36da5fe

27 files changed

+141
-124
lines changed

deps/spdlog

Submodule spdlog updated 175 files

include/shards/utility.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,15 +848,15 @@ template <class SH_CORE> struct TVarOrReference {
848848

849849
TVarOrReference(SHContext *context, const SHVar &v) : ptr(&v) {
850850
if (v.valueType == SHType::ContextVar) {
851-
if (auto var = SH_CORE::findVariable(context, SHSTRVIEW(v))) {
851+
if (auto var = SH_CORE::findVariable(context, toSWL(SHSTRVIEW(v)))) {
852852
ptr = var;
853853
owned = var;
854854
}
855855
}
856856
}
857857

858858
TVarOrReference(SHContext *context, const char *varName) : ptr(nullptr) {
859-
if (auto var = SH_CORE::findVariable(context, varName)) {
859+
if (auto var = SH_CORE::findVariable(context, toSWL(varName))) {
860860
ptr = var;
861861
owned = var;
862862
} else {
@@ -906,4 +906,9 @@ template <typename T> struct hash<shards::TOwnedVar<T>> {
906906
};
907907
} // namespace std
908908

909+
template<typename SH_CORE>
910+
auto format_as(const shards::TOwnedVar<SH_CORE>& ov) {
911+
return (SHVar&)ov;
912+
}
913+
909914
#endif

shards/core/foundation.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,13 +1314,13 @@ struct InternalCore {
13141314
}
13151315

13161316
static SHVar *referenceVariable(SHContext *context, SHStringWithLen name) {
1317-
return shards::referenceVariable(context, std::string_view(name.string, name.len));
1317+
return shards::referenceVariable(context, toStringView(name));
13181318
}
13191319

13201320
static void stringGrow(SHStringPayload *str, uint32_t size) { shards::stringGrow(str, size); }
13211321
static void stringFree(SHStringPayload *str) { shards::stringFree(str); }
13221322

1323-
static SHVar *findVariable(SHContext *context, SHStringWithLen name) { return shards::findVariable(context, name); }
1323+
static SHVar *findVariable(SHContext *context, SHStringWithLen name) { return shards::findVariable(context, toStringView(name)); }
13241324

13251325
static void releaseVariable(SHVar *variable) { shards::releaseVariable(variable); }
13261326

@@ -1756,4 +1756,16 @@ inline void swlFree(SHStringWithLen &in) {
17561756

17571757
}; // namespace shards
17581758

1759+
inline auto format_as(SHWire::State state) {
1760+
return magic_enum::enum_name(state);
1761+
}
1762+
1763+
inline auto format_as(const shards::SeqVar& v) {
1764+
return (SHVar&)v;
1765+
}
1766+
1767+
inline auto format_as(const shards::TableVar& v) {
1768+
return (SHVar&)v;
1769+
}
1770+
17591771
#endif // SH_CORE_FOUNDATION

shards/core/ops_internal.hpp

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <shards/shards.hpp>
99
#include "spdlog/fmt/bundled/core.h"
1010
#include <shards/ops.hpp>
11+
#include <shards/utility.hpp>
1112
#include <sstream>
1213
#include <spdlog/fmt/fmt.h>
1314
#include <spdlog/fmt/ostr.h> // must be included
@@ -85,87 +86,75 @@ inline std::ostream &operator<<(std::ostream &os, const SHTypeInfo &v) { return
8586
inline std::ostream &operator<<(std::ostream &os, const SHTypesInfo &v) { return shards::defaultFormatter.format(os, v); }
8687
inline std::ostream &operator<<(std::ostream &os, const SHTrait &v) { return shards::defaultFormatter.format(os, v); }
8788

88-
template <typename T> struct StringStreamFormatter {
89-
constexpr auto parse(fmt::format_parse_context &ctx) -> decltype(ctx.begin()) {
90-
auto it = ctx.begin(), end = ctx.end();
91-
if (it != end)
92-
throw fmt::format_error("invalid format");
93-
return it;
94-
}
95-
96-
template <typename FormatContext> auto format(const T &v, FormatContext &ctx) -> decltype(ctx.out()) {
89+
template <typename T> struct StringStreamFormatter {
90+
template <typename FormatContext> auto format(const T &v, FormatContext &ctx) const -> decltype(ctx.out()) {
9791
std::stringstream ss;
9892
ss << v;
9993
return fmt::format_to(ctx.out(), "{}", ss.str());
10094
}
10195
};
10296

103-
template <> struct fmt::formatter<SHStringWithLen> {
97+
template <> struct fmt::formatter<SHStringWithLen> : fmt::formatter<std::string_view> {
10498
StringStreamFormatter<SHStringWithLen> base;
105-
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) { return base.parse(ctx); }
106-
template <typename FormatContext> auto format(const SHStringWithLen &v, FormatContext &ctx) -> decltype(ctx.out()) {
99+
template <typename FormatContext> auto format(const SHStringWithLen &v, FormatContext &ctx) const -> decltype(ctx.out()) {
107100
return base.format(v, ctx);
108101
}
109102
};
110103

111-
template <> struct fmt::formatter<SHTrait> {
104+
template <> struct fmt::formatter<SHTrait> : fmt::formatter<std::string_view> {
112105
StringStreamFormatter<SHTrait> base;
113-
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) { return base.parse(ctx); }
114-
template <typename FormatContext> auto format(const SHTrait &v, FormatContext &ctx) -> decltype(ctx.out()) {
106+
template <typename FormatContext> auto format(const SHTrait &v, FormatContext &ctx) const -> decltype(ctx.out()) {
115107
return base.format(v, ctx);
116108
}
117109
};
118110

119-
template <> struct fmt::formatter<SHVar> {
111+
template <> struct fmt::formatter<SHVar> : fmt::formatter<std::string_view> {
120112
StringStreamFormatter<SHVar> base;
121-
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) { return base.parse(ctx); }
122-
template <typename FormatContext> auto format(const SHVar &v, FormatContext &ctx) -> decltype(ctx.out()) {
113+
template <typename FormatContext> auto format(const SHVar &v, FormatContext &ctx) const -> decltype(ctx.out()) {
123114
return base.format(v, ctx);
124115
}
125116
};
126117

127-
template <> struct fmt::formatter<SHTypeInfo> {
118+
template <> struct fmt::formatter<SHTypeInfo> : fmt::formatter<std::string_view> {
128119
StringStreamFormatter<SHTypeInfo> base;
129-
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) { return base.parse(ctx); }
130-
template <typename FormatContext> auto format(const SHTypeInfo &v, FormatContext &ctx) -> decltype(ctx.out()) {
120+
template <typename FormatContext> auto format(const SHTypeInfo &v, FormatContext &ctx) const -> decltype(ctx.out()) {
131121
return base.format(v, ctx);
132122
}
133123
};
134124

135-
template <> struct fmt::formatter<SHTypesInfo> {
125+
template <> struct fmt::formatter<SHTypesInfo> : fmt::formatter<std::string_view> {
136126
StringStreamFormatter<SHTypesInfo> base;
137-
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) { return base.parse(ctx); }
138-
template <typename FormatContext> auto format(const SHTypesInfo &v, FormatContext &ctx) -> decltype(ctx.out()) {
127+
template <typename FormatContext> auto format(const SHTypesInfo &v, FormatContext &ctx) const -> decltype(ctx.out()) {
139128
return base.format(v, ctx);
140129
}
141130
};
142131

143-
template <> struct fmt::formatter<SHType> {
144-
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) {
145-
auto it = ctx.begin(), end = ctx.end();
146-
if (it != end)
147-
throw format_error("invalid format");
148-
return it;
149-
}
150-
template <typename FormatContext> auto format(const SHType &v, FormatContext &ctx) -> decltype(ctx.out()) {
132+
template <> struct fmt::formatter<SHType> : fmt::formatter<std::string_view> {
133+
template <typename FormatContext> auto format(const SHType &v, FormatContext &ctx) const -> decltype(ctx.out()) {
151134
return format_to(ctx.out(), "{}", magic_enum::enum_name(v));
152135
}
153136
};
154137

155-
template <> struct fmt::formatter<shards::Type> {
138+
template <> struct fmt::formatter<shards::Type> : fmt::formatter<std::string_view> {
156139
fmt::formatter<SHTypeInfo> base;
157-
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) { return base.parse(ctx); }
158-
template <typename FormatContext> auto format(const shards::Type &v, FormatContext &ctx) -> decltype(ctx.out()) {
140+
template <typename FormatContext> auto format(const shards::Type &v, FormatContext &ctx) const -> decltype(ctx.out()) {
159141
return base.format(v, ctx);
160142
}
161143
};
162144

163-
template <> struct fmt::formatter<shards::Types> {
145+
template <> struct fmt::formatter<shards::Types> : fmt::formatter<std::string_view> {
164146
fmt::formatter<SHTypesInfo> base;
165-
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) { return base.parse(ctx); }
166-
template <typename FormatContext> auto format(const shards::Types &v, FormatContext &ctx) -> decltype(ctx.out()) {
147+
template <typename FormatContext> auto format(const shards::Types &v, FormatContext &ctx) const -> decltype(ctx.out()) {
167148
return base.format(v, ctx);
168149
}
169150
};
170151

152+
inline auto format_as(SHStringWithLen s) {
153+
return shards::toStringView(s);
154+
}
155+
156+
inline auto format_as(SHWireState state) {
157+
return magic_enum::enum_name(state);
158+
}
159+
171160
#endif // SH_CORE_OPS_INTERNAL

shards/core/pmr/shared_temp_allocator.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ static shards::logging::Logger getLogger() {
1414
#define STA_TRACE(...)
1515
#endif
1616

17+
namespace std {
18+
inline auto format_as(const std::thread::id& id) {
19+
std::stringstream ss;
20+
ss << id;
21+
return (std::string)ss.str();
22+
}
23+
}
24+
1725
namespace shards::pmr {
1826
struct SharedTempAllocatorImpl {
1927
TempAllocator allocator;

shards/core/runtime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ void error_handler(int err_sig) {
16191619

16201620
if (crashed) {
16211621
#ifndef __EMSCRIPTEN__
1622-
SHLOG_ERROR(boost::stacktrace::stacktrace());
1622+
SHLOG_ERROR("{}", boost::stacktrace::to_string(boost::stacktrace::stacktrace()));
16231623
#endif
16241624

16251625
auto handler = GetGlobals().CrashHandler;

shards/core/runtime.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "inline.hpp"
2525
#include "utils.hpp"
2626
#include "platform.hpp"
27+
#include "ops_internal.hpp"
2728

2829
#include <chrono>
2930
#include <iostream>

shards/core/trait.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ SHTrait cloneTrait(const SHTrait &other) {
4242
return result;
4343
}
4444

45-
template <typename S, typename... Args> inline auto formatLineInto(std::string &str, const S &format_str, Args &&...args) {
45+
template <typename... TArgs> inline auto formatLineInto(std::string &str, fmt::format_string<TArgs...> format_str, TArgs &&...args) {
4646
if (!str.empty())
4747
str.push_back('\n');
48-
fmt::format_to(std::back_inserter(str), format_str, std::forward<Args>(args)...);
48+
fmt::format_to(std::back_inserter(str), format_str, std::forward<TArgs>(args)...);
4949
}
5050

5151
bool TraitMatcher::operator()(SHExposedTypesInfo exposedVariables, const SHTrait &trait) {

shards/core/trait.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct TraitMatcher {
2121

2222
struct Trait : public SHTrait {
2323
~Trait() { reset(); }
24-
Trait() { memset(this, 0, sizeof(SHTrait)); }
24+
Trait() { memset((SHTrait*)this, 0, sizeof(SHTrait)); }
2525
Trait(const SHTrait &other) : SHTrait(cloneTrait(other)) {}
2626
Trait(const Trait &other) : SHTrait(cloneTrait(other)) {}
2727
Trait &operator=(const SHTrait &other) {
@@ -102,4 +102,8 @@ struct TraitRegister {
102102

103103
} // namespace shards
104104

105+
inline auto format_as(const shards::Trait &trait) {
106+
return (SHTrait&)trait;
107+
}
108+
105109
#endif /* B7638520_BA4D_4989_BDC2_7F3533FE84B5 */

shards/fast_string/fmt.hpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44
#include "fast_string.hpp"
55
#include <spdlog/fmt/fmt.h>
66

7-
// template<> struct fmt::formatter<shards::fast_string::FastString> {
8-
// constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) {
9-
// auto it = ctx.begin(), end = ctx.end();
10-
// if (it != end)
11-
// throw format_error("invalid format");
12-
// return it;
13-
// }
14-
15-
// template <typename FormatContext>
16-
// auto format(const shards::fast_string::FastString &str, FormatContext &ctx) -> decltype(ctx.out()) {
17-
// return format_to(ctx.out(), "{}", str.str());
18-
// }
19-
// };
7+
template <> struct fmt::formatter<shards::fast_string::FastString> : fmt::formatter<std::string_view> {
8+
template <typename FormatContext>
9+
auto format(const shards::fast_string::FastString &str, FormatContext &ctx) const -> decltype(ctx.out()) {
10+
return format_to(ctx.out(), "{}", str.str());
11+
}
12+
};
2013

2114
#endif /* C15A8B87_4A27_4D56_AD9E_4DA2AACA21FE */

shards/gfx/context.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ struct ContextMainOutput {
240240
}
241241

242242
if (preferredFormat == WGPUTextureFormat_Undefined) {
243-
throw formatException("Failed to reconfigure Surface with format {}", preferredFormat);
243+
throw formatException("Failed to reconfigure Surface with format {}", magic_enum::enum_name(preferredFormat));
244244
}
245245

246246
if (preferredFormat != swapchainFormat) {
@@ -253,7 +253,7 @@ struct ContextMainOutput {
253253
shassert(wgpuSurface);
254254
shassert(swapchainFormat != WGPUTextureFormat_Undefined);
255255

256-
SPDLOG_LOGGER_DEBUG(logger, "Configuring surface width: {}, height: {}, format: {}", newSize.x, newSize.y, swapchainFormat);
256+
SPDLOG_LOGGER_DEBUG(logger, "Configuring surface width: {}, height: {}, format: {}", newSize.x, newSize.y, magic_enum::enum_name(swapchainFormat));
257257
currentSize = newSize;
258258

259259
// Force flush all texture references before resizing
@@ -368,7 +368,7 @@ void Context::init(Window &window, const ContextCreationOptions &inOptions) {
368368

369369
void Context::init(const ContextCreationOptions &inOptions) {
370370
options = inOptions;
371-
if (inOptions.overrideNativeWindowHandle) {
371+
if (inOptions.overrideNativeWindowHandle) {
372372
mainOutput = std::make_shared<ContextMainOutput>(inOptions.overrideNativeWindowHandle, onFlushTextureReferences);
373373
}
374374

@@ -730,10 +730,10 @@ void Context::requestAdapter() {
730730
}
731731
extras.backends = instanceBackends;
732732

733-
if (const char *debug = SDL_getenv("SHARDS_GFX_DEBUG")) {
733+
if (SDL_getenv("SHARDS_GFX_DEBUG")) {
734734
extras.flags |= WGPUInstanceFlag_Debug;
735735
}
736-
if (const char *debug = SDL_getenv("SHARDS_GFX_VALIDATION")) {
736+
if (SDL_getenv("SHARDS_GFX_VALIDATION")) {
737737
extras.flags |= WGPUInstanceFlag_Validation;
738738
}
739739
desc.nextInChain = &extras.chain;
@@ -771,8 +771,8 @@ void Context::requestAdapter() {
771771
adapterType: {}
772772
backendType: {}
773773
}})",
774-
props.vendorID, props.architecture, props.deviceID, props.description, props.adapterType,
775-
props.backendType);
774+
props.vendorID, props.architecture, props.deviceID, props.description,
775+
magic_enum::enum_name(props.adapterType), magic_enum::enum_name(props.backendType));
776776
if (!adapterToUse && (useAnyAdapter || props.adapterType == WGPUAdapterType_DiscreteGPU)) {
777777
adapterToUse = adapter;
778778
backendType = props.backendType;

shards/gfx/enums.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const TextureFormatDesc &getTextureFormatDescription(WGPUTextureFormat pixelForm
8989
auto &textureFormatMap = getTextureFormatMap();
9090
auto it = textureFormatMap.find(pixelFormat);
9191
if (it == textureFormatMap.end()) {
92-
throw formatException("Unsupported texture input format", magic_enum::enum_name(pixelFormat));
92+
throw formatException("Unsupported texture input format: {}", magic_enum::enum_name(pixelFormat));
9393
}
9494
return it->second;
9595
}

shards/gfx/error_utils.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#include <stdexcept>
66

77
namespace gfx {
8-
template <typename... TArgs> std::runtime_error formatException(const char *format, TArgs... args) {
9-
return std::runtime_error(fmt::format(format, args...));
8+
template <typename... TArgs>
9+
std::runtime_error formatException(fmt::format_string<TArgs...> format, TArgs&&... args) {
10+
return std::runtime_error(fmt::format(format, std::forward<TArgs>(args)...));
1011
}
1112
} // namespace gfx
1213

shards/gfx/fmt.hpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@
22
#define F69DB8FE_C060_498E_914A_E5245FB65749
33

44
#include "linalg.hpp"
5+
#include "unique_id.hpp"
6+
#include "gfx_wgpu.hpp"
7+
#include <magic_enum.hpp>
58
#include <spdlog/fmt/fmt.h>
69
#include <sstream>
710

8-
template <class T, int M> struct fmt::formatter<linalg::vec<T, M>> {
9-
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) {
10-
auto it = ctx.begin(), end = ctx.end();
11-
if (it != end)
12-
throw format_error("invalid format");
13-
return it;
14-
}
15-
16-
template <typename FormatContext> auto format(const linalg::vec<T, M> &vec, FormatContext &ctx) -> decltype(ctx.out()) {
11+
template <class T, int M> struct fmt::formatter<linalg::vec<T, M>> : fmt::formatter<std::string_view> {
12+
template <typename FormatContext> auto format(const linalg::vec<T, M> &vec, FormatContext &ctx) const -> decltype(ctx.out()) {
1713
using namespace linalg::ostream_overloads;
1814
std::stringstream ss;
1915
ss << vec;
2016
return format_to(ctx.out(), "{}", ss.str());
2117
}
2218
};
2319

20+
template <> struct fmt::formatter<gfx::UniqueId> : fmt::formatter<std::string_view> {
21+
template <typename FormatContext> auto format(const gfx::UniqueId &id, FormatContext &ctx) const -> decltype(ctx.out()) {
22+
return format_to(ctx.out(), "{}", id.value);
23+
}
24+
};
25+
26+
inline auto format_as(WGPUTextureFormat texture) {
27+
return magic_enum::enum_name(texture);
28+
}
29+
2430
#endif /* F69DB8FE_C060_498E_914A_E5245FB65749 */

0 commit comments

Comments
 (0)