wined3d: When creating a new shader, check shader type and version.

This commit is contained in:
Matteo Bruni 2011-09-23 17:03:19 +02:00 committed by Alexandre Julliard
parent f5307025fc
commit 2a146448f4
5 changed files with 38 additions and 23 deletions

View file

@ -262,7 +262,7 @@ HRESULT d3d10_vertex_shader_init(struct d3d10_vertex_shader *shader, struct d3d1
}
hr = wined3d_shader_create_vs(device->wined3d_device, shader_info.shader_code,
&shader->output_signature, shader, &d3d10_vertex_shader_wined3d_parent_ops, &shader->wined3d_shader);
&shader->output_signature, shader, &d3d10_vertex_shader_wined3d_parent_ops, &shader->wined3d_shader, 4);
if (FAILED(hr))
{
WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
@ -408,7 +408,7 @@ HRESULT d3d10_geometry_shader_init(struct d3d10_geometry_shader *shader, struct
}
hr = wined3d_shader_create_gs(device->wined3d_device, shader_info.shader_code,
&shader->output_signature, shader, &d3d10_geometry_shader_wined3d_parent_ops, &shader->wined3d_shader);
&shader->output_signature, shader, &d3d10_geometry_shader_wined3d_parent_ops, &shader->wined3d_shader, 4);
if (FAILED(hr))
{
WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
@ -548,7 +548,7 @@ HRESULT d3d10_pixel_shader_init(struct d3d10_pixel_shader *shader, struct d3d10_
}
hr = wined3d_shader_create_ps(device->wined3d_device, shader_info.shader_code,
&shader->output_signature, shader, &d3d10_pixel_shader_wined3d_parent_ops, &shader->wined3d_shader);
&shader->output_signature, shader, &d3d10_pixel_shader_wined3d_parent_ops, &shader->wined3d_shader, 4);
if (FAILED(hr))
{
WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);

View file

