diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index af3addc2487..43befb82bce 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -2577,7 +2577,7 @@ BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_de * result in changes to the current FBO, due to using e.g. FBO blits for * updating a resource location. */ device_update_tex_unit_map(device); - device_preload_textures(device); + device_preload_textures(device, context); if (isStateDirty(context, STATE_VDECL) || isStateDirty(context, STATE_STREAMSRC)) context_update_stream_info(context, state); if (state->index_buffer) diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 627f0eb5797..d9f7eb111f9 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -134,17 +134,20 @@ static enum wined3d_primitive_type d3d_primitive_type_from_gl(GLenum primitive_t } } -static void device_preload_texture(const struct wined3d_state *state, unsigned int idx) +/* Context activation is done by the caller. */ +static void device_preload_texture(const struct wined3d_state *state, + struct wined3d_context *context, unsigned int idx) { struct wined3d_texture *texture; enum WINED3DSRGB srgb; if (!(texture = state->textures[idx])) return; srgb = state->sampler_states[idx][WINED3D_SAMP_SRGB_TEXTURE] ? SRGB_SRGB : SRGB_RGB; - texture->texture_ops->texture_preload(texture, srgb); + texture->texture_ops->texture_preload(texture, context, srgb); } -void device_preload_textures(const struct wined3d_device *device) +/* Context activation is done by the caller. */ +void device_preload_textures(const struct wined3d_device *device, struct wined3d_context *context) { const struct wined3d_state *state = &device->state; unsigned int i; @@ -154,7 +157,7 @@ void device_preload_textures(const struct wined3d_device *device) for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i) { if (state->vertex_shader->reg_maps.sampler_type[i]) - device_preload_texture(state, MAX_FRAGMENT_SAMPLERS + i); + device_preload_texture(state, context, MAX_FRAGMENT_SAMPLERS + i); } } @@ -163,7 +166,7 @@ void device_preload_textures(const struct wined3d_device *device) for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i) { if (state->pixel_shader->reg_maps.sampler_type[i]) - device_preload_texture(state, i); + device_preload_texture(state, context, i); } } else @@ -173,7 +176,7 @@ void device_preload_textures(const struct wined3d_device *device) for (i = 0; ffu_map; ffu_map >>= 1, ++i) { if (ffu_map & 1) - device_preload_texture(state, i); + device_preload_texture(state, context, i); } } } @@ -3909,6 +3912,7 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device, enum wined3d_resource_type type; unsigned int level_count, i; HRESULT hr; + struct wined3d_context *context; TRACE("device %p, src_texture %p, dst_texture %p.\n", device, src_texture, dst_texture); @@ -3947,7 +3951,9 @@ HRESULT CDECL wined3d_device_update_texture(struct wined3d_device *device, } /* Make sure that the destination texture is loaded. */ - dst_texture->texture_ops->texture_preload(dst_texture, SRGB_RGB); + context = context_acquire(device, NULL); + dst_texture->texture_ops->texture_preload(dst_texture, context, SRGB_RGB); + context_release(context); /* Update every surface level of the texture. */ switch (type) diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c index 42f6cb709c7..0b4b3f7e071 100644 --- a/dlls/wined3d/drawprim.c +++ b/dlls/wined3d/drawprim.c @@ -613,9 +613,6 @@ void draw_primitive(struct wined3d_device *device, UINT start_idx, UINT index_co } } - /* Signals other modules that a drawing is in progress and the stateblock finalized */ - device->isInDraw = TRUE; - context = context_acquire(device, device->fb.render_targets[0]); if (!context->valid) { @@ -780,7 +777,4 @@ void draw_primitive(struct wined3d_device *device, UINT start_idx, UINT index_co context_release(context); TRACE("Done all gl drawing\n"); - - /* Control goes back to the device, stateblock values may change again */ - device->isInDraw = FALSE; } diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index a48d0bff163..66587a13743 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -3690,25 +3690,24 @@ HRESULT CDECL wined3d_surface_flip(struct wined3d_surface *surface, struct wined void surface_internal_preload(struct wined3d_surface *surface, enum WINED3DSRGB srgb) { struct wined3d_device *device = surface->resource.device; + struct wined3d_context *context; TRACE("iface %p, srgb %#x.\n", surface, srgb); + /* TODO: Use already acquired context when possible. */ + context = context_acquire(device, NULL); + if (surface->container) { struct wined3d_texture *texture = surface->container; TRACE("Passing to container (%p).\n", texture); - texture->texture_ops->texture_preload(texture, srgb); + texture->texture_ops->texture_preload(texture, context, srgb); } else { - struct wined3d_context *context; - TRACE("(%p) : About to load surface\n", surface); - /* TODO: Use already acquired context when possible. */ - context = context_acquire(device, NULL); - surface_load(surface, srgb == SRGB_SRGB); if (surface->resource.pool == WINED3D_POOL_DEFAULT) @@ -3718,9 +3717,8 @@ void surface_internal_preload(struct wined3d_surface *surface, enum WINED3DSRGB tmp = 0.9f; context->gl_info->gl_ops.gl.p_glPrioritizeTextures(1, &surface->texture_name, &tmp); } - - context_release(context); } + context_release(context); } /* Read the framebuffer back into the surface */ diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c index 5d24ada1657..56d13f67d56 100644 --- a/dlls/wined3d/texture.c +++ b/dlls/wined3d/texture.c @@ -477,7 +477,10 @@ DWORD CDECL wined3d_texture_get_priority(const struct wined3d_texture *texture) void CDECL wined3d_texture_preload(struct wined3d_texture *texture) { - texture->texture_ops->texture_preload(texture, SRGB_ANY); + struct wined3d_context *context; + context = context_acquire(texture->resource.device, NULL); + texture->texture_ops->texture_preload(texture, context, SRGB_ANY); + context_release(context); } void * CDECL wined3d_texture_get_parent(const struct wined3d_texture *texture) @@ -668,12 +671,12 @@ static BOOL texture_srgb_mode(const struct wined3d_texture *texture, enum WINED3 } } -static void texture2d_preload(struct wined3d_texture *texture, enum WINED3DSRGB srgb) +/* Context activation is done by the caller */ +static void texture2d_preload(struct wined3d_texture *texture, + struct wined3d_context *context, enum WINED3DSRGB srgb) { UINT sub_count = texture->level_count * texture->layer_count; - struct wined3d_device *device = texture->resource.device; - const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; - struct wined3d_context *context = NULL; + const struct wined3d_gl_info *gl_info = context->gl_info; BOOL srgb_mode; DWORD flag; UINT i; @@ -692,21 +695,12 @@ static void texture2d_preload(struct wined3d_texture *texture, enum WINED3DSRGB return; } - if (!device->isInDraw) - { - /* No danger of recursive calls, context_acquire() sets isInDraw to TRUE - * when loading offscreen render targets into the texture. */ - context = context_acquire(device, NULL); - } - /* Reload the surfaces if the texture is marked dirty. */ for (i = 0; i < sub_count; ++i) { surface_load(surface_from_resource(texture->sub_resources[i]), srgb_mode); } texture->flags |= flag; - - if (context) context_release(context); } static void texture2d_sub_resource_add_dirty_region(struct wined3d_resource *sub_resource, @@ -1050,12 +1044,12 @@ static HRESULT texture3d_bind(struct wined3d_texture *texture, return wined3d_texture_bind(texture, context, srgb, &dummy); } -static void texture3d_preload(struct wined3d_texture *texture, enum WINED3DSRGB srgb) +/* Context activation is done by the caller. */ +static void texture3d_preload(struct wined3d_texture *texture, + struct wined3d_context *context, enum WINED3DSRGB srgb) { UINT sub_count = texture->level_count * texture->layer_count; - struct wined3d_device *device = texture->resource.device; - const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; - struct wined3d_context *context = NULL; + const struct wined3d_gl_info *gl_info = context->gl_info; BOOL srgb_mode; DWORD flag; UINT i; @@ -1074,16 +1068,12 @@ static void texture3d_preload(struct wined3d_texture *texture, enum WINED3DSRGB return; } - context = context_acquire(device, NULL); - /* Reload the surfaces if the texture is marked dirty. */ for (i = 0; i < sub_count; ++i) { wined3d_volume_load(volume_from_resource(texture->sub_resources[i]), context, srgb_mode); } texture->flags |= flag; - - context_release(context); } static void texture3d_sub_resource_add_dirty_region(struct wined3d_resource *sub_resource, diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 07e8c9b74ec..125556e2c19 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1883,13 +1883,12 @@ struct wined3d_device UINT instance_count; WORD vertexBlendUsed : 1; /* To avoid needless setting of the blend matrices */ - WORD isInDraw : 1; WORD bCursorVisible : 1; WORD d3d_initialized : 1; WORD inScene : 1; /* A flag to check for proper BeginScene / EndScene call pairs */ WORD softwareVertexProcessing : 1; /* process vertex shaders using software or hardware */ WORD filter_messages : 1; - WORD padding : 9; + WORD padding : 10; BYTE fixed_function_usage_map; /* MAX_TEXTURES, 8 */ @@ -1952,7 +1951,7 @@ void device_context_remove(struct wined3d_device *device, struct wined3d_context HRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d, UINT adapter_idx, enum wined3d_device_type device_type, HWND focus_window, DWORD flags, BYTE surface_alignment, struct wined3d_device_parent *device_parent) DECLSPEC_HIDDEN; -void device_preload_textures(const struct wined3d_device *device) DECLSPEC_HIDDEN; +void device_preload_textures(const struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN; LRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL unicode, UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc) DECLSPEC_HIDDEN; void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN; @@ -2064,7 +2063,8 @@ struct wined3d_texture_ops { HRESULT (*texture_bind)(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb); - void (*texture_preload)(struct wined3d_texture *texture, enum WINED3DSRGB srgb); + void (*texture_preload)(struct wined3d_texture *texture, struct wined3d_context *context, + enum WINED3DSRGB srgb); void (*texture_sub_resource_add_dirty_region)(struct wined3d_resource *sub_resource, const struct wined3d_box *dirty_region); void (*texture_sub_resource_cleanup)(struct wined3d_resource *sub_resource);