Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/wined3d/stateblock.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index db0019adbf4..6d747f97311 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -852,9 +852,9 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock, }
map = stateblock->changed.streamSource; - for (i = 0; map; map >>= 1, ++i) + while (map) { - if (!(map & 1)) continue; + i = wined3d_bit_scan(&map);
if (stateblock->stateblock_state.streams[i].stride != state->streams[i].stride || stateblock->stateblock_state.streams[i].offset != state->streams[i].offset @@ -877,9 +877,9 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock, }
map = stateblock->changed.streamFreq; - for (i = 0; map; map >>= 1, ++i) + while (map) { - if (!(map & 1)) continue; + i = wined3d_bit_scan(&map);
if (stateblock->stateblock_state.streams[i].frequency != state->streams[i].frequency || stateblock->stateblock_state.streams[i].flags != state->streams[i].flags) @@ -893,9 +893,9 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock, }
map = stateblock->changed.clipplane; - for (i = 0; map; map >>= 1, ++i) + while (map) { - if (!(map & 1)) continue; + i = wined3d_bit_scan(&map);
if (memcmp(&stateblock->stateblock_state.clip_planes[i], &state->clip_planes[i], sizeof(state->clip_planes[i]))) { @@ -929,9 +929,9 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock,
/* Samplers */ map = stateblock->changed.textures; - for (i = 0; map; map >>= 1, ++i) + while (map) { - if (!(map & 1)) continue; + i = wined3d_bit_scan(&map);
TRACE("Updating texture %u to %p (was %p).\n", i, state->textures[i], stateblock->stateblock_state.textures[i]);
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/wined3d/stateblock.c | 81 +++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 41 deletions(-)
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 6d747f97311..b6c3169c4c6 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -985,6 +985,8 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock,
if (stateblock->changed.vertexShader) wined3d_stateblock_set_vertex_shader(device_state, state->vs); + if (stateblock->changed.pixelShader) + wined3d_stateblock_set_pixel_shader(device_state, state->ps);
for (start = 0; ; start = range.offset + range.size) { @@ -1007,23 +1009,6 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, wined3d_stateblock_set_vs_consts_b(device_state, range.offset, range.size, &state->vs_consts_b[range.offset]); }
- if (stateblock->changed.lights) - { - for (i = 0; i < ARRAY_SIZE(state->light_state->light_map); ++i) - { - const struct wined3d_light_info *light; - - LIST_FOR_EACH_ENTRY(light, &state->light_state->light_map[i], struct wined3d_light_info, entry) - { - wined3d_stateblock_set_light(device_state, light->OriginalIndex, &light->OriginalParms); - wined3d_stateblock_set_light_enable(device_state, light->OriginalIndex, light->glIndex != -1); - } - } - } - - if (stateblock->changed.pixelShader) - wined3d_stateblock_set_pixel_shader(device_state, state->ps); - for (start = 0; ; start = range.offset + range.size) { if (!wined3d_bitmap_get_range(stateblock->changed.ps_consts_f, WINED3D_MAX_PS_CONSTS_F, start, &range)) @@ -1045,6 +1030,30 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, wined3d_stateblock_set_ps_consts_b(device_state, range.offset, range.size, &state->ps_consts_b[range.offset]); }
+ if (stateblock->changed.transforms) + { + for (i = 0; i < stateblock->num_contained_transform_states; ++i) + { + enum wined3d_transform_state transform = stateblock->contained_transform_states[i]; + + wined3d_stateblock_set_transform(device_state, transform, &state->transforms[transform]); + } + } + + if (stateblock->changed.lights) + { + for (i = 0; i < ARRAY_SIZE(state->light_state->light_map); ++i) + { + const struct wined3d_light_info *light; + + LIST_FOR_EACH_ENTRY(light, &state->light_state->light_map[i], struct wined3d_light_info, entry) + { + wined3d_stateblock_set_light(device_state, light->OriginalIndex, &light->OriginalParms); + wined3d_stateblock_set_light_enable(device_state, light->OriginalIndex, light->glIndex != -1); + } + } + } + if (stateblock->changed.alpha_to_coverage) { device_state->stateblock_state.alpha_to_coverage = state->alpha_to_coverage; @@ -1079,16 +1088,6 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, state->sampler_states[stage][sampler_state]); }
- if (stateblock->changed.transforms) - { - for (i = 0; i < stateblock->num_contained_transform_states; ++i) - { - enum wined3d_transform_state transform = stateblock->contained_transform_states[i]; - - wined3d_stateblock_set_transform(device_state, transform, &state->transforms[transform]); - } - } - if (stateblock->changed.indices) { wined3d_stateblock_set_index_buffer(device_state, state->index_buffer, state->index_format); @@ -1108,33 +1107,33 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, wined3d_stateblock_set_scissor_rect(device_state, &state->scissor_rect);
map = stateblock->changed.streamSource; - for (i = 0; map; map >>= 1, ++i) + while (map) { - if (map & 1) - wined3d_stateblock_set_stream_source(device_state, i, state->streams[i].buffer, - state->streams[i].offset, state->streams[i].stride); + i = wined3d_bit_scan(&map); + wined3d_stateblock_set_stream_source(device_state, i, state->streams[i].buffer, + state->streams[i].offset, state->streams[i].stride); }
map = stateblock->changed.streamFreq; - for (i = 0; map; map >>= 1, ++i) + while (map) { - if (map & 1) - wined3d_stateblock_set_stream_source_freq(device_state, i, - state->streams[i].frequency | state->streams[i].flags); + i = wined3d_bit_scan(&map); + wined3d_stateblock_set_stream_source_freq(device_state, i, + state->streams[i].frequency | state->streams[i].flags); }
map = stateblock->changed.textures; - for (i = 0; map; map >>= 1, ++i) + while (map) { - if (map & 1) - wined3d_stateblock_set_texture(device_state, i, state->textures[i]); + i = wined3d_bit_scan(&map); + wined3d_stateblock_set_texture(device_state, i, state->textures[i]); }
map = stateblock->changed.clipplane; - for (i = 0; map; map >>= 1, ++i) + while (map) { - if (map & 1) - wined3d_stateblock_set_clip_plane(device_state, i, &state->clip_planes[i]); + i = wined3d_bit_scan(&map); + wined3d_stateblock_set_clip_plane(device_state, i, &state->clip_planes[i]); }
TRACE("Applied stateblock %p.\n", stateblock);
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/ddraw/ddraw.c | 1 + dlls/ddraw/ddraw_private.h | 2 ++ dlls/ddraw/device.c | 23 ++++++++++++----------- dlls/ddraw/vertexbuffer.c | 4 ++-- dlls/ddraw/viewport.c | 2 +- 5 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c index de457511591..050f625f715 100644 --- a/dlls/ddraw/ddraw.c +++ b/dlls/ddraw/ddraw.c @@ -5048,6 +5048,7 @@ HRESULT ddraw_init(struct ddraw *ddraw, DWORD flags, enum wined3d_device_type de wined3d_decref(ddraw->wined3d); return hr; } + ddraw->stateblock_state = wined3d_stateblock_get_state(ddraw->state);
return DD_OK; } diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h index 515a622e37a..f4fe970a612 100644 --- a/dlls/ddraw/ddraw_private.h +++ b/dlls/ddraw/ddraw_private.h @@ -132,6 +132,7 @@ struct ddraw UINT numConvertedDecls, declArraySize;
struct wined3d_stateblock *state; + const struct wined3d_stateblock_state *stateblock_state; };
#define DDRAW_WINDOW_CLASS_NAME "DirectDrawDeviceWnd" @@ -356,6 +357,7 @@ struct d3d_device struct wined3d_vec4 user_clip_planes[D3DMAXUSERCLIPPLANES];
struct wined3d_stateblock *recording, *state, *update_state; + const struct wined3d_stateblock_state *stateblock_state; };
HRESULT d3d_device_create(struct ddraw *ddraw, struct ddraw_surface *target, IUnknown *rt_iface, diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index 3c0ae71196d..048ba7fba66 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -2302,7 +2302,7 @@ static HRESULT d3d_device7_GetRenderState(IDirect3DDevice7 *iface, return DDERR_INVALIDPARAMS;
wined3d_mutex_lock(); - device_state = wined3d_stateblock_get_state(device->state); + device_state = device->stateblock_state; switch (state) { case D3DRENDERSTATE_TEXTUREMAG: @@ -2451,7 +2451,7 @@ static HRESULT WINAPI d3d_device3_GetRenderState(IDirect3DDevice3 *iface, *value = 0;
wined3d_mutex_lock(); - if ((tex = wined3d_stateblock_get_state(device->state)->textures[0])) + if ((tex = device->stateblock_state->textures[0])) { /* The parent of the texture is the IDirectDrawSurface7 * interface of the ddraw surface. */ @@ -2673,7 +2673,7 @@ static void fixup_texture_alpha_op(struct d3d_device *device) if (!(device->legacyTextureBlending && device->texture_map_blend == D3DTBLEND_MODULATE)) return;
- if ((tex = wined3d_stateblock_get_state(device->state)->textures[0])) + if ((tex = device->stateblock_state->textures[0])) { struct wined3d_resource_desc desc;
@@ -3233,7 +3233,7 @@ static HRESULT d3d_device7_GetTransform(IDirect3DDevice7 *iface,
/* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ wined3d_mutex_lock(); - memcpy(matrix, &wined3d_stateblock_get_state(device->state)->transforms[wined3d_state], sizeof(*matrix)); + memcpy(matrix, &device->stateblock_state->transforms[wined3d_state], sizeof(*matrix)); wined3d_mutex_unlock();
return D3D_OK; @@ -3886,7 +3886,7 @@ static HRESULT WINAPI d3d_device7_GetClipStatus(IDirect3DDevice7 *iface, D3DCLIP
FIXME("iface %p, clip_status %p stub.\n", iface, clip_status);
- vp = wined3d_stateblock_get_state(device->state)->viewport; + vp = device->stateblock_state->viewport; clip_status->minx = vp.x; clip_status->maxx = vp.x + vp.width; clip_status->miny = vp.y; @@ -4566,7 +4566,7 @@ static void prepare_clip_space_planes(struct d3d_device *device, struct wined3d_ /* We want the wined3d matrices since those include the legacy viewport * transformation. */ wined3d_mutex_lock(); - state = wined3d_stateblock_get_state(device->state); + state = device->stateblock_state; multiply_matrix(&m, &state->transforms[WINED3D_TS_VIEW], &state->transforms[WINED3D_TS_WORLD]); multiply_matrix(&m, &state->transforms[WINED3D_TS_PROJECTION], &m); wined3d_mutex_unlock(); @@ -4725,7 +4725,7 @@ static HRESULT d3d_device7_GetTexture(IDirect3DDevice7 *iface, }
wined3d_mutex_lock(); - if (!(wined3d_texture = wined3d_stateblock_get_state(device->state)->textures[stage])) + if (!(wined3d_texture = device->stateblock_state->textures[stage])) { *texture = NULL; wined3d_mutex_unlock(); @@ -4936,7 +4936,7 @@ static HRESULT d3d_device7_GetTextureStageState(IDirect3DDevice7 *iface,
wined3d_mutex_lock();
- device_state = wined3d_stateblock_get_state(device->state); + device_state = device->stateblock_state;
if (l->sampler_state) { @@ -5391,7 +5391,7 @@ static HRESULT d3d_device7_GetViewport(IDirect3DDevice7 *iface, D3DVIEWPORT7 *vi return DDERR_INVALIDPARAMS;
wined3d_mutex_lock(); - wined3d_viewport = wined3d_stateblock_get_state(device->state)->viewport; + wined3d_viewport = device->stateblock_state->viewport; wined3d_mutex_unlock();
viewport->dwX = wined3d_viewport.x; @@ -5493,7 +5493,7 @@ static HRESULT d3d_device7_GetMaterial(IDirect3DDevice7 *iface, D3DMATERIAL7 *ma
wined3d_mutex_lock(); /* Note: D3DMATERIAL7 is compatible with struct wined3d_material. */ - memcpy(material, &wined3d_stateblock_get_state(device->state)->material, sizeof(*material)); + memcpy(material, &device->stateblock_state->material, sizeof(*material)); wined3d_mutex_unlock();
return D3D_OK; @@ -6577,7 +6577,7 @@ static HRESULT d3d_device7_GetClipPlane(IDirect3DDevice7 *iface, DWORD idx, D3DV
wined3d_mutex_lock(); if (idx < WINED3D_MAX_CLIP_DISTANCES) - memcpy(plane, &wined3d_stateblock_get_state(device->state)->clip_planes[idx], sizeof(struct wined3d_vec4)); + memcpy(plane, &device->stateblock_state->clip_planes[idx], sizeof(struct wined3d_vec4)); else { WARN("Clip plane %u is not supported.\n", idx); @@ -6997,6 +6997,7 @@ static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw, device->wined3d_device = ddraw->wined3d_device; wined3d_device_incref(ddraw->wined3d_device); device->update_state = device->state = ddraw->state; + device->stateblock_state = ddraw->stateblock_state; wined3d_stateblock_incref(ddraw->state);
/* Render to the back buffer */ diff --git a/dlls/ddraw/vertexbuffer.c b/dlls/ddraw/vertexbuffer.c index afd798cb9fe..584d9d162b9 100644 --- a/dlls/ddraw/vertexbuffer.c +++ b/dlls/ddraw/vertexbuffer.c @@ -85,7 +85,7 @@ static ULONG WINAPI d3d_vertex_buffer7_Release(IDirect3DVertexBuffer7 *iface) * stream source in wined3d and they should get unset there before * they are destroyed. */ wined3d_mutex_lock(); - if (wined3d_stateblock_get_state(buffer->ddraw->state)->streams[0].buffer == buffer->wined3d_buffer) + if (buffer->ddraw->stateblock_state->streams[0].buffer == buffer->wined3d_buffer) wined3d_stateblock_set_stream_source(buffer->ddraw->state, 0, NULL, 0, 0);
wined3d_vertex_declaration_decref(buffer->wined3d_declaration); @@ -275,7 +275,7 @@ static HRESULT WINAPI d3d_vertex_buffer7_ProcessVertices(IDirect3DVertexBuffer7
wined3d_mutex_lock();
- state = wined3d_stateblock_get_state(device_impl->state); + state = device_impl->stateblock_state;
/* WineD3D doesn't know d3d7 vertex operation, it uses * render states instead. Set the render states according to diff --git a/dlls/ddraw/viewport.c b/dlls/ddraw/viewport.c index ac56928e4f4..4a415c4daf1 100644 --- a/dlls/ddraw/viewport.c +++ b/dlls/ddraw/viewport.c @@ -520,7 +520,7 @@ static HRESULT WINAPI d3d_viewport_TransformVertices(IDirect3DViewport3 *iface, if (activate) viewport_activate(viewport, TRUE);
- state = wined3d_stateblock_get_state(device->state); + state = device->stateblock_state; multiply_matrix(&mat, &state->transforms[WINED3D_TS_VIEW], &state->transforms[WINED3D_TS_WORLD_MATRIX(0)]); multiply_matrix(&mat, &state->transforms[WINED3D_TS_PROJECTION], &mat);
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/d3d9/texture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/d3d9/texture.c b/dlls/d3d9/texture.c index 0d36c02aaa6..9be9d450ba0 100644 --- a/dlls/d3d9/texture.c +++ b/dlls/d3d9/texture.c @@ -543,7 +543,7 @@ static ULONG WINAPI d3d9_texture_cube_AddRef(IDirect3DCubeTexture9 *iface) wined3d_mutex_lock(); LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d9_surface, rtv_entry) { - wined3d_rendertarget_view_decref(surface->wined3d_rtv); + wined3d_rendertarget_view_incref(surface->wined3d_rtv); } wined3d_texture_incref(texture->wined3d_texture); wined3d_mutex_unlock();
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/wined3d/context.c | 2 +- dlls/wined3d/device.c | 2 +- dlls/wined3d/shader.c | 2 +- dlls/wined3d/state.c | 2 +- dlls/wined3d/utils.c | 2 +- dlls/wined3d/wined3d_private.h | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index d9e3dfaa505..0bfb714f0c8 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -3414,7 +3414,7 @@ BOOL wined3d_context_gl_apply_clear_state(struct wined3d_context_gl *context_gl, gl_info->gl_ops.gl.p_glEnable(GL_SCISSOR_TEST); if (rt_count && gl_info->supported[ARB_FRAMEBUFFER_SRGB]) { - if (needs_srgb_write(&context_gl->c, state, fb)) + if (needs_srgb_write(context_gl->c.d3d_info, state, fb)) gl_info->gl_ops.gl.p_glEnable(GL_FRAMEBUFFER_SRGB); else gl_info->gl_ops.gl.p_glDisable(GL_FRAMEBUFFER_SRGB); diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 42d645d201e..0a0c4c526c8 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -426,7 +426,7 @@ void device_clear_render_targets(struct wined3d_device *device, UINT rt_count, c wined3d_texture_invalidate_location(texture, rtv->sub_resource_idx, ~rtv->resource->draw_binding); }
- if (!gl_info->supported[ARB_FRAMEBUFFER_SRGB] && needs_srgb_write(context, state, fb)) + if (!gl_info->supported[ARB_FRAMEBUFFER_SRGB] && needs_srgb_write(context->d3d_info, state, fb)) { if (rt_count > 1) WARN("Clearing multiple sRGB render targets without GL_ARB_framebuffer_sRGB " diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c index d9ef1a96e20..f9fdaa33701 100644 --- a/dlls/wined3d/shader.c +++ b/dlls/wined3d/shader.c @@ -3904,7 +3904,7 @@ void find_ps_compile_args(const struct wined3d_state *state, const struct wined3 unsigned int i;
memset(args, 0, sizeof(*args)); /* FIXME: Make sure all bits are set. */ - if (!d3d_info->srgb_write_control && needs_srgb_write(context, state, state->fb)) + if (!d3d_info->srgb_write_control && needs_srgb_write(d3d_info, state, state->fb)) { static unsigned int warned = 0;
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 62893179368..b9a1be15e96 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -4447,7 +4447,7 @@ void state_srgbwrite(struct wined3d_context *context, const struct wined3d_state
TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
- if (needs_srgb_write(context, state, state->fb)) + if (needs_srgb_write(context->d3d_info, state, state->fb)) gl_info->gl_ops.gl.p_glEnable(GL_FRAMEBUFFER_SRGB); else gl_info->gl_ops.gl.p_glDisable(GL_FRAMEBUFFER_SRGB); diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 54866da533c..f3ed3b3cec5 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -6236,7 +6236,7 @@ void gen_ffp_frag_op(const struct wined3d_context *context, const struct wined3d break; } } - settings->sRGB_write = !d3d_info->srgb_write_control && needs_srgb_write(context, state, state->fb); + settings->sRGB_write = !d3d_info->srgb_write_control && needs_srgb_write(d3d_info, state, state->fb); if (d3d_info->vs_clipping || !use_vs(state) || !state->render_states[WINED3D_RS_CLIPPING] || !state->render_states[WINED3D_RS_CLIPPLANEENABLE]) { diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 9240b0e455e..08fcf9d8c2b 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -5115,10 +5115,10 @@ static inline BOOL needs_separate_srgb_gl_texture(const struct wined3d_context * return FALSE; }
-static inline BOOL needs_srgb_write(const struct wined3d_context *context, +static inline BOOL needs_srgb_write(const struct wined3d_d3d_info *d3d_info, const struct wined3d_state *state, const struct wined3d_fb_state *fb) { - return (!(context->d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL) + return (!(d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL) || state->render_states[WINED3D_RS_SRGBWRITEENABLE]) && fb->render_targets[0] && fb->render_targets[0]->format_flags & WINED3DFMT_FLAG_SRGB_WRITE; }
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com