d3d11: Implement d3d11_input_layout_to_wined3d_declaration() on top of vkd3d_shader_parse_input_signature().
This was originally prompted by the fact that wined3d_extract_shader_input_signature_from_dxbc() allocates elements with HeapAlloc(), but d3d11_input_layout_to_wined3d_declaration() attempts to free them with free(). That's a regression introduced by commit b951c37b8791ceb052c9e159ad7927f75a72d667. Since we're touching the code though, we may as well use vkd3d_shader_parse_input_signature(), and get rid of wined3d_extract_shader_input_signature_from_dxbc().
From: Henri Verbeet hverbeet@codeweavers.com
This was originally prompted by the fact that wined3d_extract_shader_input_signature_from_dxbc() allocates elements with HeapAlloc(), but d3d11_input_layout_to_wined3d_declaration() attempts to free them with free(). That's a regression introduced by commit b951c37b8791ceb052c9e159ad7927f75a72d667. Since we're touching the code though, we may as well use vkd3d_shader_parse_input_signature(), and get rid of wined3d_extract_shader_input_signature_from_dxbc(). --- dlls/d3d11/Makefile.in | 1 + dlls/d3d11/inputlayout.c | 30 +++++++++++---------- dlls/wined3d/shader_sm4.c | 23 ---------------- dlls/wined3d/wined3d.spec | 2 -- dlls/wined3d/wined3d_private.h | 46 +++++++++++++++++++++++++++++++ include/wine/wined3d.h | 49 ---------------------------------- 6 files changed, 63 insertions(+), 88 deletions(-)
diff --git a/dlls/d3d11/Makefile.in b/dlls/d3d11/Makefile.in index 5a56faec523..5197f9ef9d7 100644 --- a/dlls/d3d11/Makefile.in +++ b/dlls/d3d11/Makefile.in @@ -1,6 +1,7 @@ MODULE = d3d11.dll IMPORTLIB = d3d11 IMPORTS = dxguid uuid dxgi wined3d +EXTRAINCL = $(VKD3D_PE_CFLAGS)
C_SRCS = \ async.c \ diff --git a/dlls/d3d11/inputlayout.c b/dlls/d3d11/inputlayout.c index cfdd0e980ed..9f26ef4032b 100644 --- a/dlls/d3d11/inputlayout.c +++ b/dlls/d3d11/inputlayout.c @@ -19,27 +19,28 @@
#include "d3d11_private.h" #include "winternl.h" +#include <vkd3d_shader.h>
WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
-static BOOL is_vs_sysval_semantic(const struct wined3d_shader_signature_element *e) +static BOOL is_vs_sysval_semantic(const struct vkd3d_shader_signature_element *e) { return !stricmp(e->semantic_name, "sv_instanceid") || !stricmp(e->semantic_name, "sv_vertexid"); }
static unsigned int find_input_element(const D3D11_INPUT_ELEMENT_DESC *element_descs, unsigned int element_count, - struct wined3d_shader_signature_element *ise) + const struct vkd3d_shader_signature_element *ise) { const D3D11_INPUT_ELEMENT_DESC *f; unsigned int i;
- if (ise->stream_idx) + if (ise->stream_index) return element_count;
for (i = 0; i < element_count; ++i) { f = &element_descs[i]; - if (!stricmp(ise->semantic_name, f->SemanticName) && ise->semantic_idx == f->SemanticIndex) + if (!stricmp(ise->semantic_name, f->SemanticName) && ise->semantic_index == f->SemanticIndex) return i; } return element_count; @@ -54,22 +55,23 @@ static HRESULT d3d11_input_layout_to_wined3d_declaration(const D3D11_INPUT_ELEME UINT element_count, const void *shader_byte_code, SIZE_T shader_byte_code_length, struct wined3d_vertex_element **wined3d_elements) { - struct wined3d_shader_signature_element *ise; - struct wined3d_shader_signature is; + const struct vkd3d_shader_code dxbc = {shader_byte_code, shader_byte_code_length}; + struct vkd3d_shader_signature_element *ise; const D3D11_INPUT_ELEMENT_DESC *f; + struct vkd3d_shader_signature is; unsigned int i, index; - HRESULT hr; + int ret;
- if (FAILED(hr = wined3d_extract_shader_input_signature_from_dxbc(&is, shader_byte_code, shader_byte_code_length))) + if ((ret = vkd3d_shader_parse_input_signature(&dxbc, &is, NULL)) < 0) { - ERR("Failed to extract input signature.\n"); + ERR("Failed to extract input signature, ret %d.\n", ret); return E_FAIL; }
if (!(*wined3d_elements = calloc(element_count, sizeof(**wined3d_elements)))) { ERR("Failed to allocate wined3d vertex element array memory.\n"); - free(is.elements); + vkd3d_shader_free_shader_signature(&is); return E_OUTOFMEMORY; }
@@ -96,18 +98,18 @@ static HRESULT d3d11_input_layout_to_wined3d_declaration(const D3D11_INPUT_ELEME { if ((index = find_input_element(element_descs, element_count, &ise[i])) < element_count) { - (*wined3d_elements)[index].output_slot = ise[i].register_idx; + (*wined3d_elements)[index].output_slot = ise[i].register_index; } else if (!is_vs_sysval_semantic(&ise[i])) { - WARN("Input element %s%u not found in shader signature.\n", ise[i].semantic_name, ise[i].semantic_idx); + WARN("Input element %s%u not found in shader signature.\n", ise[i].semantic_name, ise[i].semantic_index); free(*wined3d_elements); - free(is.elements); + vkd3d_shader_free_shader_signature(&is); return E_INVALIDARG; } }
- free(is.elements); + vkd3d_shader_free_shader_signature(&is);
return S_OK; } diff --git a/dlls/wined3d/shader_sm4.c b/dlls/wined3d/shader_sm4.c index e60eb9b2fc4..73001d90833 100644 --- a/dlls/wined3d/shader_sm4.c +++ b/dlls/wined3d/shader_sm4.c @@ -2159,26 +2159,3 @@ 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 a5cf7eca22c..e6126faf838 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -319,8 +319,6 @@ @ cdecl wined3d_vertex_declaration_get_parent(ptr) @ cdecl wined3d_vertex_declaration_incref(ptr)
-@ cdecl wined3d_extract_shader_input_signature_from_dxbc(ptr ptr long) - @ cdecl vkd3d_create_instance(ptr ptr) @ cdecl vkd3d_instance_decref(ptr) @ cdecl vkd3d_instance_get_vk_instance(ptr) diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index a87471fd5d1..5217ee7d221 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -778,6 +778,52 @@ enum wined3d_shader_conditional_op WINED3D_SHADER_CONDITIONAL_OP_Z = 1 };
+enum wined3d_sysval_semantic +{ + WINED3D_SV_POSITION = 0x01, + WINED3D_SV_CLIP_DISTANCE = 0x02, + WINED3D_SV_CULL_DISTANCE = 0x03, + WINED3D_SV_RENDER_TARGET_ARRAY_INDEX = 0x04, + WINED3D_SV_VIEWPORT_ARRAY_INDEX = 0x05, + WINED3D_SV_VERTEX_ID = 0x06, + WINED3D_SV_PRIMITIVE_ID = 0x07, + WINED3D_SV_INSTANCE_ID = 0x08, + WINED3D_SV_IS_FRONT_FACE = 0x09, + WINED3D_SV_SAMPLE_INDEX = 0x0a, + WINED3D_SV_TESS_FACTOR_QUADEDGE = 0x0b, + WINED3D_SV_TESS_FACTOR_QUADINT = 0x0c, + WINED3D_SV_TESS_FACTOR_TRIEDGE = 0x0d, + WINED3D_SV_TESS_FACTOR_TRIINT = 0x0e, + WINED3D_SV_TESS_FACTOR_LINEDET = 0x0f, + WINED3D_SV_TESS_FACTOR_LINEDEN = 0x10, +}; + +enum wined3d_component_type +{ + WINED3D_TYPE_UNKNOWN = 0x0, + WINED3D_TYPE_UINT = 0x1, + WINED3D_TYPE_INT = 0x2, + WINED3D_TYPE_FLOAT = 0x3, +}; + +struct wined3d_shader_signature_element +{ + const char *semantic_name; + unsigned int semantic_idx; + unsigned int stream_idx; + enum wined3d_sysval_semantic sysval_semantic; + enum wined3d_component_type component_type; + unsigned int register_idx; + uint32_t mask; + unsigned int min_precision; +}; + +struct wined3d_shader_signature +{ + unsigned int element_count; + struct wined3d_shader_signature_element *elements; +}; + #define WINED3D_SM1_VS 0xfffeu #define WINED3D_SM1_PS 0xffffu #define WINED3D_SM4_PS 0x0000u diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 1348b6fe368..d1147e03f66 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -811,34 +811,6 @@ enum wined3d_decl_usage WINED3D_DECL_USAGE_SAMPLE = 13 };
-enum wined3d_sysval_semantic -{ - WINED3D_SV_POSITION = 1, - WINED3D_SV_CLIP_DISTANCE = 2, - WINED3D_SV_CULL_DISTANCE = 3, - WINED3D_SV_RENDER_TARGET_ARRAY_INDEX = 4, - WINED3D_SV_VIEWPORT_ARRAY_INDEX = 5, - WINED3D_SV_VERTEX_ID = 6, - WINED3D_SV_PRIMITIVE_ID = 7, - WINED3D_SV_INSTANCE_ID = 8, - WINED3D_SV_IS_FRONT_FACE = 9, - WINED3D_SV_SAMPLE_INDEX = 10, - WINED3D_SV_TESS_FACTOR_QUADEDGE = 11, - WINED3D_SV_TESS_FACTOR_QUADINT = 12, - WINED3D_SV_TESS_FACTOR_TRIEDGE = 13, - WINED3D_SV_TESS_FACTOR_TRIINT = 14, - WINED3D_SV_TESS_FACTOR_LINEDET = 15, - WINED3D_SV_TESS_FACTOR_LINEDEN = 16, -}; - -enum wined3d_component_type -{ - WINED3D_TYPE_UNKNOWN = 0, - WINED3D_TYPE_UINT = 1, - WINED3D_TYPE_INT = 2, - WINED3D_TYPE_FLOAT = 3, -}; - enum wined3d_scanline_ordering { WINED3D_SCANLINE_ORDERING_UNKNOWN = 0, @@ -2113,24 +2085,6 @@ struct wined3d_sampler_desc BOOL srgb_decode; };
-struct wined3d_shader_signature_element -{ - const char *semantic_name; - unsigned int semantic_idx; - unsigned int stream_idx; - enum wined3d_sysval_semantic sysval_semantic; - enum wined3d_component_type component_type; - unsigned int register_idx; - DWORD mask; - unsigned int min_precision; -}; - -struct wined3d_shader_signature -{ - UINT element_count; - struct wined3d_shader_signature_element *elements; -}; - struct wined3d_shader_desc { const DWORD *byte_code; @@ -2930,9 +2884,6 @@ 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); - static inline void wined3d_streaming_buffer_init(struct wined3d_streaming_buffer *buffer, unsigned int bind_flags) { memset(buffer, 0, sizeof(*buffer));
This merge request was approved by Zebediah Figura.