Commit 55ab59af authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

d3dcompiler: Use vkd3d_shader_parse_dxbc() in d3dcompiler_shader_reflection_init().

parent 372dc31e
......@@ -553,16 +553,4 @@ void SlDeleteShader(struct bwriter_shader *shader) DECLSPEC_HIDDEN;
#define TAG_XNAP MAKE_TAG('X', 'N', 'A', 'P')
#define TAG_XNAS MAKE_TAG('X', 'N', 'A', 'S')
struct dxbc
{
UINT size;
UINT count;
struct vkd3d_shader_dxbc_section_desc *sections;
};
void dxbc_destroy(struct dxbc *dxbc) DECLSPEC_HIDDEN;
HRESULT dxbc_parse(const char *data, SIZE_T data_size, struct dxbc *dxbc) DECLSPEC_HIDDEN;
HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, size_t data_size) DECLSPEC_HIDDEN;
HRESULT dxbc_init(struct dxbc *dxbc, unsigned int size) DECLSPEC_HIDDEN;
#endif /* __WINE_D3DCOMPILER_PRIVATE_H */
......@@ -1862,22 +1862,23 @@ static HRESULT d3dcompiler_parse_shdr(struct d3dcompiler_shader_reflection *r, c
static HRESULT d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_reflection *reflection,
const void *data, SIZE_T data_size)
{
struct dxbc src_dxbc;
HRESULT hr;
const struct vkd3d_shader_code src_dxbc = {.code = data, .size = data_size};
struct vkd3d_shader_dxbc_desc src_dxbc_desc;
HRESULT hr = S_OK;
unsigned int i;
int ret;
wine_rb_init(&reflection->types, d3dcompiler_shader_reflection_type_compare);
hr = dxbc_parse(data, data_size, &src_dxbc);
if (FAILED(hr))
if ((ret = vkd3d_shader_parse_dxbc(&src_dxbc, 0, &src_dxbc_desc, NULL)) < 0)
{
WARN("Failed to parse reflection\n");
return hr;
WARN("Failed to parse reflection, ret %d.\n", ret);
return E_FAIL;
}
for (i = 0; i < src_dxbc.count; ++i)
for (i = 0; i < src_dxbc_desc.section_count; ++i)
{
const struct vkd3d_shader_dxbc_section_desc *section = &src_dxbc.sections[i];
const struct vkd3d_shader_dxbc_section_desc *section = &src_dxbc_desc.sections[i];
switch (section->tag)
{
......@@ -1967,13 +1968,13 @@ static HRESULT d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_refl
}
}
dxbc_destroy(&src_dxbc);
vkd3d_shader_free_dxbc(&src_dxbc_desc);
return hr;
err_out:
reflection_cleanup(reflection);
dxbc_destroy(&src_dxbc);
vkd3d_shader_free_dxbc(&src_dxbc_desc);
return hr;
}
......
......@@ -526,132 +526,6 @@ void skip_u32_unknown(const char **ptr, unsigned int count)
}
}
HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, size_t data_size)
{
TRACE("dxbc %p, tag %s, size %#Ix.\n", dxbc, debugstr_an((const char *)&tag, 4), data_size);
if (dxbc->count >= dxbc->size)
{
struct vkd3d_shader_dxbc_section_desc *new_sections;
DWORD new_size = dxbc->size << 1;
new_sections = HeapReAlloc(GetProcessHeap(), 0, dxbc->sections, new_size * sizeof(*dxbc->sections));
if (!new_sections)
{
ERR("Failed to allocate dxbc section memory\n");
return E_OUTOFMEMORY;
}
dxbc->sections = new_sections;
dxbc->size = new_size;
}
dxbc->sections[dxbc->count].tag = tag;
dxbc->sections[dxbc->count].data.size = data_size;
dxbc->sections[dxbc->count].data.code = data;
++dxbc->count;
return S_OK;
}
HRESULT dxbc_init(struct dxbc *dxbc, unsigned int size)
{
TRACE("dxbc %p, size %u.\n", dxbc, size);
/* use a good starting value for the size if none specified */
if (!size) size = 2;
dxbc->sections = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*dxbc->sections));
if (!dxbc->sections)
{
ERR("Failed to allocate dxbc section memory\n");
return E_OUTOFMEMORY;
}
dxbc->size = size;
dxbc->count = 0;
return S_OK;
}
HRESULT dxbc_parse(const char *data, SIZE_T data_size, struct dxbc *dxbc)
{
uint32_t tag, total_size, chunk_count;
const char *ptr = data;
unsigned int i;
HRESULT hr;
if (!data)
{
WARN("No data supplied.\n");
return E_FAIL;
}
tag = read_u32(&ptr);
TRACE("tag: %s.\n", debugstr_an((const char *)&tag, 4));
if (tag != TAG_DXBC)
{
WARN("Wrong tag.\n");
return E_FAIL;
}
/* checksum? */
skip_u32_unknown(&ptr, 4);
skip_u32_unknown(&ptr, 1);
total_size = read_u32(&ptr);
TRACE("total size: %#x\n", total_size);
if (data_size != total_size)
{
WARN("Wrong size supplied.\n");
return D3DERR_INVALIDCALL;
}
chunk_count = read_u32(&ptr);
TRACE("chunk count: %#x\n", chunk_count);
hr = dxbc_init(dxbc, chunk_count);
if (FAILED(hr))
{
WARN("Failed to init dxbc\n");
return hr;
}
for (i = 0; i < chunk_count; ++i)
{
uint32_t chunk_tag, chunk_size;
const char *chunk_ptr;
uint32_t chunk_offset;
chunk_offset = read_u32(&ptr);
TRACE("chunk %u at offset %#x\n", i, chunk_offset);
chunk_ptr = data + chunk_offset;
chunk_tag = read_u32(&chunk_ptr);
chunk_size = read_u32(&chunk_ptr);
hr = dxbc_add_section(dxbc, chunk_tag, chunk_ptr, chunk_size);
if (FAILED(hr))
{
WARN("Failed to add section to dxbc\n");
return hr;
}
}
return hr;
}
void dxbc_destroy(struct dxbc *dxbc)
{
TRACE("dxbc %p.\n", dxbc);
HeapFree(GetProcessHeap(), 0, dxbc->sections);
}
void compilation_message(struct compilation_messages *msg, const char *fmt, va_list args)
{
char* buffer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment