diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c index f6ecf9e2..57e360f0 100644 --- a/libs/vkd3d-shader/trace.c +++ b/libs/vkd3d-shader/trace.c @@ -749,12 +749,17 @@ static void shader_dump_src_param(struct vkd3d_d3d_asm_compiler *compiler, static void shader_print_float_literal(struct vkd3d_d3d_asm_compiler *compiler, const char *prefix, float f, const char *suffix) { + const char *sign = ""; + if (isfinite(f) && signbit(f)) - vkd3d_string_buffer_printf(&compiler->buffer, "%s-%s%.8e%s%s", - prefix, compiler->colours.literal, -f, compiler->colours.reset, suffix); - else - vkd3d_string_buffer_printf(&compiler->buffer, "%s%s%.8e%s%s", - prefix, compiler->colours.literal, f, compiler->colours.reset, suffix); + { + sign = "-"; + f = -f; + } + + vkd3d_string_buffer_printf(&compiler->buffer, "%s%s%s", prefix, sign, compiler->colours.literal); + vkd3d_string_buffer_print_f32(&compiler->buffer, f); + vkd3d_string_buffer_printf(&compiler->buffer, "%s%s", compiler->colours.reset, suffix); } static void shader_print_double_literal(struct vkd3d_d3d_asm_compiler *compiler, diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index b5b66e1f..c5ab9a6a 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -20,6 +20,7 @@ #include "vkd3d_version.h" #include +#include VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG"); @@ -91,6 +92,21 @@ int vkd3d_string_buffer_printf(struct vkd3d_string_buffer *buffer, const char *f return ret; } +int vkd3d_string_buffer_print_f32(struct vkd3d_string_buffer *buffer, float f) +{ + unsigned int idx = buffer->content_size + 1; + int ret; + + if (!(ret = vkd3d_string_buffer_printf(buffer, "%.8e", f)) && isfinite(f)) + { + if (signbit(f)) + ++idx; + buffer->buffer[idx] = '.'; + } + + return ret; +} + void vkd3d_string_buffer_trace_(const struct vkd3d_string_buffer *buffer, const char *function) { vkd3d_shader_trace_text_(buffer->buffer, buffer->content_size, function); diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 60c86155..f0228c15 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -993,6 +993,7 @@ struct vkd3d_string_buffer *vkd3d_string_buffer_get(struct vkd3d_string_buffer_c void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer); void vkd3d_string_buffer_cache_cleanup(struct vkd3d_string_buffer_cache *list); void vkd3d_string_buffer_cache_init(struct vkd3d_string_buffer_cache *list); +int vkd3d_string_buffer_print_f32(struct vkd3d_string_buffer *buffer, float f); int vkd3d_string_buffer_printf(struct vkd3d_string_buffer *buffer, const char *format, ...) VKD3D_PRINTF_FUNC(2, 3); void vkd3d_string_buffer_release(struct vkd3d_string_buffer_cache *list, struct vkd3d_string_buffer *buffer); #define vkd3d_string_buffer_trace(buffer) \