Commit 4cfac484 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Move feature level selection to wined3d_state_create().

parent 53fdee61
......@@ -295,7 +295,8 @@ static struct wined3d_state *d3d_device_context_state_get_wined3d_state(struct d
if ((entry = d3d_device_context_state_get_entry(state, device)))
return entry->wined3d_state;
if (FAILED(wined3d_state_create(device->wined3d_device, &wined3d_state)))
if (FAILED(wined3d_state_create(device->wined3d_device,
(enum wined3d_feature_level *)&device->feature_level, 1, &wined3d_state)))
return NULL;
if (!d3d_device_context_state_add_entry(state, device, wined3d_state))
......
......@@ -3008,7 +3008,8 @@ static DWORD WINAPI wined3d_cs_run(void *ctx)
FreeLibraryAndExitThread(wined3d_module, 0);
}
struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device, enum wined3d_feature_level feature_level)
struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device,
const enum wined3d_feature_level *levels, unsigned int level_count)
{
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
struct wined3d_cs *cs;
......@@ -3016,12 +3017,11 @@ struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device, enum wined3d
if (!(cs = heap_alloc_zero(sizeof(*cs))))
return NULL;
if (!(cs->c.state = heap_alloc_zero(sizeof(*cs->c.state))))
if (FAILED(wined3d_state_create(device, levels, level_count, &cs->c.state)))
{
heap_free(cs);
return NULL;
}
state_init(cs->c.state, &device->adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT, feature_level);
cs->c.ops = &wined3d_cs_st_ops;
cs->c.device = device;
......
......@@ -5976,27 +5976,6 @@ static int wined3d_depth_stencil_state_compare(const void *key, const struct win
return memcmp(&state->desc, key, sizeof(state->desc));
}
static BOOL wined3d_select_feature_level(const struct wined3d_adapter *adapter,
const enum wined3d_feature_level *levels, unsigned int level_count,
enum wined3d_feature_level *selected_level)
{
const struct wined3d_d3d_info *d3d_info = &adapter->d3d_info;
unsigned int i;
for (i = 0; i < level_count; ++i)
{
if (levels[i] && d3d_info->feature_level >= levels[i])
{
*selected_level = levels[i];
return TRUE;
}
}
FIXME_(winediag)("None of the requested D3D feature levels is supported on this GPU "
"with the current shader backend.\n");
return FALSE;
}
HRESULT wined3d_device_init(struct wined3d_device *device, struct wined3d *wined3d,
unsigned int adapter_idx, enum wined3d_device_type device_type, HWND focus_window, unsigned int flags,
BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count,
......@@ -6005,15 +5984,9 @@ HRESULT wined3d_device_init(struct wined3d_device *device, struct wined3d *wined
struct wined3d_adapter *adapter = wined3d->adapters[adapter_idx];
const struct wined3d_fragment_pipe_ops *fragment_pipeline;
const struct wined3d_vertex_pipe_ops *vertex_pipeline;
enum wined3d_feature_level feature_level;
unsigned int i;
HRESULT hr;
if (!wined3d_select_feature_level(adapter, levels, level_count, &feature_level))
return E_FAIL;
TRACE("Device feature level %s.\n", wined3d_debug_feature_level(feature_level));
device->ref = 1;
device->wined3d = wined3d;
wined3d_incref(device->wined3d);
......@@ -6058,7 +6031,7 @@ HRESULT wined3d_device_init(struct wined3d_device *device, struct wined3d *wined
device->max_frame_latency = 3;
if (!(device->cs = wined3d_cs_create(device, feature_level)))
if (!(device->cs = wined3d_cs_create(device, levels, level_count)))
{
WARN("Failed to create command stream.\n");
hr = E_FAIL;
......
......@@ -27,6 +27,7 @@
#include "wined3d_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
WINE_DECLARE_DEBUG_CHANNEL(winediag);
static const DWORD pixel_states_render[] =
{
......@@ -1887,15 +1888,43 @@ void state_init(struct wined3d_state *state, const struct wined3d_d3d_info *d3d_
state_init_default(state, d3d_info);
}
HRESULT CDECL wined3d_state_create(struct wined3d_device *device, struct wined3d_state **state)
static bool wined3d_select_feature_level(const struct wined3d_adapter *adapter,
const enum wined3d_feature_level *levels, unsigned int level_count,
enum wined3d_feature_level *selected_level)
{
const struct wined3d_d3d_info *d3d_info = &adapter->d3d_info;
unsigned int i;
for (i = 0; i < level_count; ++i)
{
if (levels[i] && d3d_info->feature_level >= levels[i])
{
*selected_level = levels[i];
return true;
}
}
FIXME_(winediag)("None of the requested D3D feature levels is supported on this GPU "
"with the current shader backend.\n");
return false;
}
HRESULT CDECL wined3d_state_create(struct wined3d_device *device,
const enum wined3d_feature_level *levels, unsigned int level_count, struct wined3d_state **state)
{
enum wined3d_feature_level feature_level;
struct wined3d_state *object;
TRACE("device %p, state %p.\n", device, state);
TRACE("device %p, levels %p, level_count %u, state %p.\n", device, levels, level_count, state);
if (!wined3d_select_feature_level(device->adapter, levels, level_count, &feature_level))
return E_FAIL;
TRACE("Selected feature level %s.\n", wined3d_debug_feature_level(feature_level));
if (!(object = heap_alloc_zero(sizeof(*object))))
return E_OUTOFMEMORY;
state_init(object, &device->adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT, device->cs->c.state->feature_level);
state_init(object, &device->adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT, feature_level);
*state = object;
return S_OK;
......
......@@ -245,7 +245,7 @@
@ cdecl wined3d_shader_resource_view_get_parent(ptr)
@ cdecl wined3d_shader_resource_view_incref(ptr)
@ cdecl wined3d_state_create(ptr ptr)
@ cdecl wined3d_state_create(ptr ptr long ptr)
@ cdecl wined3d_state_destroy(ptr)
@ cdecl wined3d_state_get_feature_level(ptr)
......
......@@ -4717,7 +4717,7 @@ struct wined3d_cs
};
struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device,
enum wined3d_feature_level feature_level) DECLSPEC_HIDDEN;
const enum wined3d_feature_level *levels, unsigned int level_count) DECLSPEC_HIDDEN;
void wined3d_cs_destroy(struct wined3d_cs *cs) DECLSPEC_HIDDEN;
void wined3d_cs_destroy_object(struct wined3d_cs *cs,
void (*callback)(void *object), void *object) DECLSPEC_HIDDEN;
......
......@@ -2745,7 +2745,8 @@ void __cdecl wined3d_shader_resource_view_generate_mipmaps(struct wined3d_shader
void * __cdecl wined3d_shader_resource_view_get_parent(const struct wined3d_shader_resource_view *view);
ULONG __cdecl wined3d_shader_resource_view_incref(struct wined3d_shader_resource_view *view);
HRESULT __cdecl wined3d_state_create(struct wined3d_device *device, struct wined3d_state **state);
HRESULT __cdecl wined3d_state_create(struct wined3d_device *device,
const enum wined3d_feature_level *levels, unsigned int level_count, struct wined3d_state **state);
void __cdecl wined3d_state_destroy(struct wined3d_state *state);
enum wined3d_feature_level __cdecl wined3d_state_get_feature_level(const struct wined3d_state *state);
......
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