Signed-off-by: Isabella Bosia ibosia@codeweavers.com --- V2: - shader_dump_to_buffer renamed to vkd3d_dxbc_binary_to_text - Now it returns a vkd3d_result and takes a vkd3d_shader_code * out parameter
libs/vkd3d-shader/trace.c | 37 ++++++++++++++++++++---- libs/vkd3d-shader/vkd3d_shader_private.h | 1 + 2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/libs/vkd3d-shader/trace.c b/libs/vkd3d-shader/trace.c index f0797b0..e01e162 100644 --- a/libs/vkd3d-shader/trace.c +++ b/libs/vkd3d-shader/trace.c @@ -1558,17 +1558,18 @@ static void shader_dump_instruction(struct vkd3d_string_buffer *buffer, shader_addline(buffer, "\n"); }
-void vkd3d_shader_trace(void *data) +enum vkd3d_result vkd3d_dxbc_binary_to_text(void *data, struct vkd3d_shader_code *out) { struct vkd3d_shader_version shader_version; - struct vkd3d_string_buffer buffer; - const char *p, *q; const DWORD *ptr; + struct vkd3d_string_buffer buffer; + enum vkd3d_result result = VKD3D_OK; + void *code;
if (!vkd3d_string_buffer_init(&buffer)) { ERR("Failed to initialize string buffer.\n"); - return; + return VKD3D_ERROR; }
shader_sm4_read_header(data, &ptr, &shader_version); @@ -1584,13 +1585,37 @@ void vkd3d_shader_trace(void *data) { WARN("Skipping unrecognized instruction.\n"); shader_addline(&buffer, "<unrecognized instruction>\n"); + result = VKD3D_ERROR; continue; }
shader_dump_instruction(&buffer, &ins, &shader_version); }
- for (p = buffer.buffer; *p; p = q) + code = vkd3d_malloc(buffer.content_size); + if (code) + { + memcpy(code, buffer.buffer, buffer.content_size); + out->size = buffer.content_size; + out->code = code; + } + else + result = VKD3D_ERROR_OUT_OF_MEMORY; + + vkd3d_string_buffer_cleanup(&buffer); + + return result; +} + +void vkd3d_shader_trace(void *data) +{ + const char *p, *q; + struct vkd3d_shader_code code; + + if (vkd3d_dxbc_binary_to_text(data, &code) != VKD3D_OK) + return; + + for (p = code.code; *p; p = q) { if (!(q = strstr(p, "\n"))) q = p + strlen(p); @@ -1599,5 +1624,5 @@ void vkd3d_shader_trace(void *data) TRACE(" %.*s", (int)(q - p), p); }
- vkd3d_string_buffer_cleanup(&buffer); + vkd3d_shader_free_shader_code(&code); } diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index 00b2441..ec0014e 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -830,6 +830,7 @@ struct vkd3d_string_buffer unsigned int content_size; };
+enum vkd3d_result vkd3d_dxbc_binary_to_text(void *data, struct vkd3d_shader_code *out) DECLSPEC_HIDDEN; void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer) DECLSPEC_HIDDEN; bool vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer) DECLSPEC_HIDDEN; int vkd3d_string_buffer_vprintf(struct vkd3d_string_buffer *buffer, const char *format, va_list args) DECLSPEC_HIDDEN;
On Fri, 25 Sep 2020 at 15:00, Henri Verbeet hverbeet@codeweavers.com wrote:
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Although ideally with the commit message updated to refer to vkd3d_dxbc_binary_to_text().