Skip to content

Commit

Permalink
Rename add-on API logging function to match core for consistency in b…
Browse files Browse the repository at this point in the history
…uilt-in add-on code
  • Loading branch information
crosire committed Aug 16, 2024
1 parent e415974 commit 90495eb
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 92 deletions.
76 changes: 38 additions & 38 deletions examples/04-api_trace/api_trace_addon.cpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/09-depth/generic_depth_addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ struct __declspec(uuid("e006e162-33ac-4b9f-b10f-0e15335c7bdb")) generic_depth_de
else
{
depth_stencil_backups.pop_back();
reshade::log_message(reshade::log_level::error, "Failed to create backup depth-stencil texture!");
reshade::log::message(reshade::log::level::error, "Failed to create backup depth-stencil texture!");

return nullptr;
}
Expand Down Expand Up @@ -542,7 +542,7 @@ static bool on_create_resource(device *device, resource_desc &desc, subresource_
if (desc.texture.width <= 512)
return false;
if (desc.texture.format == format::d32_float || desc.texture.format == format::d32_float_s8_uint)
reshade::log_message(reshade::log_level::warning, "Replacing high bit depth depth-stencil format with a lower bit depth format");
reshade::log::message(reshade::log::level::warning, "Replacing high bit depth depth-stencil format with a lower bit depth format");
// Replace texture format with special format that supports normal sampling (see https://aras-p.info/texts/D3D9GPUHacks.html#depth)
desc.texture.format = format::intz;
desc.usage |= resource_usage::shader_resource;
Expand Down Expand Up @@ -623,7 +623,7 @@ static void on_destroy_resource(device *device, resource resource)
{
lock.unlock();

reshade::log_message(reshade::log_level::warning, "A depth-stencil resource was destroyed while still in use.");
reshade::log::message(reshade::log::level::warning, "A depth-stencil resource was destroyed while still in use.");

// This is bad ... the resource may still be in use by an effect on the GPU and destroying it would crash it
// Try to mitigate that somehow by delaying this thread a little to hopefully give the GPU enough time to catch up before the resource memory is deallocated
Expand Down
6 changes: 3 additions & 3 deletions examples/10-texture_overlay/texture_overlay_addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ static void on_init_device(device *device)

if (!device->create_resource(resource_desc(1, 1, 1, 1, format::r8g8b8a8_unorm, 1, memory_heap::gpu_only, resource_usage::shader_resource), &initial_data, resource_usage::shader_resource, &data.green_texture))
{
reshade::log_message(reshade::log_level::error, "Failed to create green texture!");
reshade::log::message(reshade::log::level::error, "Failed to create green texture!");
return;
}
if (!device->create_resource_view(data.green_texture, resource_usage::shader_resource, resource_view_desc(format::r8g8b8a8_unorm), &data.green_texture_srv))
{
reshade::log_message(reshade::log_level::error, "Failed to create green texture view!");
reshade::log::message(reshade::log::level::error, "Failed to create green texture view!");
return;
}
}
Expand Down Expand Up @@ -299,7 +299,7 @@ static bool save_texture_image(command_queue *queue, resource tex, const resourc

if (!device->create_resource(resource_desc(desc.texture.width, desc.texture.height, 1, 1, format_to_default_typed(desc.texture.format), 1, memory_heap::gpu_to_cpu, resource_usage::copy_dest), nullptr, resource_usage::copy_dest, &intermediate))
{
reshade::log_message(reshade::log_level::error, "Failed to create system memory texture for texture dumping!");
reshade::log::message(reshade::log::level::error, "Failed to create system memory texture for texture dumping!");
return false;
}

Expand Down
22 changes: 11 additions & 11 deletions examples/12-video_capture/video_capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool video_capture::init_codec_ctx(const reshade::api::resource_desc &buffer_des

if (codec == nullptr)
{
reshade::log_message(reshade::log_level::error, "Failed to find a H.264 encoder that passes requirements!");
reshade::log::message(reshade::log::level::error, "Failed to find a H.264 encoder that passes requirements!");
return false;
}

Expand Down Expand Up @@ -83,7 +83,7 @@ bool video_capture::init_codec_ctx(const reshade::api::resource_desc &buffer_des
break;
default:
destroy_codec_ctx();
reshade::log_message(reshade::log_level::error, "Unsupported texture format!");
reshade::log::message(reshade::log::level::error, "Unsupported texture format!");
return false;
}

Expand All @@ -93,7 +93,7 @@ bool video_capture::init_codec_ctx(const reshade::api::resource_desc &buffer_des

char errbuf[32 + AV_ERROR_MAX_STRING_SIZE] = "Failed to initialize encoder: ";
av_make_error_string(errbuf + strlen(errbuf), sizeof(errbuf) - strlen(errbuf), err);
reshade::log_message(reshade::log_level::error, errbuf);
reshade::log::message(reshade::log::level::error, errbuf);
return false;
}

Expand All @@ -116,7 +116,7 @@ bool video_capture::init_codec_ctx(const reshade::api::resource_desc &buffer_des

char errbuf[32 + AV_ERROR_MAX_STRING_SIZE] = "Failed to get frame buffer: ";
av_make_error_string(errbuf + strlen(errbuf), sizeof(errbuf) - strlen(errbuf), err);
reshade::log_message(reshade::log_level::error, errbuf);
reshade::log::message(reshade::log::level::error, errbuf);
return false;
}

Expand All @@ -143,7 +143,7 @@ bool video_capture::init_format_ctx(const char *filename)
{
char errbuf[32 + AV_ERROR_MAX_STRING_SIZE] = "Failed to initialize ffmpeg output context: ";
av_make_error_string(errbuf + strlen(errbuf), sizeof(errbuf) - strlen(errbuf), err);
reshade::log_message(reshade::log_level::error, errbuf);
reshade::log::message(reshade::log::level::error, errbuf);
return false;
}

Expand All @@ -152,7 +152,7 @@ bool video_capture::init_format_ctx(const char *filename)
avformat_free_context(output_ctx);
output_ctx = nullptr;

reshade::log_message(reshade::log_level::error, "Failed to open output file!");
reshade::log::message(reshade::log::level::error, "Failed to open output file!");
return false;
}

Expand Down Expand Up @@ -184,7 +184,7 @@ static void encode_frame(AVCodecContext *enc, AVFormatContext *s, AVFrame *frame
{
char errbuf[32 + AV_ERROR_MAX_STRING_SIZE] = "Failed to send frame for encoding: ";
av_make_error_string(errbuf + strlen(errbuf), sizeof(errbuf) - strlen(errbuf), err);
reshade::log_message(reshade::log_level::error, errbuf);
reshade::log::message(reshade::log::level::error, errbuf);
return;
}

Expand All @@ -206,7 +206,7 @@ static void on_init(reshade::api::effect_runtime *runtime)
// Create a fence that is used to communicate status of copies between device and host
if (!runtime->get_device()->create_fence(0, reshade::api::fence_flags::none, &data.copy_finished_fence))
{
reshade::log_message(reshade::log_level::error, "Failed to create copy fence!");
reshade::log::message(reshade::log::level::error, "Failed to create copy fence!");
}
}
static void on_destroy(reshade::api::effect_runtime *runtime)
Expand Down Expand Up @@ -242,7 +242,7 @@ static void on_reshade_finish_effects(reshade::api::effect_runtime *runtime, res
{
if (data.output_ctx != nullptr)
{
reshade::log_message(reshade::log_level::info, "Stopping video recording ...");
reshade::log::message(reshade::log::level::info, "Stopping video recording ...");

queue->wait_idle();

Expand Down Expand Up @@ -276,7 +276,7 @@ static void on_reshade_finish_effects(reshade::api::effect_runtime *runtime, res
{
if (!device->create_resource(desc, nullptr, reshade::api::resource_usage::copy_dest, &data.host_resources[i]))
{
reshade::log_message(reshade::log_level::error, "Failed to create host resource!");
reshade::log::message(reshade::log::level::error, "Failed to create host resource!");

for (size_t k = 0; k < i; ++k)
{
Expand All @@ -290,7 +290,7 @@ static void on_reshade_finish_effects(reshade::api::effect_runtime *runtime, res
}
}

reshade::log_message(reshade::log_level::info, "Starting video recording ...");
reshade::log::message(reshade::log::level::info, "Starting video recording ...");

data.start_time = data.last_time = std::chrono::system_clock::now();
}
Expand Down
4 changes: 2 additions & 2 deletions examples/utils/load_texture_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool load_texture_image(const resource_desc &desc, subresource_data &data, std::
if (desc.texture.width != static_cast<uint32_t>(width) ||
desc.texture.height != static_cast<uint32_t>(height))
{
reshade::log_message(reshade::log_level::error, "Failed to replace texture data because dimensions do not match!");
reshade::log::message(reshade::log::level::error, "Failed to replace texture data because dimensions do not match!");
return false;
}

Expand Down Expand Up @@ -139,7 +139,7 @@ bool load_texture_image(const resource_desc &desc, subresource_data &data, std::
break;
default:
// Unsupported format
reshade::log_message(reshade::log_level::error, "Failed to replace texture data because format is not supported!");
reshade::log::message(reshade::log::level::error, "Failed to replace texture data because format is not supported!");
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/utils/save_texture_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ bool save_texture_image(const resource_desc &desc, const subresource_data &data)
static std::set<uint32_t> hash_set;
if (hash_set.find(hash) != hash_set.end())
{
reshade::log_message(reshade::log_level::error, "Skipped texture that was already dumped.");
reshade::log::message(reshade::log::level::error, "Skipped texture that was already dumped.");
return true;
}
else
Expand Down
71 changes: 38 additions & 33 deletions include/reshade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ namespace reshade { namespace internal
/// <summary>
/// Gets the handle to the ReShade module.
/// </summary>
inline HMODULE get_reshade_module_handle(HMODULE reshade_module = nullptr)
inline HMODULE get_reshade_module_handle(HMODULE initial_handle = nullptr)
{
static HMODULE handle = reshade_module;
static HMODULE handle = initial_handle;
if (handle == nullptr)
{
HMODULE modules[1024]; DWORD num = 0;
Expand All @@ -86,9 +86,9 @@ namespace reshade { namespace internal
/// <summary>
/// Gets the handle to the current add-on module.
/// </summary>
inline HMODULE get_current_module_handle(HMODULE addon_module = nullptr)
inline HMODULE get_current_module_handle(HMODULE initial_handle = nullptr)
{
static HMODULE handle = addon_module;
static HMODULE handle = initial_handle;
return handle;
}
} }
Expand All @@ -97,44 +97,49 @@ namespace reshade { namespace internal

namespace reshade
{
/// <summary>
/// Available log severity levels.
/// </summary>
enum class log_level
#if !defined(RESHADE_API_LIBRARY_EXPORT) || defined(BUILTIN_ADDON)
namespace log
{
/// <summary>
/// | [ERROR] | ...
/// </summary>
error = 1,
/// <summary>
/// | [WARN] | ...
/// Severity levels for logging.
/// </summary>
warning = 2,
/// <summary>
/// | [INFO] | ...
/// </summary>
info = 3,
enum class level
{
/// <summary>
/// | ERROR | ...
/// </summary>
error = 1,
/// <summary>
/// | WARN | ...
/// </summary>
warning = 2,
/// <summary>
/// | INFO | ...
/// </summary>
info = 3,
/// <summary>
/// | DEBUG | ...
/// </summary>
debug = 4,
};

/// <summary>
/// | [DEBUG] | ...
/// Writes a message to ReShade's log.
/// </summary>
debug = 4
};

/// <summary>
/// Writes a message to ReShade's log.
/// </summary>
/// <param name="level">Severity level.</param>
/// <param name="message">A null-terminated message string.</param>
inline void log_message(log_level level, const char *message)
{
/// <param name="level">Severity level.</param>
/// <param name="message">A null-terminated message string.</param>
inline void message(level level, const char *message)
{
#if defined(RESHADE_API_LIBRARY)
ReShadeLogMessage(nullptr, static_cast<int>(level), message);
ReShadeLogMessage(nullptr, static_cast<int>(level), message);
#else
static const auto func = reinterpret_cast<void(*)(HMODULE, int, const char *)>(
GetProcAddress(internal::get_reshade_module_handle(), "ReShadeLogMessage"));
func(internal::get_current_module_handle(), static_cast<int>(level), message);
static const auto func = reinterpret_cast<void(*)(HMODULE, int, const char *)>(
GetProcAddress(internal::get_reshade_module_handle(), "ReShadeLogMessage"));
func(internal::get_current_module_handle(), static_cast<int>(level), message);
#endif
}
}
#endif

/// <summary>
/// Gets the base path ReShade uses to resolve relative paths.
Expand Down
18 changes: 17 additions & 1 deletion source/dll_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,34 @@

namespace reshade::log
{
/// <summary>
/// Severity levels for logging.
/// </summary>
enum class level
{
info = 3,
/// <summary>
/// | ERROR | ...
/// </summary>
error = 1,
/// <summary>
/// | WARN | ...
/// </summary>
warning = 2,
/// <summary>
/// | INFO | ...
/// </summary>
info = 3,
/// <summary>
/// | DEBUG | ...
/// </summary>
debug = 4,
};

/// <summary>
/// Opens a log file for writing.
/// </summary>
/// <param name="path">Path to the log file.</param>
/// <param name="ec">Error code that is set on failure.</param>
bool open_log_file(const std::filesystem::path &path, std::error_code &ec);

/// <summary>
Expand Down

0 comments on commit 90495eb

Please sign in to comment.