Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- After this patch d3d9.dll's .text section shrinks by 150-200 bytes but, for some reason, .debug_info grows by ~16.5KB. I looked a bit at the generated code and there doesn't seem to be anything surprising. I guess this is okay...
dlls/d3d9/d3d9_private.h | 1 + dlls/d3d9/device.c | 66 +++++++++++++++++++--------------------- dlls/d3d9/stateblock.c | 2 +- 3 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index a9f3f47596c..a21582d6e1e 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -122,6 +122,7 @@ struct d3d9_device struct wined3d_swapchain **implicit_swapchains;
struct wined3d_stateblock *recording, *state, *update_state; + const struct wined3d_stateblock_state *stateblock_state; };
HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wined3d *wined3d, diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index a651a63f02e..8ffe04c94d7 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1042,7 +1042,7 @@ static HRESULT d3d9_device_reset(struct d3d9_device *device,
if (extended) { - const struct wined3d_viewport *current = &wined3d_stateblock_get_state(device->state)->viewport; + const struct wined3d_viewport *current = &device->stateblock_state->viewport; struct wined3d_viewport vp; RECT rect;
@@ -2121,7 +2121,7 @@ static HRESULT WINAPI d3d9_device_GetTransform(IDirect3DDevice9Ex *iface,
/* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ wined3d_mutex_lock(); - memcpy(matrix, &wined3d_stateblock_get_state(device->state)->transforms[state], sizeof(*matrix)); + memcpy(matrix, &device->stateblock_state->transforms[state], sizeof(*matrix)); wined3d_mutex_unlock();
return D3D_OK; @@ -2171,7 +2171,7 @@ static HRESULT WINAPI d3d9_device_GetViewport(IDirect3DDevice9Ex *iface, D3DVIEW TRACE("iface %p, viewport %p.\n", iface, viewport);
wined3d_mutex_lock(); - wined3d_viewport = wined3d_stateblock_get_state(device->state)->viewport; + wined3d_viewport = device->stateblock_state->viewport; wined3d_mutex_unlock();
viewport->X = wined3d_viewport.x; @@ -2206,7 +2206,7 @@ static HRESULT WINAPI d3d9_device_GetMaterial(IDirect3DDevice9Ex *iface, D3DMATE
/* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */ wined3d_mutex_lock(); - 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; @@ -2297,7 +2297,7 @@ static HRESULT WINAPI d3d9_device_GetClipPlane(IDirect3DDevice9Ex *iface, DWORD index = min(index, device->max_user_clip_planes - 1);
wined3d_mutex_lock(); - memcpy(plane, &wined3d_stateblock_get_state(device->state)->clip_planes[index], sizeof(struct wined3d_vec4)); + memcpy(plane, &device->stateblock_state->clip_planes[index], sizeof(struct wined3d_vec4)); wined3d_mutex_unlock();
return D3D_OK; @@ -2305,7 +2305,7 @@ static HRESULT WINAPI d3d9_device_GetClipPlane(IDirect3DDevice9Ex *iface, DWORD
static void resolve_depth_buffer(struct d3d9_device *device) { - const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state); + const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_rendertarget_view *wined3d_dsv; struct wined3d_resource *dst_resource; struct wined3d_texture *dst_texture; @@ -2356,7 +2356,7 @@ static HRESULT WINAPI d3d9_device_GetRenderState(IDirect3DDevice9Ex *iface, TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
wined3d_mutex_lock(); - device_state = wined3d_stateblock_get_state(device->state); + device_state = device->stateblock_state; *value = device_state->rs[state]; wined3d_mutex_unlock();
@@ -2525,7 +2525,7 @@ static HRESULT WINAPI d3d9_device_GetTexture(IDirect3DDevice9Ex *iface, DWORD st }
wined3d_mutex_lock(); - state = wined3d_stateblock_get_state(device->state); + state = device->stateblock_state; if ((wined3d_texture = state->textures[stage])) { texture_impl = wined3d_texture_get_parent(wined3d_texture); @@ -2622,7 +2622,7 @@ static HRESULT WINAPI d3d9_device_GetTextureStageState(IDirect3DDevice9Ex *iface }
wined3d_mutex_lock(); - *value = wined3d_stateblock_get_state(device->state)->texture_states[stage][tss_lookup[state]]; + *value = device->stateblock_state->texture_states[stage][tss_lookup[state]]; wined3d_mutex_unlock();
return D3D_OK; @@ -2667,7 +2667,7 @@ static HRESULT WINAPI d3d9_device_GetSamplerState(IDirect3DDevice9Ex *iface, }
wined3d_mutex_lock(); - device_state = wined3d_stateblock_get_state(device->state); + device_state = device->stateblock_state; *value = device_state->sampler_states[sampler_idx][state]; wined3d_mutex_unlock();
@@ -2758,7 +2758,7 @@ static HRESULT WINAPI d3d9_device_GetScissorRect(IDirect3DDevice9Ex *iface, RECT TRACE("iface %p, rect %p.\n", iface, rect);
wined3d_mutex_lock(); - *rect = wined3d_stateblock_get_state(device->state)->scissor_rect; + *rect = device->stateblock_state->scissor_rect; wined3d_mutex_unlock();
return D3D_OK; @@ -2822,7 +2822,7 @@ static float WINAPI d3d9_device_GetNPatchMode(IDirect3DDevice9Ex *iface) /* wined3d critical section must be taken by the caller. */ static void d3d9_generate_auto_mipmaps(struct d3d9_device *device) { - const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state); + const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_texture *texture; unsigned int i, map;
@@ -2838,7 +2838,7 @@ static void d3d9_generate_auto_mipmaps(struct d3d9_device *device) static void d3d9_device_upload_sysmem_vertex_buffers(struct d3d9_device *device, int base_vertex, unsigned int start_vertex, unsigned int vertex_count) { - const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state); + const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_vertex_declaration *wined3d_decl; struct wined3d_box box = {0, 0, 0, 1, 0, 1}; const struct wined3d_stream_state *stream; @@ -2884,7 +2884,7 @@ static void d3d9_device_upload_sysmem_vertex_buffers(struct d3d9_device *device, static void d3d9_device_upload_sysmem_index_buffer(struct d3d9_device *device, unsigned int start_idx, unsigned int idx_count) { - const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state); + const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_box box = {0, 0, 0, 1, 0, 1}; struct wined3d_resource *dst_resource; struct d3d9_indexbuffer *d3d9_buffer; @@ -3250,7 +3250,7 @@ static HRESULT WINAPI d3d9_device_ProcessVertices(IDirect3DDevice9Ex *iface, iface, src_start_idx, dst_idx, vertex_count, dst_buffer, declaration, flags);
wined3d_mutex_lock(); - state = wined3d_stateblock_get_state(device->state); + state = device->stateblock_state;
/* Note that an alternative approach would be to simply create these * buffers with WINED3D_RESOURCE_ACCESS_MAP_R and update them here like we @@ -3341,7 +3341,7 @@ static HRESULT WINAPI d3d9_device_GetVertexDeclaration(IDirect3DDevice9Ex *iface if (!declaration) return D3DERR_INVALIDCALL;
wined3d_mutex_lock(); - if ((wined3d_declaration = wined3d_stateblock_get_state(device->state)->vertex_declaration)) + if ((wined3d_declaration = device->stateblock_state->vertex_declaration)) { declaration_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration); *declaration = &declaration_impl->IDirect3DVertexDeclaration9_iface; @@ -3461,7 +3461,7 @@ static HRESULT WINAPI d3d9_device_GetFVF(IDirect3DDevice9Ex *iface, DWORD *fvf) TRACE("iface %p, fvf %p.\n", iface, fvf);
wined3d_mutex_lock(); - if ((wined3d_declaration = wined3d_stateblock_get_state(device->state)->vertex_declaration)) + if ((wined3d_declaration = device->stateblock_state->vertex_declaration)) { d3d9_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration); *fvf = d3d9_declaration->fvf; @@ -3527,7 +3527,7 @@ static HRESULT WINAPI d3d9_device_GetVertexShader(IDirect3DDevice9Ex *iface, IDi TRACE("iface %p, shader %p.\n", iface, shader);
wined3d_mutex_lock(); - if ((wined3d_shader = wined3d_stateblock_get_state(device->state)->vs)) + if ((wined3d_shader = device->stateblock_state->vs)) { shader_impl = wined3d_shader_get_parent(wined3d_shader); *shader = &shader_impl->IDirect3DVertexShader9_iface; @@ -3586,7 +3586,7 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex *i }
wined3d_mutex_lock(); - src = wined3d_stateblock_get_state(device->state)->vs_consts_f; + src = device->stateblock_state->vs_consts_f; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -3623,7 +3623,7 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex *i count = WINED3D_MAX_CONSTS_I - start_idx;
wined3d_mutex_lock(); - src = wined3d_stateblock_get_state(device->state)->vs_consts_i; + src = device->stateblock_state->vs_consts_i; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -3658,7 +3658,7 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex *i count = WINED3D_MAX_CONSTS_B - start_idx;
wined3d_mutex_lock(); - memcpy(constants, &wined3d_stateblock_get_state(device->state)->vs_consts_b[start_idx], count * sizeof(*constants)); + memcpy(constants, &device->stateblock_state->vs_consts_b[start_idx], count * sizeof(*constants)); wined3d_mutex_unlock();
return D3D_OK; @@ -3669,14 +3669,13 @@ static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface, { struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); struct d3d9_vertexbuffer *buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer9(buffer); - const struct wined3d_stateblock_state *state; struct wined3d_buffer *wined3d_buffer; HRESULT hr;
TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n", iface, stream_idx, buffer, offset, stride);
- if (stream_idx >= ARRAY_SIZE(state->streams)) + if (stream_idx >= ARRAY_SIZE(device->stateblock_state->streams)) { WARN("Stream index %u out of range.\n", stream_idx); return WINED3DERR_INVALIDCALL; @@ -3685,9 +3684,8 @@ static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface, wined3d_mutex_lock(); if (!buffer_impl) { - const struct wined3d_stream_state *stream; - state = wined3d_stateblock_get_state(device->state); - stream = &state->streams[stream_idx]; + const struct wined3d_stream_state *stream = &device->stateblock_state->streams[stream_idx]; + offset = stream->offset; stride = stream->stride; wined3d_buffer = NULL; @@ -3736,8 +3734,7 @@ static HRESULT WINAPI d3d9_device_GetStreamSource(IDirect3DDevice9Ex *iface, }
wined3d_mutex_lock(); - state = wined3d_stateblock_get_state(device->state); - stream = &state->streams[stream_idx]; + stream = &device->stateblock_state->streams[stream_idx]; if (stream->buffer) { buffer_impl = wined3d_buffer_get_parent(stream->buffer); @@ -3776,7 +3773,7 @@ static HRESULT WINAPI d3d9_device_GetStreamSourceFreq(IDirect3DDevice9Ex *iface, TRACE("iface %p, stream_idx %u, freq %p.\n", iface, stream_idx, freq);
wined3d_mutex_lock(); - stream = &wined3d_stateblock_get_state(device->state)->streams[stream_idx]; + stream = &device->stateblock_state->streams[stream_idx]; *freq = stream->flags | stream->frequency; wined3d_mutex_unlock();
@@ -3819,7 +3816,7 @@ static HRESULT WINAPI d3d9_device_GetIndices(IDirect3DDevice9Ex *iface, IDirect3 return D3DERR_INVALIDCALL;
wined3d_mutex_lock(); - if ((wined3d_buffer = wined3d_stateblock_get_state(device->state)->index_buffer)) + if ((wined3d_buffer = device->stateblock_state->index_buffer)) { buffer_impl = wined3d_buffer_get_parent(wined3d_buffer); *buffer = &buffer_impl->IDirect3DIndexBuffer9_iface; @@ -3889,7 +3886,7 @@ static HRESULT WINAPI d3d9_device_GetPixelShader(IDirect3DDevice9Ex *iface, IDir if (!shader) return D3DERR_INVALIDCALL;
wined3d_mutex_lock(); - if ((wined3d_shader = wined3d_stateblock_get_state(device->state)->ps)) + if ((wined3d_shader = device->stateblock_state->ps)) { shader_impl = wined3d_shader_get_parent(wined3d_shader); *shader = &shader_impl->IDirect3DPixelShader9_iface; @@ -3934,7 +3931,7 @@ static HRESULT WINAPI d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex *if return WINED3DERR_INVALIDCALL;
wined3d_mutex_lock(); - src = wined3d_stateblock_get_state(device->state)->ps_consts_f; + src = device->stateblock_state->ps_consts_f; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -3971,7 +3968,7 @@ static HRESULT WINAPI d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex *if count = WINED3D_MAX_CONSTS_I - start_idx;
wined3d_mutex_lock(); - src = wined3d_stateblock_get_state(device->state)->ps_consts_i; + src = device->stateblock_state->ps_consts_i; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -4006,7 +4003,7 @@ static HRESULT WINAPI d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex *if count = WINED3D_MAX_CONSTS_I - start_idx;
wined3d_mutex_lock(); - memcpy(constants, &wined3d_stateblock_get_state(device->state)->ps_consts_b[start_idx], count * sizeof(*constants)); + memcpy(constants, &device->stateblock_state->ps_consts_b[start_idx], count * sizeof(*constants)); wined3d_mutex_unlock();
return D3D_OK; @@ -4641,6 +4638,7 @@ HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wine wined3d_mutex_unlock(); return hr; } + device->stateblock_state = wined3d_stateblock_get_state(device->state); device->update_state = device->state;
if (flags & D3DCREATE_MULTITHREADED) diff --git a/dlls/d3d9/stateblock.c b/dlls/d3d9/stateblock.c index a65fa1cd8d4..a1ce3d5856c 100644 --- a/dlls/d3d9/stateblock.c +++ b/dlls/d3d9/stateblock.c @@ -151,7 +151,7 @@ static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface) device->auto_mipmaps = 0; for (i = 0; i < D3D9_MAX_TEXTURE_UNITS; ++i) { - if ((wined3d_texture = wined3d_stateblock_get_state(device->state)->textures[i]) + if ((wined3d_texture = device->stateblock_state->textures[i]) && (texture = wined3d_texture_get_parent(wined3d_texture)) && texture->usage & D3DUSAGE_AUTOGENMIPMAP) device->auto_mipmaps |= 1u << i;
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/d3d9/stateblock.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/dlls/d3d9/stateblock.c b/dlls/d3d9/stateblock.c index a1ce3d5856c..3c1e3230095 100644 --- a/dlls/d3d9/stateblock.c +++ b/dlls/d3d9/stateblock.c @@ -118,11 +118,9 @@ static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface) struct wined3d_texture *wined3d_texture; struct wined3d_buffer *wined3d_buffer; struct d3d9_vertexbuffer *buffer; - unsigned int i, offset, stride; - enum wined3d_format_id format; struct d3d9_texture *texture; struct d3d9_device *device; - HRESULT hr; + unsigned int i;
TRACE("iface %p.\n", iface);
@@ -138,15 +136,14 @@ static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface) device->sysmem_vb = 0; for (i = 0; i < D3D9_MAX_STREAMS; ++i) { - if (FAILED(hr = wined3d_device_get_stream_source(device->wined3d_device, - i, &wined3d_buffer, &offset, &stride))) + if (!(wined3d_buffer = device->stateblock_state->streams[i].buffer)) continue; - if (!wined3d_buffer || !(buffer = wined3d_buffer_get_parent(wined3d_buffer))) + if (!(buffer = wined3d_buffer_get_parent(wined3d_buffer))) continue; if (buffer->draw_buffer) device->sysmem_vb |= 1u << i; } - device->sysmem_ib = (wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &format, &offset)) + device->sysmem_ib = (wined3d_buffer = device->stateblock_state->index_buffer) && (buffer = wined3d_buffer_get_parent(wined3d_buffer)) && buffer->draw_buffer; device->auto_mipmaps = 0; for (i = 0; i < D3D9_MAX_TEXTURE_UNITS; ++i)
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/d3d8/d3d8_private.h | 1 + dlls/d3d8/device.c | 45 ++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h index e49087fcd5d..f67841b4b13 100644 --- a/dlls/d3d8/d3d8_private.h +++ b/dlls/d3d8/d3d8_private.h @@ -140,6 +140,7 @@ struct d3d8_device struct wined3d_swapchain *implicit_swapchain;
struct wined3d_stateblock *recording, *state, *update_state; + const struct wined3d_stateblock_state *stateblock_state; };
HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wined3d *wined3d, UINT adapter, diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index 2850b93fd1d..45b158314ed 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -1634,7 +1634,7 @@ static HRESULT WINAPI d3d8_device_GetTransform(IDirect3DDevice8 *iface,
/* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ wined3d_mutex_lock(); - memcpy(matrix, &wined3d_stateblock_get_state(device->state)->transforms[state], sizeof(*matrix)); + memcpy(matrix, &device->stateblock_state->transforms[state], sizeof(*matrix)); wined3d_mutex_unlock();
return D3D_OK; @@ -1703,7 +1703,7 @@ static HRESULT WINAPI d3d8_device_GetViewport(IDirect3DDevice8 *iface, D3DVIEWPO TRACE("iface %p, viewport %p.\n", iface, viewport);
wined3d_mutex_lock(); - wined3d_viewport = wined3d_stateblock_get_state(device->state)->viewport; + wined3d_viewport = device->stateblock_state->viewport; wined3d_mutex_unlock();
viewport->X = wined3d_viewport.x; @@ -1738,7 +1738,7 @@ static HRESULT WINAPI d3d8_device_GetMaterial(IDirect3DDevice8 *iface, D3DMATERI
/* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */ wined3d_mutex_lock(); - 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; @@ -1831,7 +1831,7 @@ static HRESULT WINAPI d3d8_device_GetClipPlane(IDirect3DDevice8 *iface, DWORD in }
wined3d_mutex_lock(); - memcpy(plane, &wined3d_stateblock_get_state(device->state)->clip_planes[index], sizeof(struct wined3d_vec4)); + memcpy(plane, &device->stateblock_state->clip_planes[index], sizeof(struct wined3d_vec4)); wined3d_mutex_unlock();
return D3D_OK; @@ -1839,7 +1839,7 @@ static HRESULT WINAPI d3d8_device_GetClipPlane(IDirect3DDevice8 *iface, DWORD in
static void resolve_depth_buffer(struct d3d8_device *device) { - const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state); + const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_rendertarget_view *wined3d_dsv; struct wined3d_resource *dst_resource; struct wined3d_texture *dst_texture; @@ -1892,7 +1892,7 @@ static HRESULT WINAPI d3d8_device_GetRenderState(IDirect3DDevice8 *iface, TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
wined3d_mutex_lock(); - device_state = wined3d_stateblock_get_state(device->state); + device_state = device->stateblock_state; switch (state) { case D3DRS_ZBIAS: @@ -2000,7 +2000,7 @@ static HRESULT WINAPI d3d8_device_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD } wined3d_stateblock_apply(stateblock, device->state); device->sysmem_vb = 0; - state = wined3d_stateblock_get_state(device->state); + state = device->stateblock_state; for (i = 0; i < D3D8_MAX_STREAMS; ++i) { wined3d_buffer = state->streams[i].buffer; @@ -2167,7 +2167,7 @@ static HRESULT WINAPI d3d8_device_GetTexture(IDirect3DDevice8 *iface, DWORD stag }
wined3d_mutex_lock(); - if ((wined3d_texture = wined3d_stateblock_get_state(device->state)->textures[stage])) + if ((wined3d_texture = device->stateblock_state->textures[stage])) { texture_impl = wined3d_texture_get_parent(wined3d_texture); *texture = &texture_impl->IDirect3DBaseTexture8_iface; @@ -2259,7 +2259,7 @@ static HRESULT WINAPI d3d8_device_GetTextureStageState(IDirect3DDevice8 *iface, l = &tss_lookup[state];
wined3d_mutex_lock(); - device_state = wined3d_stateblock_get_state(device->state); + device_state = device->stateblock_state; if (l->sampler_state) *value = device_state->sampler_states[stage][l->u.sampler_state]; else @@ -2356,7 +2356,7 @@ static HRESULT WINAPI d3d8_device_GetCurrentTexturePalette(IDirect3DDevice8 *ifa static void d3d8_device_upload_sysmem_vertex_buffers(struct d3d8_device *device, unsigned int start_vertex, unsigned int vertex_count) { - const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state); + const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_vertex_declaration *wined3d_decl; struct wined3d_box box = {0, 0, 0, 1, 0, 1}; const struct wined3d_stream_state *stream; @@ -2397,7 +2397,7 @@ static void d3d8_device_upload_sysmem_vertex_buffers(struct d3d8_device *device, static void d3d8_device_upload_sysmem_index_buffer(struct d3d8_device *device, unsigned int start_idx, unsigned int idx_count) { - const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state); + const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_box box = {0, 0, 0, 1, 0, 1}; struct wined3d_resource *dst_resource; struct d3d8_indexbuffer *d3d8_buffer; @@ -2459,7 +2459,7 @@ static HRESULT WINAPI d3d8_device_DrawIndexedPrimitive(IDirect3DDevice8 *iface,
index_count = vertex_count_from_primitive_count(primitive_type, primitive_count); wined3d_mutex_lock(); - base_vertex_index = wined3d_stateblock_get_state(device->state)->base_vertex_index; + base_vertex_index = device->stateblock_state->base_vertex_index; d3d8_device_upload_sysmem_vertex_buffers(device, base_vertex_index + min_vertex_idx, vertex_count); d3d8_device_upload_sysmem_index_buffer(device, start_idx, index_count); wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0); @@ -2713,7 +2713,7 @@ static HRESULT WINAPI d3d8_device_ProcessVertices(IDirect3DDevice8 *iface, UINT
wined3d_mutex_lock();
- state = wined3d_stateblock_get_state(device->state); + state = device->stateblock_state;
/* Note that an alternative approach would be to simply create these * buffers with WINED3D_RESOURCE_ACCESS_MAP_R and update them here like we @@ -2914,7 +2914,7 @@ static HRESULT WINAPI d3d8_device_GetVertexShader(IDirect3DDevice8 *iface, DWORD TRACE("iface %p, shader %p.\n", iface, shader);
wined3d_mutex_lock(); - if ((wined3d_declaration = wined3d_stateblock_get_state(device->state)->vertex_declaration)) + if ((wined3d_declaration = device->stateblock_state->vertex_declaration)) { d3d8_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration); *shader = d3d8_declaration->shader_handle; @@ -2947,7 +2947,7 @@ static HRESULT WINAPI d3d8_device_DeleteVertexShader(IDirect3DDevice8 *iface, DW }
if (shader_impl->wined3d_shader - && wined3d_stateblock_get_state(device->state)->vs == shader_impl->wined3d_shader) + && device->stateblock_state->vs == shader_impl->wined3d_shader) IDirect3DDevice8_SetVertexShader(iface, 0);
wined3d_mutex_unlock(); @@ -2999,7 +2999,7 @@ static HRESULT WINAPI d3d8_device_GetVertexShaderConstant(IDirect3DDevice8 *ifac }
wined3d_mutex_lock(); - src = wined3d_stateblock_get_state(device->state)->vs_consts_f; + src = device->stateblock_state->vs_consts_f; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -3123,7 +3123,7 @@ static HRESULT WINAPI d3d8_device_GetIndices(IDirect3DDevice8 *iface,
/* The case from UINT to INT is safe because d3d8 will never set negative values */ wined3d_mutex_lock(); - state = wined3d_stateblock_get_state(device->state); + state = device->stateblock_state; *base_vertex_index = state->base_vertex_index; if ((wined3d_buffer = state->index_buffer)) { @@ -3228,7 +3228,7 @@ static HRESULT WINAPI d3d8_device_GetPixelShader(IDirect3DDevice8 *iface, DWORD return D3DERR_INVALIDCALL;
wined3d_mutex_lock(); - if ((object = wined3d_stateblock_get_state(device->state)->ps)) + if ((object = device->stateblock_state->ps)) { struct d3d8_pixel_shader *d3d8_shader; d3d8_shader = wined3d_shader_get_parent(object); @@ -3261,7 +3261,7 @@ static HRESULT WINAPI d3d8_device_DeletePixelShader(IDirect3DDevice8 *iface, DWO return D3DERR_INVALIDCALL; }
- if (wined3d_stateblock_get_state(device->state)->ps == shader_impl->wined3d_shader) + if (device->stateblock_state->ps == shader_impl->wined3d_shader) IDirect3DDevice8_SetPixelShader(iface, 0);
wined3d_mutex_unlock(); @@ -3299,7 +3299,7 @@ static HRESULT WINAPI d3d8_device_GetPixelShaderConstant(IDirect3DDevice8 *iface return WINED3DERR_INVALIDCALL;
wined3d_mutex_lock(); - src = wined3d_stateblock_get_state(device->state)->ps_consts_f; + src = device->stateblock_state->ps_consts_f; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -3376,7 +3376,7 @@ static HRESULT WINAPI d3d8_device_SetStreamSource(IDirect3DDevice8 *iface, if (!buffer_impl) { wined3d_buffer = NULL; - state = wined3d_stateblock_get_state(device->state); + state = device->stateblock_state; stride = state->streams[stream_idx].stride; } else if (buffer_impl->draw_buffer) @@ -3419,7 +3419,7 @@ static HRESULT WINAPI d3d8_device_GetStreamSource(IDirect3DDevice8 *iface, }
wined3d_mutex_lock(); - state = wined3d_stateblock_get_state(device->state); + state = device->stateblock_state; stream = &state->streams[stream_idx]; if (stream->buffer) { @@ -3704,6 +3704,7 @@ HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wine wined3d_mutex_unlock(); return hr; } + device->stateblock_state = wined3d_stateblock_get_state(device->state); device->update_state = device->state;
if (!parameters->Windowed)
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/d3d8/d3d8_private.h | 1 + dlls/d3d8/device.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h index f67841b4b13..488035c7f82 100644 --- a/dlls/d3d8/d3d8_private.h +++ b/dlls/d3d8/d3d8_private.h @@ -40,6 +40,7 @@ #define D3DPRESENTFLAGS_MASK 0x00000fffu
#define D3D8_MAX_VERTEX_SHADER_CONSTANTF 256 +#define D3D8_MAX_PIXEL_SHADER_CONSTANTF 8 #define D3D8_MAX_STREAMS 16
#define D3DFMT_RESZ MAKEFOURCC('R','E','S','Z') diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index 45b158314ed..d6253a4a2bf 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -3295,7 +3295,8 @@ static HRESULT WINAPI d3d8_device_GetPixelShaderConstant(IDirect3DDevice8 *iface
TRACE("iface %p, start_idx %u, constants %p, count %u.\n", iface, start_idx, constants, count);
- if (!constants || start_idx >= WINED3D_MAX_PS_CONSTS_F || count > WINED3D_MAX_PS_CONSTS_F - start_idx) + if (!constants || start_idx >= D3D8_MAX_PIXEL_SHADER_CONSTANTF + || count > D3D8_MAX_PIXEL_SHADER_CONSTANTF - start_idx) return WINED3DERR_INVALIDCALL;
wined3d_mutex_lock();
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Do the offsetting in d3d9 instead.
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/d3d9/device.c | 23 +++++++++++++---------- dlls/wined3d/device.c | 18 +++--------------- dlls/wined3d/stateblock.c | 14 +------------- include/wine/wined3d.h | 5 +---- 4 files changed, 18 insertions(+), 42 deletions(-)
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 8ffe04c94d7..d6a3d9e0b87 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -2514,8 +2514,8 @@ static HRESULT WINAPI d3d9_device_GetTexture(IDirect3DDevice9Ex *iface, DWORD st if (!texture) return D3DERR_INVALIDCALL;
- if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3) - stage -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS); + if (stage >= D3DVERTEXTEXTURESAMPLER0 && stage <= D3DVERTEXTEXTURESAMPLER3) + stage -= D3DVERTEXTEXTURESAMPLER0 - WINED3D_VERTEX_SAMPLER_OFFSET;
if (stage >= ARRAY_SIZE(state->textures)) { @@ -2550,20 +2550,20 @@ static HRESULT WINAPI d3d9_device_SetTexture(IDirect3DDevice9Ex *iface, DWORD st
texture_impl = unsafe_impl_from_IDirect3DBaseTexture9(texture);
+ if (stage >= D3DVERTEXTEXTURESAMPLER0 && stage <= D3DVERTEXTEXTURESAMPLER3) + stage -= D3DVERTEXTEXTURESAMPLER0 - WINED3D_VERTEX_SAMPLER_OFFSET; + wined3d_mutex_lock(); wined3d_stateblock_set_texture(device->update_state, stage, texture_impl ? texture_impl->wined3d_texture : NULL); if (!device->recording) { - unsigned int i = stage < 16 || (stage >= D3DVERTEXTEXTURESAMPLER0 && stage <= D3DVERTEXTEXTURESAMPLER3) - ? stage < 16 ? stage : stage - D3DVERTEXTEXTURESAMPLER0 + 16 : ~0u; - - if (i < D3D9_MAX_TEXTURE_UNITS) + if (stage < D3D9_MAX_TEXTURE_UNITS) { if (texture_impl && texture_impl->usage & D3DUSAGE_AUTOGENMIPMAP) - device->auto_mipmaps |= 1u << i; + device->auto_mipmaps |= 1u << stage; else - device->auto_mipmaps &= ~(1u << i); + device->auto_mipmaps &= ~(1u << stage); } } wined3d_mutex_unlock(); @@ -2656,8 +2656,8 @@ static HRESULT WINAPI d3d9_device_GetSamplerState(IDirect3DDevice9Ex *iface,
TRACE("iface %p, sampler_idx %u, state %#x, value %p.\n", iface, sampler_idx, state, value);
- if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3) - sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS); + if (sampler_idx >= D3DVERTEXTEXTURESAMPLER0 && sampler_idx <= D3DVERTEXTEXTURESAMPLER3) + sampler_idx -= D3DVERTEXTEXTURESAMPLER0 - WINED3D_VERTEX_SAMPLER_OFFSET;
if (sampler_idx >= ARRAY_SIZE(device_state->sampler_states)) { @@ -2681,6 +2681,9 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_SetSamplerState(IDirect3DDev
TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface, sampler, state, value);
+ if (sampler >= D3DVERTEXTEXTURESAMPLER0 && sampler <= D3DVERTEXTEXTURESAMPLER3) + sampler -= D3DVERTEXTEXTURESAMPLER0 - WINED3D_VERTEX_SAMPLER_OFFSET; + wined3d_mutex_lock(); wined3d_stateblock_set_sampler_state(device->update_state, sampler, state, value); wined3d_mutex_unlock(); diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 21f9af9566d..70dce23fbde 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -1746,9 +1746,6 @@ static void wined3d_device_set_sampler_state(struct wined3d_device *device, TRACE("device %p, sampler_idx %u, state %s, value %#x.\n", device, sampler_idx, debug_d3dsamplerstate(state), value);
- if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3) - sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS); - if (value == device->state.sampler_states[sampler_idx][state]) { TRACE("Application is setting the old value over, nothing to do.\n"); @@ -3492,9 +3489,6 @@ static void wined3d_device_set_texture(struct wined3d_device *device,
TRACE("device %p, stage %u, texture %p.\n", device, stage, texture);
- if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3) - stage -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS); - /* Windows accepts overflowing this array... we do not. */ if (stage >= ARRAY_SIZE(device->state.textures)) { @@ -3534,7 +3528,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, struct wined3d_color colour; struct wined3d_range range; BOOL set_blend_state; - DWORD map, stage; + DWORD map;
TRACE("device %p, stateblock %p.\n", device, stateblock);
@@ -3657,14 +3651,11 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device,
for (i = 0; i < ARRAY_SIZE(changed->samplerState); ++i) { - stage = i; - if (stage >= WINED3D_MAX_FRAGMENT_SAMPLERS) - stage += WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS; map = changed->samplerState[i]; while (map) { j = wined3d_bit_scan(&map); - wined3d_device_set_sampler_state(device, stage, j, state->sampler_states[i][j]); + wined3d_device_set_sampler_state(device, i, j, state->sampler_states[i][j]); } }
@@ -3713,10 +3704,7 @@ void CDECL wined3d_device_apply_stateblock(struct wined3d_device *device, while (map) { i = wined3d_bit_scan(&map); - stage = i; - if (stage >= WINED3D_MAX_FRAGMENT_SAMPLERS) - stage += WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS; - wined3d_device_set_texture(device, stage, state->textures[i]); + wined3d_device_set_texture(device, i, state->textures[i]); }
map = changed->clipplane; diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 70943afddaa..6e9060c0254 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -1092,7 +1092,6 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, DWORD stage = stateblock->contained_sampler_states[i].stage; DWORD sampler_state = stateblock->contained_sampler_states[i].state;
- if (stage >= WINED3D_MAX_FRAGMENT_SAMPLERS) stage += WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS; wined3d_stateblock_set_sampler_state(device_state, stage, sampler_state, state->sampler_states[stage][sampler_state]); } @@ -1144,13 +1143,8 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock, map = stateblock->changed.textures; for (i = 0; map; map >>= 1, ++i) { - DWORD stage = i; - - if (stage >= WINED3D_MAX_FRAGMENT_SAMPLERS) - stage += WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS; - if (map & 1) - wined3d_stateblock_set_texture(device_state, stage, state->textures[i]); + wined3d_stateblock_set_texture(device_state, i, state->textures[i]); }
map = stateblock->changed.clipplane; @@ -1380,9 +1374,6 @@ void CDECL wined3d_stateblock_set_sampler_state(struct wined3d_stateblock *state TRACE("stateblock %p, sampler_idx %u, state %s, value %#x.\n", stateblock, sampler_idx, debug_d3dsamplerstate(state), value);
- if (sampler_idx >= WINED3DVERTEXTEXTURESAMPLER0 && sampler_idx <= WINED3DVERTEXTEXTURESAMPLER3) - sampler_idx -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS); - if (sampler_idx >= ARRAY_SIZE(stateblock->stateblock_state.sampler_states)) { WARN("Invalid sampler %u.\n", sampler_idx); @@ -1421,9 +1412,6 @@ void CDECL wined3d_stateblock_set_texture(struct wined3d_stateblock *stateblock, { TRACE("stateblock %p, stage %u, texture %p.\n", stateblock, stage, texture);
- if (stage >= WINED3DVERTEXTEXTURESAMPLER0 && stage <= WINED3DVERTEXTEXTURESAMPLER3) - stage -= (WINED3DVERTEXTEXTURESAMPLER0 - WINED3D_MAX_FRAGMENT_SAMPLERS); - if (stage >= ARRAY_SIZE(stateblock->stateblock_state.textures)) { WARN("Ignoring invalid stage %u.\n", stage); diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index cb8f19981aa..e4b31e7f9c7 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -1035,10 +1035,7 @@ enum wined3d_shader_type
/* VTF defines */ #define WINED3DDMAPSAMPLER 0x100 -#define WINED3DVERTEXTEXTURESAMPLER0 (WINED3DDMAPSAMPLER + 1) -#define WINED3DVERTEXTEXTURESAMPLER1 (WINED3DDMAPSAMPLER + 2) -#define WINED3DVERTEXTEXTURESAMPLER2 (WINED3DDMAPSAMPLER + 3) -#define WINED3DVERTEXTEXTURESAMPLER3 (WINED3DDMAPSAMPLER + 4) +#define WINED3D_VERTEX_SAMPLER_OFFSET WINED3D_MAX_FRAGMENT_SAMPLERS
#define WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD 0x00000020 #define WINED3DCAPS3_LINEAR_TO_SRGB_PRESENTATION 0x00000080
On 3/6/20 5:33 AM, Matteo Bruni wrote:
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
After this patch d3d9.dll's .text section shrinks by 150-200 bytes but, for some reason, .debug_info grows by ~16.5KB. I looked a bit at the generated code and there doesn't seem to be anything surprising. I guess this is okay...
So this made me curious enough to look into why this happens, and it seems the answer is that the "struct wined3d_stateblock_state" type, and its member types, are now defined in several other files (e.g. buffer.c) where they wasn't used before, since "struct d3d9_device" now depends on it.
This is a well-known problem, enough that there's actually a solution: -fdebug-types-section, which defines "large" types in COMDAT .debug_types sections and tries to deduplicate when linking. Note that to make use of this, we'd also need to upgrade to -gdwarf-4.
I took a couple measurements of d3d9.dll (here built with -g -O0): with -gdwarf-2, this patch increases the size from 1290597 to 1306469 (15872 bytes), with -gdwarf-4 -fdebug-types-section, the size increases from 724034 to 725058 (1024 bytes).
Of course, the utility of this is a bit questionable, since debug builds are broadly only used by developers. On the other hand, it's clearly a lot of space that'd be saved.
I think dbghelp would also need work to support DWARF version 4. That said, I have half of a patch somewhere in my local tree that reimplements dbghelp's DWARF parser on top of libdwarf, which could make that easier.
dlls/d3d9/d3d9_private.h | 1 + dlls/d3d9/device.c | 66 +++++++++++++++++++--------------------- dlls/d3d9/stateblock.c | 2 +- 3 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index a9f3f47596c..a21582d6e1e 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -122,6 +122,7 @@ struct d3d9_device struct wined3d_swapchain **implicit_swapchains;
struct wined3d_stateblock *recording, *state, *update_state;
- const struct wined3d_stateblock_state *stateblock_state;
};
HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wined3d *wined3d, diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index a651a63f02e..8ffe04c94d7 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1042,7 +1042,7 @@ static HRESULT d3d9_device_reset(struct d3d9_device *device,
if (extended) {
const struct wined3d_viewport *current = &wined3d_stateblock_get_state(device->state)->viewport;
const struct wined3d_viewport *current = &device->stateblock_state->viewport; struct wined3d_viewport vp; RECT rect;
@@ -2121,7 +2121,7 @@ static HRESULT WINAPI d3d9_device_GetTransform(IDirect3DDevice9Ex *iface,
/* Note: D3DMATRIX is compatible with struct wined3d_matrix. */ wined3d_mutex_lock();
- memcpy(matrix, &wined3d_stateblock_get_state(device->state)->transforms[state], sizeof(*matrix));
memcpy(matrix, &device->stateblock_state->transforms[state], sizeof(*matrix)); wined3d_mutex_unlock();
return D3D_OK;
@@ -2171,7 +2171,7 @@ static HRESULT WINAPI d3d9_device_GetViewport(IDirect3DDevice9Ex *iface, D3DVIEW TRACE("iface %p, viewport %p.\n", iface, viewport);
wined3d_mutex_lock();
- wined3d_viewport = wined3d_stateblock_get_state(device->state)->viewport;
wined3d_viewport = device->stateblock_state->viewport; wined3d_mutex_unlock();
viewport->X = wined3d_viewport.x;
@@ -2206,7 +2206,7 @@ static HRESULT WINAPI d3d9_device_GetMaterial(IDirect3DDevice9Ex *iface, D3DMATE
/* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */ wined3d_mutex_lock();
- 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;
@@ -2297,7 +2297,7 @@ static HRESULT WINAPI d3d9_device_GetClipPlane(IDirect3DDevice9Ex *iface, DWORD index = min(index, device->max_user_clip_planes - 1);
wined3d_mutex_lock();
- memcpy(plane, &wined3d_stateblock_get_state(device->state)->clip_planes[index], sizeof(struct wined3d_vec4));
memcpy(plane, &device->stateblock_state->clip_planes[index], sizeof(struct wined3d_vec4)); wined3d_mutex_unlock();
return D3D_OK;
@@ -2305,7 +2305,7 @@ static HRESULT WINAPI d3d9_device_GetClipPlane(IDirect3DDevice9Ex *iface, DWORD
static void resolve_depth_buffer(struct d3d9_device *device) {
- const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state);
- const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_rendertarget_view *wined3d_dsv; struct wined3d_resource *dst_resource; struct wined3d_texture *dst_texture;
@@ -2356,7 +2356,7 @@ static HRESULT WINAPI d3d9_device_GetRenderState(IDirect3DDevice9Ex *iface, TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
wined3d_mutex_lock();
- device_state = wined3d_stateblock_get_state(device->state);
- device_state = device->stateblock_state; *value = device_state->rs[state]; wined3d_mutex_unlock();
@@ -2525,7 +2525,7 @@ static HRESULT WINAPI d3d9_device_GetTexture(IDirect3DDevice9Ex *iface, DWORD st }
wined3d_mutex_lock();
- state = wined3d_stateblock_get_state(device->state);
- state = device->stateblock_state; if ((wined3d_texture = state->textures[stage])) { texture_impl = wined3d_texture_get_parent(wined3d_texture);
@@ -2622,7 +2622,7 @@ static HRESULT WINAPI d3d9_device_GetTextureStageState(IDirect3DDevice9Ex *iface }
wined3d_mutex_lock();
- *value = wined3d_stateblock_get_state(device->state)->texture_states[stage][tss_lookup[state]];
*value = device->stateblock_state->texture_states[stage][tss_lookup[state]]; wined3d_mutex_unlock();
return D3D_OK;
@@ -2667,7 +2667,7 @@ static HRESULT WINAPI d3d9_device_GetSamplerState(IDirect3DDevice9Ex *iface, }
wined3d_mutex_lock();
- device_state = wined3d_stateblock_get_state(device->state);
- device_state = device->stateblock_state; *value = device_state->sampler_states[sampler_idx][state]; wined3d_mutex_unlock();
@@ -2758,7 +2758,7 @@ static HRESULT WINAPI d3d9_device_GetScissorRect(IDirect3DDevice9Ex *iface, RECT TRACE("iface %p, rect %p.\n", iface, rect);
wined3d_mutex_lock();
- *rect = wined3d_stateblock_get_state(device->state)->scissor_rect;
*rect = device->stateblock_state->scissor_rect; wined3d_mutex_unlock();
return D3D_OK;
@@ -2822,7 +2822,7 @@ static float WINAPI d3d9_device_GetNPatchMode(IDirect3DDevice9Ex *iface) /* wined3d critical section must be taken by the caller. */ static void d3d9_generate_auto_mipmaps(struct d3d9_device *device) {
- const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state);
- const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_texture *texture; unsigned int i, map;
@@ -2838,7 +2838,7 @@ static void d3d9_generate_auto_mipmaps(struct d3d9_device *device) static void d3d9_device_upload_sysmem_vertex_buffers(struct d3d9_device *device, int base_vertex, unsigned int start_vertex, unsigned int vertex_count) {
- const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state);
- const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_vertex_declaration *wined3d_decl; struct wined3d_box box = {0, 0, 0, 1, 0, 1}; const struct wined3d_stream_state *stream;
@@ -2884,7 +2884,7 @@ static void d3d9_device_upload_sysmem_vertex_buffers(struct d3d9_device *device, static void d3d9_device_upload_sysmem_index_buffer(struct d3d9_device *device, unsigned int start_idx, unsigned int idx_count) {
- const struct wined3d_stateblock_state *state = wined3d_stateblock_get_state(device->state);
- const struct wined3d_stateblock_state *state = device->stateblock_state; struct wined3d_box box = {0, 0, 0, 1, 0, 1}; struct wined3d_resource *dst_resource; struct d3d9_indexbuffer *d3d9_buffer;
@@ -3250,7 +3250,7 @@ static HRESULT WINAPI d3d9_device_ProcessVertices(IDirect3DDevice9Ex *iface, iface, src_start_idx, dst_idx, vertex_count, dst_buffer, declaration, flags);
wined3d_mutex_lock();
- state = wined3d_stateblock_get_state(device->state);
state = device->stateblock_state;
/* Note that an alternative approach would be to simply create these
- buffers with WINED3D_RESOURCE_ACCESS_MAP_R and update them here like we
@@ -3341,7 +3341,7 @@ static HRESULT WINAPI d3d9_device_GetVertexDeclaration(IDirect3DDevice9Ex *iface if (!declaration) return D3DERR_INVALIDCALL;
wined3d_mutex_lock();
- if ((wined3d_declaration = wined3d_stateblock_get_state(device->state)->vertex_declaration))
- if ((wined3d_declaration = device->stateblock_state->vertex_declaration)) { declaration_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration); *declaration = &declaration_impl->IDirect3DVertexDeclaration9_iface;
@@ -3461,7 +3461,7 @@ static HRESULT WINAPI d3d9_device_GetFVF(IDirect3DDevice9Ex *iface, DWORD *fvf) TRACE("iface %p, fvf %p.\n", iface, fvf);
wined3d_mutex_lock();
- if ((wined3d_declaration = wined3d_stateblock_get_state(device->state)->vertex_declaration))
- if ((wined3d_declaration = device->stateblock_state->vertex_declaration)) { d3d9_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration); *fvf = d3d9_declaration->fvf;
@@ -3527,7 +3527,7 @@ static HRESULT WINAPI d3d9_device_GetVertexShader(IDirect3DDevice9Ex *iface, IDi TRACE("iface %p, shader %p.\n", iface, shader);
wined3d_mutex_lock();
- if ((wined3d_shader = wined3d_stateblock_get_state(device->state)->vs))
- if ((wined3d_shader = device->stateblock_state->vs)) { shader_impl = wined3d_shader_get_parent(wined3d_shader); *shader = &shader_impl->IDirect3DVertexShader9_iface;
@@ -3586,7 +3586,7 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex *i }
wined3d_mutex_lock();
- src = wined3d_stateblock_get_state(device->state)->vs_consts_f;
- src = device->stateblock_state->vs_consts_f; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -3623,7 +3623,7 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex *i count = WINED3D_MAX_CONSTS_I - start_idx;
wined3d_mutex_lock();
- src = wined3d_stateblock_get_state(device->state)->vs_consts_i;
- src = device->stateblock_state->vs_consts_i; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -3658,7 +3658,7 @@ static HRESULT WINAPI d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex *i count = WINED3D_MAX_CONSTS_B - start_idx;
wined3d_mutex_lock();
- memcpy(constants, &wined3d_stateblock_get_state(device->state)->vs_consts_b[start_idx], count * sizeof(*constants));
memcpy(constants, &device->stateblock_state->vs_consts_b[start_idx], count * sizeof(*constants)); wined3d_mutex_unlock();
return D3D_OK;
@@ -3669,14 +3669,13 @@ static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface, { struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); struct d3d9_vertexbuffer *buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer9(buffer);
const struct wined3d_stateblock_state *state; struct wined3d_buffer *wined3d_buffer; HRESULT hr;
TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n", iface, stream_idx, buffer, offset, stride);
if (stream_idx >= ARRAY_SIZE(state->streams))
- if (stream_idx >= ARRAY_SIZE(device->stateblock_state->streams)) { WARN("Stream index %u out of range.\n", stream_idx); return WINED3DERR_INVALIDCALL;
@@ -3685,9 +3684,8 @@ static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface, wined3d_mutex_lock(); if (!buffer_impl) {
const struct wined3d_stream_state *stream;
state = wined3d_stateblock_get_state(device->state);
stream = &state->streams[stream_idx];
const struct wined3d_stream_state *stream = &device->stateblock_state->streams[stream_idx];
offset = stream->offset; stride = stream->stride; wined3d_buffer = NULL;
@@ -3736,8 +3734,7 @@ static HRESULT WINAPI d3d9_device_GetStreamSource(IDirect3DDevice9Ex *iface, }
wined3d_mutex_lock();
- state = wined3d_stateblock_get_state(device->state);
- stream = &state->streams[stream_idx];
- stream = &device->stateblock_state->streams[stream_idx]; if (stream->buffer) { buffer_impl = wined3d_buffer_get_parent(stream->buffer);
@@ -3776,7 +3773,7 @@ static HRESULT WINAPI d3d9_device_GetStreamSourceFreq(IDirect3DDevice9Ex *iface, TRACE("iface %p, stream_idx %u, freq %p.\n", iface, stream_idx, freq);
wined3d_mutex_lock();
- stream = &wined3d_stateblock_get_state(device->state)->streams[stream_idx];
- stream = &device->stateblock_state->streams[stream_idx]; *freq = stream->flags | stream->frequency; wined3d_mutex_unlock();
@@ -3819,7 +3816,7 @@ static HRESULT WINAPI d3d9_device_GetIndices(IDirect3DDevice9Ex *iface, IDirect3 return D3DERR_INVALIDCALL;
wined3d_mutex_lock();
- if ((wined3d_buffer = wined3d_stateblock_get_state(device->state)->index_buffer))
- if ((wined3d_buffer = device->stateblock_state->index_buffer)) { buffer_impl = wined3d_buffer_get_parent(wined3d_buffer); *buffer = &buffer_impl->IDirect3DIndexBuffer9_iface;
@@ -3889,7 +3886,7 @@ static HRESULT WINAPI d3d9_device_GetPixelShader(IDirect3DDevice9Ex *iface, IDir if (!shader) return D3DERR_INVALIDCALL;
wined3d_mutex_lock();
- if ((wined3d_shader = wined3d_stateblock_get_state(device->state)->ps))
- if ((wined3d_shader = device->stateblock_state->ps)) { shader_impl = wined3d_shader_get_parent(wined3d_shader); *shader = &shader_impl->IDirect3DPixelShader9_iface;
@@ -3934,7 +3931,7 @@ static HRESULT WINAPI d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex *if return WINED3DERR_INVALIDCALL;
wined3d_mutex_lock();
- src = wined3d_stateblock_get_state(device->state)->ps_consts_f;
- src = device->stateblock_state->ps_consts_f; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -3971,7 +3968,7 @@ static HRESULT WINAPI d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex *if count = WINED3D_MAX_CONSTS_I - start_idx;
wined3d_mutex_lock();
- src = wined3d_stateblock_get_state(device->state)->ps_consts_i;
- src = device->stateblock_state->ps_consts_i; memcpy(constants, &src[start_idx], count * sizeof(*src)); wined3d_mutex_unlock();
@@ -4006,7 +4003,7 @@ static HRESULT WINAPI d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex *if count = WINED3D_MAX_CONSTS_I - start_idx;
wined3d_mutex_lock();
- memcpy(constants, &wined3d_stateblock_get_state(device->state)->ps_consts_b[start_idx], count * sizeof(*constants));
memcpy(constants, &device->stateblock_state->ps_consts_b[start_idx], count * sizeof(*constants)); wined3d_mutex_unlock();
return D3D_OK;
@@ -4641,6 +4638,7 @@ HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wine wined3d_mutex_unlock(); return hr; }
device->stateblock_state = wined3d_stateblock_get_state(device->state); device->update_state = device->state;
if (flags & D3DCREATE_MULTITHREADED)
diff --git a/dlls/d3d9/stateblock.c b/dlls/d3d9/stateblock.c index a65fa1cd8d4..a1ce3d5856c 100644 --- a/dlls/d3d9/stateblock.c +++ b/dlls/d3d9/stateblock.c @@ -151,7 +151,7 @@ static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface) device->auto_mipmaps = 0; for (i = 0; i < D3D9_MAX_TEXTURE_UNITS; ++i) {
if ((wined3d_texture = wined3d_stateblock_get_state(device->state)->textures[i])
if ((wined3d_texture = device->stateblock_state->textures[i]) && (texture = wined3d_texture_get_parent(wined3d_texture)) && texture->usage & D3DUSAGE_AUTOGENMIPMAP) device->auto_mipmaps |= 1u << i;