From 50f26d4c6c75e11ae1cc44aad6c795681de76124 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 16 Jun 2018 11:57:12 -0700 Subject: Reworked vulkan dynamic heap implementation --- Primitives/interface/FormatMessage.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'Primitives/interface') diff --git a/Primitives/interface/FormatMessage.h b/Primitives/interface/FormatMessage.h index 12748474..d0df1472 100644 --- a/Primitives/interface/FormatMessage.h +++ b/Primitives/interface/FormatMessage.h @@ -24,6 +24,7 @@ #pragma once #include +#include namespace Diligent { @@ -41,4 +42,34 @@ namespace Diligent FormatMsg( ss, FirstArg ); FormatMsg( ss, RestArgs... ); // recursive call using pack expansion syntax } + + + struct SizeFormatter + { + size_t size = 0; + size_t precision = 0; + size_t ref_size = 0; + }; + + template + void FormatMsg(SSType &ss, const SizeFormatter& Arg) + { + auto ref_size = Arg.ref_size != 0 ? Arg.ref_size : Arg.size; + if (ref_size >= (1 << 30)) + { + ss << std::fixed << std::setprecision(Arg.precision) << Arg.size / double{ 1 << 30 } << " GB"; + } + else if(ref_size >= (1 << 20)) + { + ss << std::fixed << std::setprecision(Arg.precision) << Arg.size / double{ 1 << 20 } << " MB"; + } + else if (ref_size >= (1 << 10)) + { + ss << std::fixed << std::setprecision(Arg.precision) << Arg.size / double{ 1 << 10 } << " KB"; + } + else + { + ss << Arg.size << (Arg.size > 1 ? " Byte" : " Bytes" ); + } + } } \ No newline at end of file -- cgit v1.2.3