wined3d: Store shader signatures directly in struct wined3d_shader_desc.

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2016-05-23 18:06:29 +02:00 committed by Alexandre Julliard
parent 597c4d52cc
commit 569fcd33dc
5 changed files with 48 additions and 73 deletions

View File

@ -385,8 +385,6 @@ static unsigned int d3d_sm_from_feature_level(D3D_FEATURE_LEVEL feature_level)
static HRESULT d3d_vertex_shader_init(struct d3d_vertex_shader *shader, struct d3d_device *device, static HRESULT d3d_vertex_shader_init(struct d3d_vertex_shader *shader, struct d3d_device *device,
const void *byte_code, SIZE_T byte_code_length) const void *byte_code, SIZE_T byte_code_length)
{ {
struct wined3d_shader_signature output_signature;
struct wined3d_shader_signature input_signature;
struct d3d_shader_info shader_info; struct d3d_shader_info shader_info;
struct wined3d_shader_desc desc; struct wined3d_shader_desc desc;
HRESULT hr; HRESULT hr;
@ -397,8 +395,8 @@ static HRESULT d3d_vertex_shader_init(struct d3d_vertex_shader *shader, struct d
wined3d_mutex_lock(); wined3d_mutex_lock();
wined3d_private_store_init(&shader->private_store); wined3d_private_store_init(&shader->private_store);
shader_info.input_signature = &input_signature; shader_info.input_signature = &desc.input_signature;
shader_info.output_signature = &output_signature; shader_info.output_signature = &desc.output_signature;
if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info))) if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info)))
{ {
WARN("Failed to extract shader, hr %#x.\n", hr); WARN("Failed to extract shader, hr %#x.\n", hr);
@ -408,14 +406,12 @@ static HRESULT d3d_vertex_shader_init(struct d3d_vertex_shader *shader, struct d
} }
desc.byte_code = shader_info.shader_code; desc.byte_code = shader_info.shader_code;
desc.input_signature = &input_signature;
desc.output_signature = &output_signature;
desc.max_version = d3d_sm_from_feature_level(device->feature_level); desc.max_version = d3d_sm_from_feature_level(device->feature_level);
hr = wined3d_shader_create_vs(device->wined3d_device, &desc, shader, hr = wined3d_shader_create_vs(device->wined3d_device, &desc, shader,
&d3d_vertex_shader_wined3d_parent_ops, &shader->wined3d_shader); &d3d_vertex_shader_wined3d_parent_ops, &shader->wined3d_shader);
shader_free_signature(&input_signature); shader_free_signature(&desc.input_signature);
shader_free_signature(&output_signature); shader_free_signature(&desc.output_signature);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr); WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
@ -601,8 +597,6 @@ static const struct wined3d_parent_ops d3d11_hull_shader_wined3d_parent_ops =
static HRESULT d3d11_hull_shader_init(struct d3d11_hull_shader *shader, struct d3d_device *device, static HRESULT d3d11_hull_shader_init(struct d3d11_hull_shader *shader, struct d3d_device *device,
const void *byte_code, SIZE_T byte_code_length) const void *byte_code, SIZE_T byte_code_length)
{ {
struct wined3d_shader_signature output_signature;
struct wined3d_shader_signature input_signature;
struct d3d_shader_info shader_info; struct d3d_shader_info shader_info;
struct wined3d_shader_desc desc; struct wined3d_shader_desc desc;
HRESULT hr; HRESULT hr;
@ -612,8 +606,8 @@ static HRESULT d3d11_hull_shader_init(struct d3d11_hull_shader *shader, struct d
wined3d_mutex_lock(); wined3d_mutex_lock();
wined3d_private_store_init(&shader->private_store); wined3d_private_store_init(&shader->private_store);
shader_info.input_signature = &input_signature; shader_info.input_signature = &desc.input_signature;
shader_info.output_signature = &output_signature; shader_info.output_signature = &desc.output_signature;
if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info))) if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info)))
{ {
WARN("Failed to extract shader, hr %#x.\n", hr); WARN("Failed to extract shader, hr %#x.\n", hr);
@ -623,14 +617,12 @@ static HRESULT d3d11_hull_shader_init(struct d3d11_hull_shader *shader, struct d
} }
desc.byte_code = shader_info.shader_code; desc.byte_code = shader_info.shader_code;
desc.input_signature = &input_signature;
desc.output_signature = &output_signature;
desc.max_version = d3d_sm_from_feature_level(device->feature_level); desc.max_version = d3d_sm_from_feature_level(device->feature_level);
hr = wined3d_shader_create_hs(device->wined3d_device, &desc, shader, hr = wined3d_shader_create_hs(device->wined3d_device, &desc, shader,
&d3d11_hull_shader_wined3d_parent_ops, &shader->wined3d_shader); &d3d11_hull_shader_wined3d_parent_ops, &shader->wined3d_shader);
shader_free_signature(&input_signature); shader_free_signature(&desc.input_signature);
shader_free_signature(&output_signature); shader_free_signature(&desc.output_signature);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to create wined3d hull shader, hr %#x.\n", hr); WARN("Failed to create wined3d hull shader, hr %#x.\n", hr);
@ -797,8 +789,6 @@ static const struct wined3d_parent_ops d3d11_domain_shader_wined3d_parent_ops =
static HRESULT d3d11_domain_shader_init(struct d3d11_domain_shader *shader, struct d3d_device *device, static HRESULT d3d11_domain_shader_init(struct d3d11_domain_shader *shader, struct d3d_device *device,
const void *byte_code, SIZE_T byte_code_length) const void *byte_code, SIZE_T byte_code_length)
{ {
struct wined3d_shader_signature output_signature;
struct wined3d_shader_signature input_signature;
struct d3d_shader_info shader_info; struct d3d_shader_info shader_info;
struct wined3d_shader_desc desc; struct wined3d_shader_desc desc;
HRESULT hr; HRESULT hr;
@ -808,8 +798,8 @@ static HRESULT d3d11_domain_shader_init(struct d3d11_domain_shader *shader, stru
wined3d_mutex_lock(); wined3d_mutex_lock();
wined3d_private_store_init(&shader->private_store); wined3d_private_store_init(&shader->private_store);
shader_info.input_signature = &input_signature; shader_info.input_signature = &desc.input_signature;
shader_info.output_signature = &output_signature; shader_info.output_signature = &desc.output_signature;
if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info))) if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info)))
{ {
WARN("Failed to extract shader, hr %#x.\n", hr); WARN("Failed to extract shader, hr %#x.\n", hr);
@ -819,14 +809,12 @@ static HRESULT d3d11_domain_shader_init(struct d3d11_domain_shader *shader, stru
} }
desc.byte_code = shader_info.shader_code; desc.byte_code = shader_info.shader_code;
desc.input_signature = &input_signature;
desc.output_signature = &output_signature;
desc.max_version = d3d_sm_from_feature_level(device->feature_level); desc.max_version = d3d_sm_from_feature_level(device->feature_level);
hr = wined3d_shader_create_ds(device->wined3d_device, &desc, shader, hr = wined3d_shader_create_ds(device->wined3d_device, &desc, shader,
&d3d11_domain_shader_wined3d_parent_ops, &shader->wined3d_shader); &d3d11_domain_shader_wined3d_parent_ops, &shader->wined3d_shader);
shader_free_signature(&input_signature); shader_free_signature(&desc.input_signature);
shader_free_signature(&output_signature); shader_free_signature(&desc.output_signature);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to create wined3d domain shader, hr %#x.\n", hr); WARN("Failed to create wined3d domain shader, hr %#x.\n", hr);
@ -1096,8 +1084,6 @@ static const struct wined3d_parent_ops d3d_geometry_shader_wined3d_parent_ops =
static HRESULT d3d_geometry_shader_init(struct d3d_geometry_shader *shader, struct d3d_device *device, static HRESULT d3d_geometry_shader_init(struct d3d_geometry_shader *shader, struct d3d_device *device,
const void *byte_code, SIZE_T byte_code_length) const void *byte_code, SIZE_T byte_code_length)
{ {
struct wined3d_shader_signature output_signature;
struct wined3d_shader_signature input_signature;
struct d3d_shader_info shader_info; struct d3d_shader_info shader_info;
struct wined3d_shader_desc desc; struct wined3d_shader_desc desc;
HRESULT hr; HRESULT hr;
@ -1108,8 +1094,8 @@ static HRESULT d3d_geometry_shader_init(struct d3d_geometry_shader *shader, stru
wined3d_mutex_lock(); wined3d_mutex_lock();
wined3d_private_store_init(&shader->private_store); wined3d_private_store_init(&shader->private_store);
shader_info.input_signature = &input_signature; shader_info.input_signature = &desc.input_signature;
shader_info.output_signature = &output_signature; shader_info.output_signature = &desc.output_signature;
if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info))) if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info)))
{ {
WARN("Failed to extract shader, hr %#x.\n", hr); WARN("Failed to extract shader, hr %#x.\n", hr);
@ -1119,14 +1105,12 @@ static HRESULT d3d_geometry_shader_init(struct d3d_geometry_shader *shader, stru
} }
desc.byte_code = shader_info.shader_code; desc.byte_code = shader_info.shader_code;
desc.input_signature = &input_signature;
desc.output_signature = &output_signature;
desc.max_version = d3d_sm_from_feature_level(device->feature_level); desc.max_version = d3d_sm_from_feature_level(device->feature_level);
hr = wined3d_shader_create_gs(device->wined3d_device, &desc, shader, hr = wined3d_shader_create_gs(device->wined3d_device, &desc, shader,
&d3d_geometry_shader_wined3d_parent_ops, &shader->wined3d_shader); &d3d_geometry_shader_wined3d_parent_ops, &shader->wined3d_shader);
shader_free_signature(&input_signature); shader_free_signature(&desc.input_signature);
shader_free_signature(&output_signature); shader_free_signature(&desc.output_signature);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to create wined3d geometry shader, hr %#x.\n", hr); WARN("Failed to create wined3d geometry shader, hr %#x.\n", hr);
@ -1422,8 +1406,6 @@ static const struct wined3d_parent_ops d3d_pixel_shader_wined3d_parent_ops =
static HRESULT d3d_pixel_shader_init(struct d3d_pixel_shader *shader, struct d3d_device *device, static HRESULT d3d_pixel_shader_init(struct d3d_pixel_shader *shader, struct d3d_device *device,
const void *byte_code, SIZE_T byte_code_length) const void *byte_code, SIZE_T byte_code_length)
{ {
struct wined3d_shader_signature output_signature;
struct wined3d_shader_signature input_signature;
struct d3d_shader_info shader_info; struct d3d_shader_info shader_info;
struct wined3d_shader_desc desc; struct wined3d_shader_desc desc;
HRESULT hr; HRESULT hr;
@ -1434,8 +1416,8 @@ static HRESULT d3d_pixel_shader_init(struct d3d_pixel_shader *shader, struct d3d
wined3d_mutex_lock(); wined3d_mutex_lock();
wined3d_private_store_init(&shader->private_store); wined3d_private_store_init(&shader->private_store);
shader_info.input_signature = &input_signature; shader_info.input_signature = &desc.input_signature;
shader_info.output_signature = &output_signature; shader_info.output_signature = &desc.output_signature;
if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info))) if (FAILED(hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info)))
{ {
WARN("Failed to extract shader, hr %#x.\n", hr); WARN("Failed to extract shader, hr %#x.\n", hr);
@ -1445,14 +1427,12 @@ static HRESULT d3d_pixel_shader_init(struct d3d_pixel_shader *shader, struct d3d
} }
desc.byte_code = shader_info.shader_code; desc.byte_code = shader_info.shader_code;
desc.input_signature = &input_signature;
desc.output_signature = &output_signature;
desc.max_version = d3d_sm_from_feature_level(device->feature_level); desc.max_version = d3d_sm_from_feature_level(device->feature_level);
hr = wined3d_shader_create_ps(device->wined3d_device, &desc, shader, hr = wined3d_shader_create_ps(device->wined3d_device, &desc, shader,
&d3d_pixel_shader_wined3d_parent_ops, &shader->wined3d_shader); &d3d_pixel_shader_wined3d_parent_ops, &shader->wined3d_shader);
shader_free_signature(&input_signature); shader_free_signature(&desc.input_signature);
shader_free_signature(&output_signature); shader_free_signature(&desc.output_signature);
if (FAILED(hr)) if (FAILED(hr))
{ {
WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr); WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);

View File

@ -117,8 +117,8 @@ HRESULT d3d8_vertex_shader_init(struct d3d8_vertex_shader *shader, struct d3d8_d
FIXME("Usage %#x not implemented.\n", usage); FIXME("Usage %#x not implemented.\n", usage);
desc.byte_code = byte_code; desc.byte_code = byte_code;
desc.input_signature = NULL; desc.input_signature.element_count = 0;
desc.output_signature = NULL; desc.output_signature.element_count = 0;
desc.max_version = 1; desc.max_version = 1;
wined3d_mutex_lock(); wined3d_mutex_lock();
@ -166,8 +166,8 @@ HRESULT d3d8_pixel_shader_init(struct d3d8_pixel_shader *shader, struct d3d8_dev
shader->handle = shader_handle; shader->handle = shader_handle;
desc.byte_code = byte_code; desc.byte_code = byte_code;
desc.input_signature = NULL; desc.input_signature.element_count = 0;
desc.output_signature = NULL; desc.output_signature.element_count = 0;
desc.max_version = 1; desc.max_version = 1;
wined3d_mutex_lock(); wined3d_mutex_lock();

View File

@ -143,8 +143,8 @@ HRESULT vertexshader_init(struct d3d9_vertexshader *shader, struct d3d9_device *
shader->IDirect3DVertexShader9_iface.lpVtbl = &d3d9_vertexshader_vtbl; shader->IDirect3DVertexShader9_iface.lpVtbl = &d3d9_vertexshader_vtbl;
desc.byte_code = byte_code; desc.byte_code = byte_code;
desc.input_signature = NULL; desc.input_signature.element_count = 0;
desc.output_signature = NULL; desc.output_signature.element_count = 0;
desc.max_version = 3; desc.max_version = 3;
wined3d_mutex_lock(); wined3d_mutex_lock();
@ -294,8 +294,8 @@ HRESULT pixelshader_init(struct d3d9_pixelshader *shader, struct d3d9_device *de
shader->IDirect3DPixelShader9_iface.lpVtbl = &d3d9_pixelshader_vtbl; shader->IDirect3DPixelShader9_iface.lpVtbl = &d3d9_pixelshader_vtbl;
desc.byte_code = byte_code; desc.byte_code = byte_code;
desc.input_signature = NULL; desc.input_signature.element_count = 0;
desc.output_signature = NULL; desc.output_signature.element_count = 0;
desc.max_version = 3; desc.max_version = 3;
wined3d_mutex_lock(); wined3d_mutex_lock();

View File

@ -2737,6 +2737,9 @@ static HRESULT shader_signature_copy(struct wined3d_shader_signature *dst,
SIZE_T len; SIZE_T len;
char *ptr; char *ptr;
if (!src->element_count)
return WINED3D_OK;
ptr = *signature_strings; ptr = *signature_strings;
dst->element_count = src->element_count; dst->element_count = src->element_count;
@ -2778,42 +2781,34 @@ static HRESULT shader_init(struct wined3d_shader *shader, struct wined3d_device
shader->parent_ops = parent_ops; shader->parent_ops = parent_ops;
total = 0; total = 0;
if (desc->input_signature) for (i = 0; i < desc->input_signature.element_count; ++i)
{ {
for (i = 0; i < desc->input_signature->element_count; ++i) e = &desc->input_signature.elements[i];
{ len = strlen(e->semantic_name);
e = &desc->input_signature->elements[i]; if (len >= ~(SIZE_T)0 - total)
len = strlen(e->semantic_name); return E_OUTOFMEMORY;
if (len >= ~(SIZE_T)0 - total)
return E_OUTOFMEMORY;
total += len + 1; total += len + 1;
}
} }
if (desc->output_signature) for (i = 0; i < desc->output_signature.element_count; ++i)
{ {
for (i = 0; i < desc->output_signature->element_count; ++i) e = &desc->output_signature.elements[i];
{ len = strlen(e->semantic_name);
e = &desc->output_signature->elements[i]; if (len >= ~(SIZE_T)0 - total)
len = strlen(e->semantic_name); return E_OUTOFMEMORY;
if (len >= ~(SIZE_T)0 - total)
return E_OUTOFMEMORY;
total += len + 1; total += len + 1;
}
} }
if (!(shader->signature_strings = HeapAlloc(GetProcessHeap(), 0, total))) if (total && !(shader->signature_strings = HeapAlloc(GetProcessHeap(), 0, total)))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
ptr = shader->signature_strings; ptr = shader->signature_strings;
if (desc->input_signature && FAILED(hr = shader_signature_copy(&shader->input_signature, if (FAILED(hr = shader_signature_copy(&shader->input_signature, &desc->input_signature, &ptr)))
desc->input_signature, &ptr)))
{ {
HeapFree(GetProcessHeap(), 0, shader->signature_strings); HeapFree(GetProcessHeap(), 0, shader->signature_strings);
return hr; return hr;
} }
if (desc->output_signature && FAILED(hr = shader_signature_copy(&shader->output_signature, if (FAILED(hr = shader_signature_copy(&shader->output_signature, &desc->output_signature, &ptr)))
desc->output_signature, &ptr)))
{ {
HeapFree(GetProcessHeap(), 0, shader->input_signature.elements); HeapFree(GetProcessHeap(), 0, shader->input_signature.elements);
HeapFree(GetProcessHeap(), 0, shader->signature_strings); HeapFree(GetProcessHeap(), 0, shader->signature_strings);

View File

@ -1929,8 +1929,8 @@ struct wined3d_shader_signature
struct wined3d_shader_desc struct wined3d_shader_desc
{ {
const DWORD *byte_code; const DWORD *byte_code;
const struct wined3d_shader_signature *input_signature; struct wined3d_shader_signature input_signature;
const struct wined3d_shader_signature *output_signature; struct wined3d_shader_signature output_signature;
unsigned int max_version; unsigned int max_version;
}; };