Commit 7d20333f authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

d3d11: Implement d3d11_input_layout_to_wined3d_declaration() on top of…

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 b951c37b. 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().
parent bba63771
MODULE = d3d11.dll MODULE = d3d11.dll
IMPORTLIB = d3d11 IMPORTLIB = d3d11
IMPORTS = dxguid uuid dxgi wined3d IMPORTS = dxguid uuid dxgi wined3d
EXTRAINCL = $(VKD3D_PE_CFLAGS)
C_SRCS = \ C_SRCS = \
async.c \ async.c \
......
...@@ -19,27 +19,28 @@ ...@@ -19,27 +19,28 @@
#include "d3d11_private.h" #include "d3d11_private.h"
#include "winternl.h" #include "winternl.h"
#include <vkd3d_shader.h>
WINE_DEFAULT_DEBUG_CHANNEL(d3d11); 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"); 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, 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; const D3D11_INPUT_ELEMENT_DESC *f;
unsigned int i; unsigned int i;
if (ise->stream_idx) if (ise->stream_index)
return element_count; return element_count;
for (i = 0; i < element_count; ++i) for (i = 0; i < element_count; ++i)
{ {
f = &element_descs[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 i;
} }
return element_count; return element_count;
...@@ -54,22 +55,23 @@ static HRESULT d3d11_input_layout_to_wined3d_declaration(const D3D11_INPUT_ELEME ...@@ -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, UINT element_count, const void *shader_byte_code, SIZE_T shader_byte_code_length,
struct wined3d_vertex_element **wined3d_elements) struct wined3d_vertex_element **wined3d_elements)
{ {
struct wined3d_shader_signature_element *ise; const struct vkd3d_shader_code dxbc = {shader_byte_code, shader_byte_code_length};
struct wined3d_shader_signature is; struct vkd3d_shader_signature_element *ise;
const D3D11_INPUT_ELEMENT_DESC *f; const D3D11_INPUT_ELEMENT_DESC *f;
struct vkd3d_shader_signature is;
unsigned int i, index; 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; return E_FAIL;
} }
if (!(*wined3d_elements = calloc(element_count, sizeof(**wined3d_elements)))) if (!(*wined3d_elements = calloc(element_count, sizeof(**wined3d_elements))))
{ {
ERR("Failed to allocate wined3d vertex element array memory.\n"); ERR("Failed to allocate wined3d vertex element array memory.\n");
free(is.elements); vkd3d_shader_free_shader_signature(&is);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
...@@ -96,18 +98,18 @@ static HRESULT d3d11_input_layout_to_wined3d_declaration(const D3D11_INPUT_ELEME ...@@ -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) 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])) 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(*wined3d_elements);
free(is.elements); vkd3d_shader_free_shader_signature(&is);
return E_INVALIDARG; return E_INVALIDARG;
} }
} }
free(is.elements); vkd3d_shader_free_shader_signature(&is);
return S_OK; return S_OK;
} }
......
...@@ -2159,26 +2159,3 @@ HRESULT shader_extract_from_dxbc(struct wined3d_shader *shader, ...@@ -2159,26 +2159,3 @@ HRESULT shader_extract_from_dxbc(struct wined3d_shader *shader,
return hr; 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);
}
...@@ -319,8 +319,6 @@ ...@@ -319,8 +319,6 @@
@ cdecl wined3d_vertex_declaration_get_parent(ptr) @ cdecl wined3d_vertex_declaration_get_parent(ptr)
@ cdecl wined3d_vertex_declaration_incref(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_create_instance(ptr ptr)
@ cdecl vkd3d_instance_decref(ptr) @ cdecl vkd3d_instance_decref(ptr)
@ cdecl vkd3d_instance_get_vk_instance(ptr) @ cdecl vkd3d_instance_get_vk_instance(ptr)
......
...@@ -778,6 +778,52 @@ enum wined3d_shader_conditional_op ...@@ -778,6 +778,52 @@ enum wined3d_shader_conditional_op
WINED3D_SHADER_CONDITIONAL_OP_Z = 1 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_VS 0xfffeu
#define WINED3D_SM1_PS 0xffffu #define WINED3D_SM1_PS 0xffffu
#define WINED3D_SM4_PS 0x0000u #define WINED3D_SM4_PS 0x0000u
......
...@@ -811,34 +811,6 @@ enum wined3d_decl_usage ...@@ -811,34 +811,6 @@ enum wined3d_decl_usage
WINED3D_DECL_USAGE_SAMPLE = 13 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 enum wined3d_scanline_ordering
{ {
WINED3D_SCANLINE_ORDERING_UNKNOWN = 0, WINED3D_SCANLINE_ORDERING_UNKNOWN = 0,
...@@ -2113,24 +2085,6 @@ struct wined3d_sampler_desc ...@@ -2113,24 +2085,6 @@ struct wined3d_sampler_desc
BOOL srgb_decode; 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 struct wined3d_shader_desc
{ {
const DWORD *byte_code; const DWORD *byte_code;
...@@ -2930,9 +2884,6 @@ ULONG __cdecl wined3d_vertex_declaration_decref(struct wined3d_vertex_declaratio ...@@ -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); void * __cdecl wined3d_vertex_declaration_get_parent(const struct wined3d_vertex_declaration *declaration);
ULONG __cdecl wined3d_vertex_declaration_incref(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) static inline void wined3d_streaming_buffer_init(struct wined3d_streaming_buffer *buffer, unsigned int bind_flags)
{ {
memset(buffer, 0, sizeof(*buffer)); memset(buffer, 0, sizeof(*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