d3dcompiler: Use vkd3d_shader_serialize_dxbc() in d3dcompiler_strip_shader().

Note that this adds a todo_wine to test_get_blob_part2(). It looks
like native d3dcompiler only adds padding between sections, while
vkd3d-shader always adds padding to the end of sections. I've sent a
vkd3d-shader patch to fix that, but the extra padding at the end of
the DXBC blob doesn't seem terribly concerning.
This commit is contained in:
Henri Verbeet 2023-04-04 10:52:15 +02:00 committed by Alexandre Julliard
parent 0c7313840c
commit 8455b47b86
4 changed files with 25 additions and 101 deletions

View file

@ -348,9 +348,12 @@ static BOOL check_blob_strip(DWORD tag, UINT flags)
static HRESULT d3dcompiler_strip_shader(const void *data, SIZE_T data_size, UINT flags, ID3DBlob **blob)
{
struct dxbc src_dxbc, dst_dxbc;
struct vkd3d_shader_dxbc_section_desc *sections;
struct vkd3d_shader_code dst_dxbc;
unsigned int section_count, i;
struct dxbc src_dxbc;
HRESULT hr;
unsigned int i;
int ret;
if (!blob)
{
@ -372,39 +375,37 @@ static HRESULT d3dcompiler_strip_shader(const void *data, SIZE_T data_size, UINT
}
/* src_dxbc.count >= dst_dxbc.count */
hr = dxbc_init(&dst_dxbc, src_dxbc.count);
if (FAILED(hr))
if (!(sections = calloc(src_dxbc.count, sizeof(*sections))))
{
ERR("Failed to allocate sections memory.\n");
dxbc_destroy(&src_dxbc);
WARN("Failed to init dxbc\n");
return hr;
return E_OUTOFMEMORY;
}
for (i = 0; i < src_dxbc.count; ++i)
for (i = 0, section_count = 0; i < src_dxbc.count; ++i)
{
const struct vkd3d_shader_dxbc_section_desc *section = &src_dxbc.sections[i];
const struct vkd3d_shader_dxbc_section_desc *src_section = &src_dxbc.sections[i];
if (check_blob_strip(section->tag, flags))
{
hr = dxbc_add_section(&dst_dxbc, section->tag, section->data.code, section->data.size);
if (FAILED(hr))
{
dxbc_destroy(&src_dxbc);
dxbc_destroy(&dst_dxbc);
WARN("Failed to add section to dxbc\n");
return hr;
}
}
if (check_blob_strip(src_section->tag, flags))
sections[section_count++] = *src_section;
}
hr = dxbc_write_blob(&dst_dxbc, blob);
if (FAILED(hr))
if ((ret = vkd3d_shader_serialize_dxbc(section_count, sections, &dst_dxbc, NULL) < 0))
{
WARN("Failed to write blob part\n");
WARN("Failed to serialise DXBC, ret %d.\n", ret);
hr = E_FAIL;
goto done;
}
if (FAILED(hr = D3DCreateBlob(dst_dxbc.size, blob)))
WARN("Failed to create blob, hr %#lx.\n", hr);
else
memcpy(ID3D10Blob_GetBufferPointer(*blob), dst_dxbc.code, dst_dxbc.size);
vkd3d_shader_free_shader_code(&dst_dxbc);
done:
free(sections);
dxbc_destroy(&src_dxbc);
dxbc_destroy(&dst_dxbc);
return hr;
}

View file

@ -560,16 +560,9 @@ struct dxbc
struct vkd3d_shader_dxbc_section_desc *sections;
};
HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob) DECLSPEC_HIDDEN;
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;
static inline void write_u32(char **ptr, uint32_t u32)
{
memcpy(*ptr, &u32, sizeof(u32));
*ptr += sizeof(u32);
}
#endif /* __WINE_D3DCOMPILER_PRIVATE_H */

View file

@ -764,7 +764,7 @@ static void test_get_blob_part2(void)
ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
size = ID3D10Blob_GetBufferSize(blob);
ok(size == 4735, "Got unexpected size %Iu.\n", size);
todo_wine ok(size == 4735, "Got unexpected size %Iu.\n", size);
dword = ((DWORD*)ID3D10Blob_GetBufferPointer(blob));
ok(TAG_DXBC == *dword, "DXBC got %#lx, expected %#lx.\n", *dword, TAG_DXBC);

View file

@ -526,12 +526,6 @@ void skip_u32_unknown(const char **ptr, unsigned int count)
}
}
static void write_u32_unknown(char **ptr, uint32_t u32)
{
FIXME("Writing unknown u32 0x%08x.\n", u32);
write_u32(ptr, u32);
}
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);
@ -658,70 +652,6 @@ void dxbc_destroy(struct dxbc *dxbc)
HeapFree(GetProcessHeap(), 0, dxbc->sections);
}
HRESULT dxbc_write_blob(struct dxbc *dxbc, ID3DBlob **blob)
{
DWORD size = 32, offset = size + 4 * dxbc->count;
ID3DBlob *object;
HRESULT hr;
char *ptr;
unsigned int i;
TRACE("dxbc %p, blob %p.\n", dxbc, blob);
for (i = 0; i < dxbc->count; ++i)
{
size += 12 + dxbc->sections[i].data.size;
}
hr = D3DCreateBlob(size, &object);
if (FAILED(hr))
{
WARN("Failed to create blob\n");
return hr;
}
ptr = ID3D10Blob_GetBufferPointer(object);
write_u32(&ptr, TAG_DXBC);
/* signature(?) */
write_u32_unknown(&ptr, 0);
write_u32_unknown(&ptr, 0);
write_u32_unknown(&ptr, 0);
write_u32_unknown(&ptr, 0);
/* seems to be always 1 */
write_u32_unknown(&ptr, 1);
/* DXBC size */
write_u32(&ptr, size);
/* chunk count */
write_u32(&ptr, dxbc->count);
/* write the chunk offsets */
for (i = 0; i < dxbc->count; ++i)
{
write_u32(&ptr, offset);
offset += 8 + dxbc->sections[i].data.size;
}
/* write the chunks */
for (i = 0; i < dxbc->count; ++i)
{
write_u32(&ptr, dxbc->sections[i].tag);
write_u32(&ptr, dxbc->sections[i].data.size);
memcpy(ptr, dxbc->sections[i].data.code, dxbc->sections[i].data.size);
ptr += dxbc->sections[i].data.size;
}
TRACE("Created ID3DBlob %p\n", object);
*blob = object;
return S_OK;
}
void compilation_message(struct compilation_messages *msg, const char *fmt, va_list args)
{
char* buffer;