Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/wined3d/device.c | 108 ++++++++++++++++++++++++++++++++++++++ dlls/wined3d/wined3d.spec | 1 + include/wine/wined3d.h | 2 + 3 files changed, 111 insertions(+)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 51f74ca1f64..20935268fc4 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -1950,6 +1950,114 @@ void CDECL wined3d_device_get_scissor_rects(const struct wined3d_device *device, *rect_count = state->scissor_rect_count; }
+void CDECL wined3d_device_swap_state(struct wined3d_device *device, + struct wined3d_state *new_state, struct wined3d_state **old_state) +{ + struct wined3d_state *state = device->state; + unsigned int i, j; + + TRACE("device %p, new_state %p, old_state %p.\n", device, new_state, old_state); + + device->state = new_state; + + for (i = 0; i < WINED3D_MAX_RENDER_TARGETS; ++i) + wined3d_cs_emit_set_rendertarget_view(device->cs, i, new_state->fb.render_targets[i]); + + wined3d_cs_emit_set_depth_stencil_view(device->cs, new_state->fb.depth_stencil); + wined3d_cs_emit_set_vertex_declaration(device->cs, new_state->vertex_declaration); + + for (i = 0; i < WINED3D_MAX_STREAM_OUTPUT_BUFFERS; ++i) + wined3d_cs_emit_set_stream_output(device->cs, i, new_state->stream_output[i].buffer, + new_state->stream_output[i].offset); + + for (i = 0; i < WINED3D_MAX_STREAMS; ++i) + wined3d_cs_emit_set_stream_source(device->cs, i, new_state->streams[i].buffer, + new_state->streams[i].offset, new_state->streams[i].stride); + + wined3d_cs_emit_set_index_buffer(device->cs, new_state->index_buffer, + new_state->index_format, new_state->index_offset); + + wined3d_cs_emit_set_predication(device->cs, new_state->predicate, + new_state->predicate_value); + + for (i = 0; i < WINED3D_SHADER_TYPE_COUNT; ++i) + { + wined3d_cs_emit_set_shader(device->cs, i, new_state->shader[i]); + for (j = 0; j < MAX_CONSTANT_BUFFERS; ++j) + wined3d_cs_emit_set_constant_buffer(device->cs, i, j, new_state->cb[i][j]); + for (j = 0; j < MAX_SAMPLER_OBJECTS; ++j) + wined3d_cs_emit_set_sampler(device->cs, i, j, new_state->sampler[i][j]); + for (j = 0; j < MAX_SHADER_RESOURCE_VIEWS; ++j) + wined3d_cs_emit_set_shader_resource_view(device->cs, i, j, + new_state->shader_resource_view[i][j]); + } + + for (i = 0; i < WINED3D_PIPELINE_COUNT; ++i) + for (j = 0; j < MAX_UNORDERED_ACCESS_VIEWS; ++j) + wined3d_cs_emit_set_unordered_access_view(device->cs, i, j, + new_state->unordered_access_view[i][j], ~0); + + wined3d_cs_push_constants(device->cs, WINED3D_PUSH_CONSTANTS_VS_F, 0, + WINED3D_MAX_VS_CONSTS_F, new_state->vs_consts_f); + wined3d_cs_push_constants(device->cs, WINED3D_PUSH_CONSTANTS_VS_I, 0, + WINED3D_MAX_CONSTS_I, new_state->vs_consts_i); + wined3d_cs_push_constants(device->cs, WINED3D_PUSH_CONSTANTS_VS_B, 0, + WINED3D_MAX_CONSTS_B, new_state->vs_consts_b); + + wined3d_cs_push_constants(device->cs, WINED3D_PUSH_CONSTANTS_PS_F, 0, + WINED3D_MAX_PS_CONSTS_F, new_state->ps_consts_f); + wined3d_cs_push_constants(device->cs, WINED3D_PUSH_CONSTANTS_PS_I, 0, + WINED3D_MAX_CONSTS_I, new_state->ps_consts_i); + wined3d_cs_push_constants(device->cs, WINED3D_PUSH_CONSTANTS_PS_B, 0, + WINED3D_MAX_CONSTS_B, new_state->ps_consts_b); + + for (i = 0; i < WINED3D_MAX_COMBINED_SAMPLERS; ++i) + { + wined3d_cs_emit_set_texture(device->cs, i, new_state->textures[i]); + for (j = 0; j < WINED3D_HIGHEST_SAMPLER_STATE + 1; ++j) + wined3d_cs_emit_set_sampler_state(device->cs, i, j, new_state->sampler_states[i][j]); + } + + for (i = 0; i < WINED3D_MAX_TEXTURES; ++i) + for (j = 0; j < WINED3D_HIGHEST_TEXTURE_STATE + 1; ++j) + wined3d_cs_emit_set_texture_state(device->cs, i, j, new_state->texture_states[i][j]); + + for (i = 0; i < WINED3D_HIGHEST_TRANSFORM_STATE + 1; ++i) + wined3d_cs_emit_set_transform(device->cs, i, new_state->transforms + i); + + for (i = 0; i < WINED3D_MAX_CLIP_DISTANCES; ++i) + wined3d_cs_emit_set_clip_plane(device->cs, i, new_state->clip_planes + i); + + wined3d_cs_emit_set_material(device->cs, &new_state->material); + + wined3d_cs_emit_set_viewports(device->cs, new_state->viewport_count, new_state->viewports); + wined3d_cs_emit_set_scissor_rects(device->cs, new_state->scissor_rect_count, + new_state->scissor_rects); + + for (i = 0; i < LIGHTMAP_SIZE; ++i) + { + const struct wined3d_light_info *light; + + LIST_FOR_EACH_ENTRY(light, &new_state->light_state.light_map[i], struct wined3d_light_info, entry) + { + wined3d_device_set_light(device, light->OriginalIndex, &light->OriginalParms); + wined3d_cs_emit_set_light_enable(device->cs, light->OriginalIndex, light->glIndex != -1); + } + } + + for (i = 0; i < WINEHIGHEST_RENDER_STATE + 1; ++i) + wined3d_cs_emit_set_render_state(device->cs, i, new_state->render_states[i]); + + wined3d_cs_emit_set_blend_state(device->cs, new_state->blend_state, &new_state->blend_factor, + new_state->sample_mask); + wined3d_cs_emit_set_depth_stencil_state(device->cs, new_state->depth_stencil_state, + new_state->stencil_ref); + wined3d_cs_emit_set_rasterizer_state(device->cs, new_state->rasterizer_state); + + if (old_state) *old_state = state; + else wined3d_state_destroy(state); +} + void CDECL wined3d_device_set_vertex_declaration(struct wined3d_device *device, struct wined3d_vertex_declaration *declaration) { diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec index 9d305bfc426..d4d33d63256 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -160,6 +160,7 @@ @ cdecl wined3d_device_set_vs_resource_view(ptr long ptr) @ cdecl wined3d_device_set_vs_sampler(ptr long ptr) @ cdecl wined3d_device_show_cursor(ptr long) +@ cdecl wined3d_device_swap_state(ptr ptr ptr) @ cdecl wined3d_device_update_sub_resource(ptr ptr long ptr ptr long long long) @ cdecl wined3d_device_update_texture(ptr ptr ptr) @ cdecl wined3d_device_validate_device(ptr ptr) diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 8de7792e742..b85915612f5 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2538,6 +2538,8 @@ void __cdecl wined3d_device_set_vs_resource_view(struct wined3d_device *device, UINT idx, struct wined3d_shader_resource_view *view); void __cdecl wined3d_device_set_vs_sampler(struct wined3d_device *device, UINT idx, struct wined3d_sampler *sampler); BOOL __cdecl wined3d_device_show_cursor(struct wined3d_device *device, BOOL show); +void __cdecl wined3d_device_swap_state(struct wined3d_device *device, + struct wined3d_state *new_state, struct wined3d_state **old_state); void __cdecl wined3d_device_update_sub_resource(struct wined3d_device *device, struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, const void *data, unsigned int row_pitch, unsigned int depth_pitch, unsigned int flags);