mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/spirv: Break long assembly lines.
Avoid overflowing the (Wine) debug log buffer when output lines are too long, and keep spirv-text output more legible. The output is still valid SPIR-V asm, as the assembler does not care for which kind of whitespace is used.
This commit is contained in:
parent
a39227c79c
commit
3d8fc1a467
Notes:
Henri Verbeet
2024-09-03 17:18:22 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1019
@ -97,15 +97,37 @@ static enum vkd3d_result vkd3d_spirv_binary_to_text(const struct vkd3d_shader_co
|
|||||||
if (!(spvret = spvBinaryToText(context, spirv->code, spirv->size / sizeof(uint32_t),
|
if (!(spvret = spvBinaryToText(context, spirv->code, spirv->size / sizeof(uint32_t),
|
||||||
get_binary_to_text_options(formatting), &text, &diagnostic)))
|
get_binary_to_text_options(formatting), &text, &diagnostic)))
|
||||||
{
|
{
|
||||||
void *code = vkd3d_malloc(text->length);
|
const char *p, *q, *end, *pad, *truncate;
|
||||||
if (code)
|
struct vkd3d_string_buffer buffer;
|
||||||
|
size_t line_len;
|
||||||
|
|
||||||
|
vkd3d_string_buffer_init(&buffer);
|
||||||
|
|
||||||
|
for (p = text->str, end = p + text->length; p < end; p = q)
|
||||||
{
|
{
|
||||||
memcpy(code, text->str, text->length);
|
if (!(q = memchr(p, '\n', end - p)))
|
||||||
out->size = text->length;
|
q = end;
|
||||||
out->code = code;
|
else
|
||||||
|
++q;
|
||||||
|
|
||||||
|
/* FIXME: Note that when colour output is enabled, we count colour
|
||||||
|
* escape codes towards the line length. It's possible to fix
|
||||||
|
* that, but not completely trivial. */
|
||||||
|
for (pad = "", line_len = 100; q - p > line_len; line_len = 100 - strlen(pad))
|
||||||
|
{
|
||||||
|
if (!(truncate = memchr(p + line_len, ' ', q - p - line_len)))
|
||||||
|
break;
|
||||||
|
vkd3d_string_buffer_printf(&buffer, "%s%.*s\n", pad, (int)(truncate - p), p);
|
||||||
|
p = truncate + 1;
|
||||||
|
if (formatting & VKD3D_SHADER_COMPILE_OPTION_FORMATTING_INDENT)
|
||||||
|
pad = " ";
|
||||||
|
else
|
||||||
|
pad = " ";
|
||||||
|
}
|
||||||
|
vkd3d_string_buffer_printf(&buffer, "%s%.*s", pad, (int)(q - p), p);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
result = VKD3D_ERROR_OUT_OF_MEMORY;
|
vkd3d_shader_code_from_string_buffer(out, &buffer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user