@ -177,7 +177,7 @@ HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Im
wined3d_mutex_lock();
hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL /* output signature */,
shader, &d3d8_vertexshader_wined3d_parent_ops, &shader->wined3d_shader);
shader, &d3d8_vertexshader_wined3d_parent_ops, &shader->wined3d_shader, 1);
wined3d_mutex_unlock();
if (FAILED(hr))
{
@ -278,7 +278,7 @@ HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl
wined3d_mutex_lock();
hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader,
&d3d8_pixelshader_wined3d_parent_ops, &shader->wined3d_shader);
&d3d8_pixelshader_wined3d_parent_ops, &shader->wined3d_shader, 1);
wined3d_mutex_unlock();
if (FAILED(hr))
{

View file

@ -145,7 +145,7 @@ HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Im
wined3d_mutex_lock();
hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL,
shader, &d3d9_vertexshader_wined3d_parent_ops, &shader->wined3d_shader);
shader, &d3d9_vertexshader_wined3d_parent_ops, &shader->wined3d_shader, 3);
wined3d_mutex_unlock();
if (FAILED(hr))
{
@ -291,7 +291,7 @@ HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl
wined3d_mutex_lock();
hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader,
&d3d9_pixelshader_wined3d_parent_ops, &shader->wined3d_shader);
&d3d9_pixelshader_wined3d_parent_ops, &shader->wined3d_shader, 3);
wined3d_mutex_unlock();
if (FAILED(hr))
{

View file

@ -1553,7 +1553,8 @@ const struct wined3d_shader_backend_ops none_shader_backend =
};
static HRESULT shader_set_function(struct wined3d_shader *shader, const DWORD *byte_code,
const struct wined3d_shader_signature *output_signature, DWORD float_const_count)
const struct wined3d_shader_signature *output_signature, DWORD float_const_count,
enum wined3d_shader_type type, unsigned int max_version)
{
struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
const struct wined3d_shader_frontend *fe;
@ -1591,6 +1592,17 @@ static HRESULT shader_set_function(struct wined3d_shader *shader, const DWORD *b
byte_code, float_const_count);
if (FAILED(hr)) return hr;
if (reg_maps->shader_version.type != type)
{
WARN("Wrong shader type %d.\n", reg_maps->shader_version.type);
return WINED3DERR_INVALIDCALL;
}
if (reg_maps->shader_version.major > max_version)
{
WARN("Shader version %d not supported by this D3D API version.\n", reg_maps->shader_version.major);
return WINED3DERR_INVALIDCALL;
}
shader->function = HeapAlloc(GetProcessHeap(), 0, shader->functionLength);
if (!shader->function)
return E_OUTOFMEMORY;
@ -1802,7 +1814,7 @@ static void vertexshader_set_limits(struct wined3d_shader *shader)
static HRESULT vertexshader_init(struct wined3d_shader *shader, struct wined3d_device *device,
const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
void *parent, const struct wined3d_parent_ops *parent_ops)
void *parent, const struct wined3d_parent_ops *parent_ops, unsigned int max_version)
{
struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
unsigned int i;
@ -1812,7 +1824,8 @@ static HRESULT vertexshader_init(struct wined3d_shader *shader, struct wined3d_d
if (!byte_code) return WINED3DERR_INVALIDCALL;
shader_init(shader, device, parent, parent_ops);
hr = shader_set_function(shader, byte_code, output_signature, device->d3d_vshader_constantF);
hr = shader_set_function(shader, byte_code, output_signature, device->d3d_vshader_constantF,
WINED3D_SHADER_TYPE_VERTEX, max_version);
if (FAILED(hr))
{
WARN("Failed to set function, hr %#x.\n", hr);
@ -1851,12 +1864,13 @@ static HRESULT vertexshader_init(struct wined3d_shader *shader, struct wined3d_d
static HRESULT geometryshader_init(struct wined3d_shader *shader, struct wined3d_device *device,
const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
void *parent, const struct wined3d_parent_ops *parent_ops)
void *parent, const struct wined3d_parent_ops *parent_ops, unsigned int max_version)
{
HRESULT hr;
shader_init(shader, device, parent, parent_ops);
hr = shader_set_function(shader, byte_code, output_signature, 0);
hr = shader_set_function(shader, byte_code, output_signature, 0,
WINED3D_SHADER_TYPE_GEOMETRY, max_version);
if (FAILED(hr))
{
WARN("Failed to set function, hr %#x.\n", hr);
@ -2057,7 +2071,7 @@ static void pixelshader_set_limits(struct wined3d_shader *shader)
static HRESULT pixelshader_init(struct wined3d_shader *shader, struct wined3d_device *device,
const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
void *parent, const struct wined3d_parent_ops *parent_ops)
void *parent, const struct wined3d_parent_ops *parent_ops, unsigned int max_version)
{
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
unsigned int i, highest_reg_used = 0, num_regs_used = 0;
@ -2066,7 +2080,8 @@ static HRESULT pixelshader_init(struct wined3d_shader *shader, struct wined3d_de
if (!byte_code) return WINED3DERR_INVALIDCALL;
shader_init(shader, device, parent, parent_ops);
hr = shader_set_function(shader, byte_code, output_signature, device->d3d_pshader_constantF);
hr = shader_set_function(shader, byte_code, output_signature, device->d3d_pshader_constantF,
WINED3D_SHADER_TYPE_PIXEL, max_version);
if (FAILED(hr))
{
WARN("Failed to set function, hr %#x.\n", hr);
@ -2167,7 +2182,7 @@ void pixelshader_update_samplers(struct wined3d_shader_reg_maps *reg_maps, struc
HRESULT CDECL wined3d_shader_create_gs(struct wined3d_device *device, const DWORD *byte_code,
const struct wined3d_shader_signature *output_signature, void *parent,
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader)
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version)
{
struct wined3d_shader *object;
HRESULT hr;
@ -2182,7 +2197,7 @@ HRESULT CDECL wined3d_shader_create_gs(struct wined3d_device *device, const DWOR
return E_OUTOFMEMORY;
}
hr = geometryshader_init(object, device, byte_code, output_signature, parent, parent_ops);
hr = geometryshader_init(object, device, byte_code, output_signature, parent, parent_ops, max_version);
if (FAILED(hr))
{
WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
@ -2198,7 +2213,7 @@ HRESULT CDECL wined3d_shader_create_gs(struct wined3d_device *device, const DWOR
HRESULT CDECL wined3d_shader_create_ps(struct wined3d_device *device, const DWORD *byte_code,
const struct wined3d_shader_signature *output_signature, void *parent,
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader)
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version)
{
struct wined3d_shader *object;
HRESULT hr;
@ -2216,7 +2231,7 @@ HRESULT CDECL wined3d_shader_create_ps(struct wined3d_device *device, const DWOR
return E_OUTOFMEMORY;
}
hr = pixelshader_init(object, device, byte_code, output_signature, parent, parent_ops);
hr = pixelshader_init(object, device, byte_code, output_signature, parent, parent_ops, max_version);
if (FAILED(hr))
{
WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
@ -2232,7 +2247,7 @@ HRESULT CDECL wined3d_shader_create_ps(struct wined3d_device *device, const DWOR
HRESULT CDECL wined3d_shader_create_vs(struct wined3d_device *device, const DWORD *byte_code,
const struct wined3d_shader_signature *output_signature, void *parent,
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader)
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version)
{
struct wined3d_shader *object;
HRESULT hr;
@ -2250,7 +2265,7 @@ HRESULT CDECL wined3d_shader_create_vs(struct wined3d_device *device, const DWOR
return E_OUTOFMEMORY;
}
hr = vertexshader_init(object, device, byte_code, output_signature, parent, parent_ops);
hr = vertexshader_init(object, device, byte_code, output_signature, parent, parent_ops, max_version);
if (FAILED(hr))
{
WARN("Failed to initialize vertex shader, hr %#x.\n", hr);

View file

@ -2392,13 +2392,13 @@ ULONG __cdecl wined3d_rendertarget_view_incref(struct wined3d_rendertarget_view
HRESULT __cdecl wined3d_shader_create_gs(struct wined3d_device *device, const DWORD *byte_code,
const struct wined3d_shader_signature *output_signature, void *parent,
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader);
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version);
HRESULT __cdecl wined3d_shader_create_ps(struct wined3d_device *device, const DWORD *byte_code,
const struct wined3d_shader_signature *output_signature, void *parent,
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader);
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version);
HRESULT __cdecl wined3d_shader_create_vs(struct wined3d_device *device, const DWORD *byte_code,
const struct wined3d_shader_signature *output_signature, void *parent,
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader);
const struct wined3d_parent_ops *parent_ops, struct wined3d_shader **shader, unsigned int max_version);
ULONG __cdecl wined3d_shader_decref(struct wined3d_shader *shader);
HRESULT __cdecl wined3d_shader_get_byte_code(const struct wined3d_shader *shader,
void *byte_code, UINT *byte_code_size);