vkd3d-shader: Add vkd3d_dxbc_binary_to_text() helper function.

Signed-off-by: Isabella Bosia <ibosia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Isabella Bosia 2020-09-25 02:26:36 +01:00 committed by Alexandre Julliard
parent 0808058ede
commit a0d469b20e
2 changed files with 32 additions and 6 deletions

View File

@ -1557,17 +1557,18 @@ static void shader_dump_instruction(struct vkd3d_string_buffer *buffer,
shader_addline(buffer, "\n"); 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_shader_version shader_version;
struct vkd3d_string_buffer buffer;
const char *p, *q;
const DWORD *ptr; const DWORD *ptr;
struct vkd3d_string_buffer buffer;
enum vkd3d_result result = VKD3D_OK;
void *code;
if (!vkd3d_string_buffer_init(&buffer)) if (!vkd3d_string_buffer_init(&buffer))
{ {
ERR("Failed to initialize string buffer.\n"); ERR("Failed to initialize string buffer.\n");
return; return VKD3D_ERROR;
} }
shader_sm4_read_header(data, &ptr, &shader_version); shader_sm4_read_header(data, &ptr, &shader_version);
@ -1583,13 +1584,37 @@ void vkd3d_shader_trace(void *data)
{ {
WARN("Skipping unrecognized instruction.\n"); WARN("Skipping unrecognized instruction.\n");
shader_addline(&buffer, "<unrecognized instruction>\n"); shader_addline(&buffer, "<unrecognized instruction>\n");
result = VKD3D_ERROR;
continue; continue;
} }
shader_dump_instruction(&buffer, &ins, &shader_version); 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"))) if (!(q = strstr(p, "\n")))
q = p + strlen(p); q = p + strlen(p);
@ -1598,5 +1623,5 @@ void vkd3d_shader_trace(void *data)
TRACE(" %.*s", (int)(q - p), p); TRACE(" %.*s", (int)(q - p), p);
} }
vkd3d_string_buffer_cleanup(&buffer); vkd3d_shader_free_shader_code(&code);
} }

View File

@ -830,6 +830,7 @@ struct vkd3d_string_buffer
unsigned int content_size; 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; void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer) DECLSPEC_HIDDEN;
bool vkd3d_string_buffer_init(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; int vkd3d_string_buffer_vprintf(struct vkd3d_string_buffer *buffer, const char *format, va_list args) DECLSPEC_HIDDEN;