Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/d3d11/d3d11_private.h | 22 -------- dlls/d3d11/inputlayout.c | 28 +++++----- dlls/d3d11/shader.c | 104 ------------------------------------- dlls/d3d11/utils.c | 83 ----------------------------- dlls/wined3d/shader_sm4.c | 23 ++++++++ dlls/wined3d/wined3d.spec | 2 + include/wine/wined3d.h | 3 ++ 7 files changed, 42 insertions(+), 223 deletions(-)
diff --git a/dlls/d3d11/d3d11_private.h b/dlls/d3d11/d3d11_private.h index 580f520aae9c..44e774b8b4df 100644 --- a/dlls/d3d11/d3d11_private.h +++ b/dlls/d3d11/d3d11_private.h @@ -102,22 +102,6 @@ static inline UINT d3d11_bind_flags_from_wined3d(unsigned int bind_flags) return bind_flags; }
-static inline void read_dword(const char **ptr, DWORD *d) -{ - memcpy(d, *ptr, sizeof(*d)); - *ptr += sizeof(*d); -} - -static inline BOOL require_space(size_t offset, size_t count, size_t size, size_t data_size) -{ - return !count || (data_size - offset) / count >= size; -} - -void skip_dword_unknown(const char **ptr, unsigned int count) DECLSPEC_HIDDEN; - -HRESULT parse_dxbc(const char *data, SIZE_T data_size, - HRESULT (*chunk_handler)(const char *data, DWORD data_size, DWORD tag, void *ctx), void *ctx) DECLSPEC_HIDDEN; - /* ID3D11Texture1D, ID3D10Texture1D */ struct d3d_texture1d { @@ -391,12 +375,6 @@ HRESULT d3d11_compute_shader_create(struct d3d_device *device, const void *byte_ struct d3d11_compute_shader **shader) DECLSPEC_HIDDEN; struct d3d11_compute_shader *unsafe_impl_from_ID3D11ComputeShader(ID3D11ComputeShader *iface) DECLSPEC_HIDDEN;
-HRESULT shader_parse_signature(DWORD tag, const char *data, DWORD data_size, - struct wined3d_shader_signature *s) DECLSPEC_HIDDEN; -struct wined3d_shader_signature_element *shader_find_signature_element(const struct wined3d_shader_signature *s, - const char *semantic_name, unsigned int semantic_idx, unsigned int stream_idx) DECLSPEC_HIDDEN; -void shader_free_signature(struct wined3d_shader_signature *s) DECLSPEC_HIDDEN; - /* ID3D11ClassLinkage */ struct d3d11_class_linkage { diff --git a/dlls/d3d11/inputlayout.c b/dlls/d3d11/inputlayout.c index a650ca77f5eb..127ea2994797 100644 --- a/dlls/d3d11/inputlayout.c +++ b/dlls/d3d11/inputlayout.c @@ -24,19 +24,20 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
-static HRESULT isgn_handler(const char *data, DWORD data_size, DWORD tag, void *ctx) +static struct wined3d_shader_signature_element *shader_find_signature_element(const struct wined3d_shader_signature *s, + const char *semantic_name, unsigned int semantic_idx, unsigned int stream_idx) { - struct wined3d_shader_signature *is = ctx; - - if (tag != TAG_ISGN) - return S_OK; + struct wined3d_shader_signature_element *e = s->elements; + unsigned int i;
- if (is->elements) + for (i = 0; i < s->element_count; ++i) { - FIXME("Multiple input signatures.\n"); - shader_free_signature(is); + if (!strcasecmp(e[i].semantic_name, semantic_name) && e[i].semantic_idx == semantic_idx + && e[i].stream_idx == stream_idx) + return &e[i]; } - return shader_parse_signature(tag, data, data_size, is); + + return NULL; }
static HRESULT d3d11_input_layout_to_wined3d_declaration(const D3D11_INPUT_ELEMENT_DESC *element_descs, @@ -47,17 +48,16 @@ static HRESULT d3d11_input_layout_to_wined3d_declaration(const D3D11_INPUT_ELEME unsigned int i; HRESULT hr;
- memset(&is, 0, sizeof(is)); - if (FAILED(hr = parse_dxbc(shader_byte_code, shader_byte_code_length, isgn_handler, &is))) + if (FAILED(hr = wined3d_extract_shader_input_signature_from_dxbc(&is, shader_byte_code, shader_byte_code_length))) { - ERR("Failed to parse input signature.\n"); + ERR("Failed to extract input signature.\n"); return E_FAIL; }
if (!(*wined3d_elements = heap_calloc(element_count, sizeof(**wined3d_elements)))) { ERR("Failed to allocate wined3d vertex element array memory.\n"); - shader_free_signature(&is); + heap_free(is.elements); return E_OUTOFMEMORY; }
@@ -83,7 +83,7 @@ static HRESULT d3d11_input_layout_to_wined3d_declaration(const D3D11_INPUT_ELEME WARN("Unused input element %u.\n", i); }
- shader_free_signature(&is); + heap_free(is.elements);
return S_OK; } diff --git a/dlls/d3d11/shader.c b/dlls/d3d11/shader.c index 259ac331dbfe..9a4f1a87b1a5 100644 --- a/dlls/d3d11/shader.c +++ b/dlls/d3d11/shader.c @@ -24,110 +24,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
-static const char *shader_get_string(const char *data, size_t data_size, DWORD offset) -{ - size_t len, max_len; - - if (offset >= data_size) - { - WARN("Invalid offset %#x (data size %#lx).\n", offset, (long)data_size); - return NULL; - } - - max_len = data_size - offset; - len = strnlen(data + offset, max_len); - - if (len == max_len) - return NULL; - - return data + offset; -} - -HRESULT shader_parse_signature(DWORD tag, const char *data, DWORD data_size, - struct wined3d_shader_signature *s) -{ - struct wined3d_shader_signature_element *e; - const char *ptr = data; - unsigned int i; - DWORD count; - - if (!require_space(0, 2, sizeof(DWORD), data_size)) - { - WARN("Invalid data size %#x.\n", data_size); - return E_INVALIDARG; - } - - read_dword(&ptr, &count); - TRACE("%u elements.\n", count); - - skip_dword_unknown(&ptr, 1); /* It seems to always be 0x00000008. */ - - if (!require_space(ptr - data, count, 6 * sizeof(DWORD), data_size)) - { - WARN("Invalid count %#x (data size %#x).\n", count, data_size); - return E_INVALIDARG; - } - - if (!(e = heap_calloc(count, sizeof(*e)))) - { - ERR("Failed to allocate input signature memory.\n"); - return E_OUTOFMEMORY; - } - - for (i = 0; i < count; ++i) - { - DWORD name_offset; - - if (tag == TAG_OSG5) - read_dword(&ptr, &e[i].stream_idx); - else - e[i].stream_idx = 0; - read_dword(&ptr, &name_offset); - if (!(e[i].semantic_name = shader_get_string(data, data_size, name_offset))) - { - WARN("Invalid name offset %#x (data size %#x).\n", name_offset, data_size); - heap_free(e); - return E_INVALIDARG; - } - read_dword(&ptr, &e[i].semantic_idx); - read_dword(&ptr, &e[i].sysval_semantic); - read_dword(&ptr, &e[i].component_type); - read_dword(&ptr, &e[i].register_idx); - read_dword(&ptr, &e[i].mask); - - TRACE("Stream: %u, semantic: %s, semantic idx: %u, sysval_semantic %#x, " - "type %u, register idx: %u, use_mask %#x, input_mask %#x.\n", - e[i].stream_idx, debugstr_a(e[i].semantic_name), e[i].semantic_idx, e[i].sysval_semantic, - e[i].component_type, e[i].register_idx, (e[i].mask >> 8) & 0xff, e[i].mask & 0xff); - } - - s->elements = e; - s->element_count = count; - - return S_OK; -} - -struct wined3d_shader_signature_element *shader_find_signature_element(const struct wined3d_shader_signature *s, - const char *semantic_name, unsigned int semantic_idx, unsigned int stream_idx) -{ - struct wined3d_shader_signature_element *e = s->elements; - unsigned int i; - - for (i = 0; i < s->element_count; ++i) - { - if (!strcasecmp(e[i].semantic_name, semantic_name) && e[i].semantic_idx == semantic_idx - && e[i].stream_idx == stream_idx) - return &e[i]; - } - - return NULL; -} - -void shader_free_signature(struct wined3d_shader_signature *s) -{ - heap_free(s->elements); -} - /* ID3D11VertexShader methods */
static inline struct d3d_vertex_shader *impl_from_ID3D11VertexShader(ID3D11VertexShader *iface) diff --git a/dlls/d3d11/utils.c b/dlls/d3d11/utils.c index cf40cc47effb..0555603eefa4 100644 --- a/dlls/d3d11/utils.c +++ b/dlls/d3d11/utils.c @@ -871,86 +871,3 @@ HRESULT d3d_set_private_data_interface(struct wined3d_private_store *store,
return hr; } - -void skip_dword_unknown(const char **ptr, unsigned int count) -{ - unsigned int i; - DWORD d; - - WARN("Skipping %u unknown DWORDs:\n", count); - for (i = 0; i < count; ++i) - { - read_dword(ptr, &d); - WARN("\t0x%08x\n", d); - } -} - -HRESULT parse_dxbc(const char *data, SIZE_T data_size, - HRESULT (*chunk_handler)(const char *data, DWORD data_size, DWORD tag, void *ctx), void *ctx) -{ - const char *ptr = data; - HRESULT hr = S_OK; - DWORD chunk_count; - DWORD total_size; - unsigned int i; - DWORD version; - DWORD tag; - - read_dword(&ptr, &tag); - TRACE("tag: %s.\n", debugstr_an((const char *)&tag, 4)); - - if (tag != TAG_DXBC) - { - WARN("Wrong tag.\n"); - return E_INVALIDARG; - } - - WARN("Ignoring DXBC checksum.\n"); - skip_dword_unknown(&ptr, 4); - - read_dword(&ptr, &version); - TRACE("version: %#x.\n", version); - if (version != 0x00000001) - { - WARN("Got unexpected DXBC version %#x.\n", version); - return E_INVALIDARG; - } - - read_dword(&ptr, &total_size); - TRACE("total size: %#x\n", total_size); - - read_dword(&ptr, &chunk_count); - TRACE("chunk count: %#x\n", chunk_count); - - for (i = 0; i < chunk_count; ++i) - { - DWORD chunk_tag, chunk_size; - const char *chunk_ptr; - DWORD chunk_offset; - - read_dword(&ptr, &chunk_offset); - TRACE("chunk %u at offset %#x\n", i, chunk_offset); - - if (chunk_offset >= data_size || !require_space(chunk_offset, 2, sizeof(DWORD), data_size)) - { - WARN("Invalid chunk offset %#x (data size %#lx).\n", chunk_offset, data_size); - return E_FAIL; - } - - chunk_ptr = data + chunk_offset; - - read_dword(&chunk_ptr, &chunk_tag); - read_dword(&chunk_ptr, &chunk_size); - - if (!require_space(chunk_ptr - data, 1, chunk_size, data_size)) - { - WARN("Invalid chunk size %#x (data size %#lx, chunk offset %#x).\n", chunk_size, data_size, chunk_offset); - return E_FAIL; - } - - hr = chunk_handler(chunk_ptr, chunk_size, chunk_tag, ctx); - if (FAILED(hr)) break; - } - - return hr; -} diff --git a/dlls/wined3d/shader_sm4.c b/dlls/wined3d/shader_sm4.c index 5f9dbecfebaa..db3297e8e993 100644 --- a/dlls/wined3d/shader_sm4.c +++ b/dlls/wined3d/shader_sm4.c @@ -2103,3 +2103,26 @@ HRESULT shader_extract_from_dxbc(struct wined3d_shader *shader,
return hr; } + +static HRESULT shader_isgn_chunk_handler(const char *data, DWORD data_size, DWORD tag, void *ctx) +{ + struct wined3d_shader_signature *is = ctx; + + if (tag != TAG_ISGN) + return S_OK; + + if (is->elements) + { + FIXME("Multiple shader signatures.\n"); + return S_OK; + } + + return shader_parse_signature(tag, data, data_size, is); +} + +HRESULT CDECL wined3d_extract_shader_input_signature_from_dxbc(struct wined3d_shader_signature *signature, + const void *code, SIZE_T code_size) +{ + memset(signature, 0, sizeof(*signature)); + return parse_dxbc(code, code_size, shader_isgn_chunk_handler, signature); +} diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec index b1d3a521de7b..75b9fe12c600 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -315,3 +315,5 @@ @ cdecl wined3d_vertex_declaration_decref(ptr) @ cdecl wined3d_vertex_declaration_get_parent(ptr) @ cdecl wined3d_vertex_declaration_incref(ptr) + +@ cdecl wined3d_extract_shader_input_signature_from_dxbc(ptr ptr long) diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index a58dd87ee7d0..07329024fefb 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2750,6 +2750,9 @@ ULONG __cdecl wined3d_vertex_declaration_decref(struct wined3d_vertex_declaratio void * __cdecl wined3d_vertex_declaration_get_parent(const struct wined3d_vertex_declaration *declaration); ULONG __cdecl wined3d_vertex_declaration_incref(struct wined3d_vertex_declaration *declaration);
+HRESULT __cdecl wined3d_extract_shader_input_signature_from_dxbc(struct wined3d_shader_signature *signature, + const void *byte_code, SIZE_T byte_code_size); + /* Return the integer base-2 logarithm of x. Undefined for x == 0. */ static inline unsigned int wined3d_log2i(unsigned int x) {
Hi,
While running your changed tests on Windows, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=47446
Your paranoid android.
=== debian9 (32 bit report) ===
d3d11: Unhandled exception: page fault on execute access to 0x00000000 in 32-bit code (0x00000000).
=== debian9 (32 bit Chinese:China report) ===
d3d11: d3d11.c:5593: Test failed: Got unexpected hr 0x8876086a.
=== debian9 (32 bit WoW report) ===
d3d11: Unhandled exception: page fault on execute access to 0x00000000 in 32-bit code (0x00000000).
=== debian9 (64 bit WoW report) ===
d3d11: Unhandled exception: page fault on execute access to 0x100000001 in 64-bit code (0x0000000100000001).
Report errors: d3d11:d3d11 crashed (c0000005)