Commit 07985a8c authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Use rendertarget views for depth/stencil buffers instead of surfaces.

I don't think the difference between d3d10 depth/stencil and rendertarget views is large enough to justify a separate type. Unfortunately that does make the name "wined3d_rendertarget_view" slightly awkward.
parent 9f973141
...@@ -1127,7 +1127,7 @@ static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface, ...@@ -1127,7 +1127,7 @@ static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface,
struct d3d8_device *device = impl_from_IDirect3DDevice8(iface); struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
struct d3d8_surface *rt_impl = unsafe_impl_from_IDirect3DSurface8(render_target); struct d3d8_surface *rt_impl = unsafe_impl_from_IDirect3DSurface8(render_target);
struct d3d8_surface *ds_impl = unsafe_impl_from_IDirect3DSurface8(depth_stencil); struct d3d8_surface *ds_impl = unsafe_impl_from_IDirect3DSurface8(depth_stencil);
struct wined3d_surface *original_ds = NULL; struct wined3d_rendertarget_view *original_dsv;
HRESULT hr = D3D_OK; HRESULT hr = D3D_OK;
TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, render_target, depth_stencil); TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, render_target, depth_stencil);
...@@ -1168,11 +1168,12 @@ static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface, ...@@ -1168,11 +1168,12 @@ static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface,
} }
} }
original_ds = wined3d_device_get_depth_stencil(device->wined3d_device); original_dsv = wined3d_device_get_depth_stencil_view(device->wined3d_device);
wined3d_device_set_depth_stencil(device->wined3d_device, ds_impl ? ds_impl->wined3d_surface : NULL); wined3d_device_set_depth_stencil_view(device->wined3d_device,
ds_impl ? d3d8_surface_get_rendertarget_view(ds_impl) : NULL);
if (render_target && FAILED(hr = wined3d_device_set_rendertarget_view(device->wined3d_device, 0, if (render_target && FAILED(hr = wined3d_device_set_rendertarget_view(device->wined3d_device, 0,
d3d8_surface_get_rendertarget_view(rt_impl), TRUE))) d3d8_surface_get_rendertarget_view(rt_impl), TRUE)))
wined3d_device_set_depth_stencil(device->wined3d_device, original_ds); wined3d_device_set_depth_stencil_view(device->wined3d_device, original_dsv);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
...@@ -1215,7 +1216,7 @@ static HRESULT WINAPI d3d8_device_GetRenderTarget(IDirect3DDevice8 *iface, IDire ...@@ -1215,7 +1216,7 @@ static HRESULT WINAPI d3d8_device_GetRenderTarget(IDirect3DDevice8 *iface, IDire
static HRESULT WINAPI d3d8_device_GetDepthStencilSurface(IDirect3DDevice8 *iface, IDirect3DSurface8 **depth_stencil) static HRESULT WINAPI d3d8_device_GetDepthStencilSurface(IDirect3DDevice8 *iface, IDirect3DSurface8 **depth_stencil)
{ {
struct d3d8_device *device = impl_from_IDirect3DDevice8(iface); struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
struct wined3d_surface *wined3d_surface; struct wined3d_rendertarget_view *wined3d_dsv;
struct d3d8_surface *surface_impl; struct d3d8_surface *surface_impl;
HRESULT hr = D3D_OK; HRESULT hr = D3D_OK;
...@@ -1225,9 +1226,11 @@ static HRESULT WINAPI d3d8_device_GetDepthStencilSurface(IDirect3DDevice8 *iface ...@@ -1225,9 +1226,11 @@ static HRESULT WINAPI d3d8_device_GetDepthStencilSurface(IDirect3DDevice8 *iface
return D3DERR_INVALIDCALL; return D3DERR_INVALIDCALL;
wined3d_mutex_lock(); wined3d_mutex_lock();
if ((wined3d_surface = wined3d_device_get_depth_stencil(device->wined3d_device))) if ((wined3d_dsv = wined3d_device_get_depth_stencil_view(device->wined3d_device)))
{ {
surface_impl = wined3d_surface_get_parent(wined3d_surface); /* We want the sub resource parent here, since the view itself may be
* internal to wined3d and may not have a parent. */
surface_impl = wined3d_rendertarget_view_get_sub_resource_parent(wined3d_dsv);
*depth_stencil = &surface_impl->IDirect3DSurface8_iface; *depth_stencil = &surface_impl->IDirect3DSurface8_iface;
IDirect3DSurface8_AddRef(*depth_stencil); IDirect3DSurface8_AddRef(*depth_stencil);
} }
......
...@@ -1397,7 +1397,8 @@ static HRESULT WINAPI d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex *ifa ...@@ -1397,7 +1397,8 @@ static HRESULT WINAPI d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex *ifa
TRACE("iface %p, depth_stencil %p.\n", iface, depth_stencil); TRACE("iface %p, depth_stencil %p.\n", iface, depth_stencil);
wined3d_mutex_lock(); wined3d_mutex_lock();
wined3d_device_set_depth_stencil(device->wined3d_device, ds_impl ? ds_impl->wined3d_surface : NULL); wined3d_device_set_depth_stencil_view(device->wined3d_device,
ds_impl ? d3d9_surface_get_rendertarget_view(ds_impl) : NULL);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
return D3D_OK; return D3D_OK;
...@@ -1406,7 +1407,7 @@ static HRESULT WINAPI d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex *ifa ...@@ -1406,7 +1407,7 @@ static HRESULT WINAPI d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex *ifa
static HRESULT WINAPI d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex *iface, IDirect3DSurface9 **depth_stencil) static HRESULT WINAPI d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex *iface, IDirect3DSurface9 **depth_stencil)
{ {
struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface); struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
struct wined3d_surface *wined3d_surface; struct wined3d_rendertarget_view *wined3d_dsv;
struct d3d9_surface *surface_impl; struct d3d9_surface *surface_impl;
HRESULT hr = D3D_OK; HRESULT hr = D3D_OK;
...@@ -1416,9 +1417,11 @@ static HRESULT WINAPI d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex *ifa ...@@ -1416,9 +1417,11 @@ static HRESULT WINAPI d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex *ifa
return D3DERR_INVALIDCALL; return D3DERR_INVALIDCALL;
wined3d_mutex_lock(); wined3d_mutex_lock();
if ((wined3d_surface = wined3d_device_get_depth_stencil(device->wined3d_device))) if ((wined3d_dsv = wined3d_device_get_depth_stencil_view(device->wined3d_device)))
{ {
surface_impl = wined3d_surface_get_parent(wined3d_surface); /* We want the sub resource parent here, since the view itself may be
* internal to wined3d and may not have a parent. */
surface_impl = wined3d_rendertarget_view_get_sub_resource_parent(wined3d_dsv);
*depth_stencil = &surface_impl->IDirect3DSurface9_iface; *depth_stencil = &surface_impl->IDirect3DSurface9_iface;
IDirect3DSurface9_AddRef(*depth_stencil); IDirect3DSurface9_AddRef(*depth_stencil);
} }
......
...@@ -767,9 +767,8 @@ static HRESULT WINAPI ddraw1_RestoreDisplayMode(IDirectDraw *iface) ...@@ -767,9 +767,8 @@ static HRESULT WINAPI ddraw1_RestoreDisplayMode(IDirectDraw *iface)
static HRESULT ddraw_set_cooperative_level(struct ddraw *ddraw, HWND window, static HRESULT ddraw_set_cooperative_level(struct ddraw *ddraw, HWND window,
DWORD cooplevel, BOOL restore_mode_on_normal) DWORD cooplevel, BOOL restore_mode_on_normal)
{ {
struct wined3d_rendertarget_view *rtv = NULL; struct wined3d_rendertarget_view *rtv = NULL, *dsv = NULL;
struct wined3d_stateblock *stateblock; struct wined3d_stateblock *stateblock;
struct wined3d_surface *ds = NULL;
BOOL restore_state = FALSE; BOOL restore_state = FALSE;
HRESULT hr; HRESULT hr;
...@@ -926,8 +925,8 @@ static HRESULT ddraw_set_cooperative_level(struct ddraw *ddraw, HWND window, ...@@ -926,8 +925,8 @@ static HRESULT ddraw_set_cooperative_level(struct ddraw *ddraw, HWND window,
else if (rtv) else if (rtv)
wined3d_rendertarget_view_incref(rtv); wined3d_rendertarget_view_incref(rtv);
if ((ds = wined3d_device_get_depth_stencil(ddraw->wined3d_device))) if ((dsv = wined3d_device_get_depth_stencil_view(ddraw->wined3d_device)))
wined3d_surface_incref(ds); wined3d_rendertarget_view_incref(dsv);
} }
ddraw_destroy_swapchain(ddraw); ddraw_destroy_swapchain(ddraw);
...@@ -938,10 +937,10 @@ static HRESULT ddraw_set_cooperative_level(struct ddraw *ddraw, HWND window, ...@@ -938,10 +937,10 @@ static HRESULT ddraw_set_cooperative_level(struct ddraw *ddraw, HWND window,
if (restore_state) if (restore_state)
{ {
if (ds) if (dsv)
{ {
wined3d_device_set_depth_stencil(ddraw->wined3d_device, ds); wined3d_device_set_depth_stencil_view(ddraw->wined3d_device, dsv);
wined3d_surface_decref(ds); wined3d_rendertarget_view_decref(dsv);
} }
if (rtv) if (rtv)
......
...@@ -6759,13 +6759,13 @@ enum wined3d_depth_buffer_type d3d_device_update_depth_stencil(struct d3d_device ...@@ -6759,13 +6759,13 @@ enum wined3d_depth_buffer_type d3d_device_update_depth_stencil(struct d3d_device
if (!depthStencil) if (!depthStencil)
{ {
TRACE("Setting wined3d depth stencil to NULL\n"); TRACE("Setting wined3d depth stencil to NULL\n");
wined3d_device_set_depth_stencil(device->wined3d_device, NULL); wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
return WINED3D_ZB_FALSE; return WINED3D_ZB_FALSE;
} }
dsi = impl_from_IDirectDrawSurface7(depthStencil); dsi = impl_from_IDirectDrawSurface7(depthStencil);
TRACE("Setting wined3d depth stencil to %p (wined3d %p)\n", dsi, dsi->wined3d_surface); wined3d_device_set_depth_stencil_view(device->wined3d_device,
wined3d_device_set_depth_stencil(device->wined3d_device, dsi->wined3d_surface); ddraw_surface_get_rendertarget_view(dsi));
IDirectDrawSurface7_Release(depthStencil); IDirectDrawSurface7_Release(depthStencil);
return WINED3D_ZB_TRUE; return WINED3D_ZB_TRUE;
......
...@@ -2201,13 +2201,13 @@ static BOOL match_depth_stencil_format(const struct wined3d_format *existing, ...@@ -2201,13 +2201,13 @@ static BOOL match_depth_stencil_format(const struct wined3d_format *existing,
/* The caller provides a context */ /* The caller provides a context */
static void context_validate_onscreen_formats(struct wined3d_context *context, static void context_validate_onscreen_formats(struct wined3d_context *context,
const struct wined3d_surface *depth_stencil) const struct wined3d_rendertarget_view *depth_stencil)
{ {
/* Onscreen surfaces are always in a swapchain */ /* Onscreen surfaces are always in a swapchain */
struct wined3d_swapchain *swapchain = context->current_rt->container->swapchain; struct wined3d_swapchain *swapchain = context->current_rt->container->swapchain;
if (context->render_offscreen || !depth_stencil) return; if (context->render_offscreen || !depth_stencil) return;
if (match_depth_stencil_format(swapchain->ds_format, depth_stencil->resource.format)) return; if (match_depth_stencil_format(swapchain->ds_format, depth_stencil->format)) return;
/* TODO: If the requested format would satisfy the needs of the existing one(reverse match), /* TODO: If the requested format would satisfy the needs of the existing one(reverse match),
* or no onscreen depth buffer was created, the OpenGL drawable could be changed to the new * or no onscreen depth buffer was created, the OpenGL drawable could be changed to the new
...@@ -2280,8 +2280,8 @@ void context_apply_blit_state(struct wined3d_context *context, const struct wine ...@@ -2280,8 +2280,8 @@ void context_apply_blit_state(struct wined3d_context *context, const struct wine
context_invalidate_state(context, STATE_FRAMEBUFFER); context_invalidate_state(context, STATE_FRAMEBUFFER);
} }
static BOOL context_validate_rt_config(UINT rt_count, static BOOL context_validate_rt_config(UINT rt_count, struct wined3d_rendertarget_view * const *rts,
struct wined3d_rendertarget_view * const *rts, const struct wined3d_surface *ds) const struct wined3d_rendertarget_view *ds)
{ {
unsigned int i; unsigned int i;
...@@ -2329,7 +2329,8 @@ BOOL context_apply_clear_state(struct wined3d_context *context, const struct win ...@@ -2329,7 +2329,8 @@ BOOL context_apply_clear_state(struct wined3d_context *context, const struct win
context->blit_targets[i] = NULL; context->blit_targets[i] = NULL;
++i; ++i;
} }
context_apply_fbo_state(context, GL_FRAMEBUFFER, context->blit_targets, fb->depth_stencil, context_apply_fbo_state(context, GL_FRAMEBUFFER, context->blit_targets,
wined3d_rendertarget_view_get_surface(fb->depth_stencil),
rt_count ? rts[0]->resource->draw_binding : WINED3D_LOCATION_TEXTURE_RGB); rt_count ? rts[0]->resource->draw_binding : WINED3D_LOCATION_TEXTURE_RGB);
} }
else else
...@@ -2446,7 +2447,8 @@ void context_state_fb(struct wined3d_context *context, const struct wined3d_stat ...@@ -2446,7 +2447,8 @@ void context_state_fb(struct wined3d_context *context, const struct wined3d_stat
{ {
context->blit_targets[i] = wined3d_rendertarget_view_get_surface(fb->render_targets[i]); context->blit_targets[i] = wined3d_rendertarget_view_get_surface(fb->render_targets[i]);
} }
context_apply_fbo_state(context, GL_FRAMEBUFFER, context->blit_targets, fb->depth_stencil, context_apply_fbo_state(context, GL_FRAMEBUFFER, context->blit_targets,
wined3d_rendertarget_view_get_surface(fb->depth_stencil),
fb->render_targets[0]->resource->draw_binding); fb->render_targets[0]->resource->draw_binding);
} }
} }
......
...@@ -32,7 +32,7 @@ enum wined3d_cs_op ...@@ -32,7 +32,7 @@ enum wined3d_cs_op
WINED3D_CS_OP_SET_VIEWPORT, WINED3D_CS_OP_SET_VIEWPORT,
WINED3D_CS_OP_SET_SCISSOR_RECT, WINED3D_CS_OP_SET_SCISSOR_RECT,
WINED3D_CS_OP_SET_RENDERTARGET_VIEW, WINED3D_CS_OP_SET_RENDERTARGET_VIEW,
WINED3D_CS_OP_SET_DEPTH_STENCIL, WINED3D_CS_OP_SET_DEPTH_STENCIL_VIEW,
WINED3D_CS_OP_SET_VERTEX_DECLARATION, WINED3D_CS_OP_SET_VERTEX_DECLARATION,
WINED3D_CS_OP_SET_STREAM_SOURCE, WINED3D_CS_OP_SET_STREAM_SOURCE,
WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ, WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ,
...@@ -102,10 +102,10 @@ struct wined3d_cs_set_rendertarget_view ...@@ -102,10 +102,10 @@ struct wined3d_cs_set_rendertarget_view
struct wined3d_rendertarget_view *view; struct wined3d_rendertarget_view *view;
}; };
struct wined3d_cs_set_depth_stencil struct wined3d_cs_set_depth_stencil_view
{ {
enum wined3d_cs_op opcode; enum wined3d_cs_op opcode;
struct wined3d_surface *depth_stencil; struct wined3d_rendertarget_view *view;
}; };
struct wined3d_cs_set_vertex_declaration struct wined3d_cs_set_vertex_declaration
...@@ -367,20 +367,21 @@ void wined3d_cs_emit_set_rendertarget_view(struct wined3d_cs *cs, unsigned int v ...@@ -367,20 +367,21 @@ void wined3d_cs_emit_set_rendertarget_view(struct wined3d_cs *cs, unsigned int v
cs->ops->submit(cs); cs->ops->submit(cs);
} }
static void wined3d_cs_exec_set_depth_stencil(struct wined3d_cs *cs, const void *data) static void wined3d_cs_exec_set_depth_stencil_view(struct wined3d_cs *cs, const void *data)
{ {
const struct wined3d_cs_set_depth_stencil *op = data; const struct wined3d_cs_set_depth_stencil_view *op = data;
struct wined3d_device *device = cs->device; struct wined3d_device *device = cs->device;
struct wined3d_surface *prev; struct wined3d_rendertarget_view *prev;
if ((prev = cs->state.fb->depth_stencil)) if ((prev = cs->state.fb->depth_stencil))
{ {
if (device->swapchains[0]->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL struct wined3d_surface *prev_surface = wined3d_rendertarget_view_get_surface(prev);
|| prev->flags & SFLAG_DISCARD)
if (prev_surface && (device->swapchains[0]->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
|| prev_surface->flags & SFLAG_DISCARD))
{ {
surface_modify_ds_location(prev, WINED3D_LOCATION_DISCARDED, surface_modify_ds_location(prev_surface, WINED3D_LOCATION_DISCARDED, prev->width, prev->height);
prev->resource.width, prev->resource.height); if (prev_surface == device->onscreen_depth_stencil)
if (prev == device->onscreen_depth_stencil)
{ {
wined3d_surface_decref(device->onscreen_depth_stencil); wined3d_surface_decref(device->onscreen_depth_stencil);
device->onscreen_depth_stencil = NULL; device->onscreen_depth_stencil = NULL;
...@@ -388,9 +389,9 @@ static void wined3d_cs_exec_set_depth_stencil(struct wined3d_cs *cs, const void ...@@ -388,9 +389,9 @@ static void wined3d_cs_exec_set_depth_stencil(struct wined3d_cs *cs, const void
} }
} }
cs->fb.depth_stencil = op->depth_stencil; cs->fb.depth_stencil = op->view;
if (!prev != !op->depth_stencil) if (!prev != !op->view)
{ {
/* Swapping NULL / non NULL depth stencil affects the depth and tests */ /* Swapping NULL / non NULL depth stencil affects the depth and tests */
device_invalidate_state(device, STATE_RENDER(WINED3D_RS_ZENABLE)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_ZENABLE));
...@@ -398,7 +399,7 @@ static void wined3d_cs_exec_set_depth_stencil(struct wined3d_cs *cs, const void ...@@ -398,7 +399,7 @@ static void wined3d_cs_exec_set_depth_stencil(struct wined3d_cs *cs, const void
device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_STENCILWRITEMASK));
device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS));
} }
else if (prev && prev->resource.format->depth_size != op->depth_stencil->resource.format->depth_size) else if (prev && prev->format->depth_size != op->view->format->depth_size)
{ {
device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS)); device_invalidate_state(device, STATE_RENDER(WINED3D_RS_DEPTHBIAS));
} }
...@@ -406,13 +407,13 @@ static void wined3d_cs_exec_set_depth_stencil(struct wined3d_cs *cs, const void ...@@ -406,13 +407,13 @@ static void wined3d_cs_exec_set_depth_stencil(struct wined3d_cs *cs, const void
device_invalidate_state(device, STATE_FRAMEBUFFER); device_invalidate_state(device, STATE_FRAMEBUFFER);
} }
void wined3d_cs_emit_set_depth_stencil(struct wined3d_cs *cs, struct wined3d_surface *depth_stencil) void wined3d_cs_emit_set_depth_stencil_view(struct wined3d_cs *cs, struct wined3d_rendertarget_view *view)
{ {
struct wined3d_cs_set_depth_stencil *op; struct wined3d_cs_set_depth_stencil_view *op;
op = cs->ops->require_space(cs, sizeof(*op)); op = cs->ops->require_space(cs, sizeof(*op));
op->opcode = WINED3D_CS_OP_SET_DEPTH_STENCIL; op->opcode = WINED3D_CS_OP_SET_DEPTH_STENCIL_VIEW;
op->depth_stencil = depth_stencil; op->view = view;
cs->ops->submit(cs); cs->ops->submit(cs);
} }
...@@ -852,7 +853,7 @@ static void (* const wined3d_cs_op_handlers[])(struct wined3d_cs *cs, const void ...@@ -852,7 +853,7 @@ static void (* const wined3d_cs_op_handlers[])(struct wined3d_cs *cs, const void
/* WINED3D_CS_OP_SET_VIEWPORT */ wined3d_cs_exec_set_viewport, /* WINED3D_CS_OP_SET_VIEWPORT */ wined3d_cs_exec_set_viewport,
/* WINED3D_CS_OP_SET_SCISSOR_RECT */ wined3d_cs_exec_set_scissor_rect, /* WINED3D_CS_OP_SET_SCISSOR_RECT */ wined3d_cs_exec_set_scissor_rect,
/* WINED3D_CS_OP_SET_RENDERTARGET_VIEW */ wined3d_cs_exec_set_rendertarget_view, /* WINED3D_CS_OP_SET_RENDERTARGET_VIEW */ wined3d_cs_exec_set_rendertarget_view,
/* WINED3D_CS_OP_SET_DEPTH_STENCIL */ wined3d_cs_exec_set_depth_stencil, /* WINED3D_CS_OP_SET_DEPTH_STENCIL_VIEW */ wined3d_cs_exec_set_depth_stencil_view,
/* WINED3D_CS_OP_SET_VERTEX_DECLARATION */ wined3d_cs_exec_set_vertex_declaration, /* WINED3D_CS_OP_SET_VERTEX_DECLARATION */ wined3d_cs_exec_set_vertex_declaration,
/* WINED3D_CS_OP_SET_STREAM_SOURCE */ wined3d_cs_exec_set_stream_source, /* WINED3D_CS_OP_SET_STREAM_SOURCE */ wined3d_cs_exec_set_stream_source,
/* WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ */ wined3d_cs_exec_set_stream_source_freq, /* WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ */ wined3d_cs_exec_set_stream_source_freq,
......
...@@ -638,11 +638,11 @@ void draw_primitive(struct wined3d_device *device, UINT start_idx, UINT index_co ...@@ -638,11 +638,11 @@ void draw_primitive(struct wined3d_device *device, UINT start_idx, UINT index_co
* Z-compare function into account, but we could skip loading the * Z-compare function into account, but we could skip loading the
* depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note * depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note
* that we never copy the stencil data.*/ * that we never copy the stencil data.*/
DWORD location = context->render_offscreen ? device->fb.depth_stencil->container->resource.draw_binding DWORD location = context->render_offscreen ? device->fb.depth_stencil->resource->draw_binding
: WINED3D_LOCATION_DRAWABLE; : WINED3D_LOCATION_DRAWABLE;
if (state->render_states[WINED3D_RS_ZWRITEENABLE] || state->render_states[WINED3D_RS_ZENABLE]) if (state->render_states[WINED3D_RS_ZWRITEENABLE] || state->render_states[WINED3D_RS_ZENABLE])
{ {
struct wined3d_surface *ds = device->fb.depth_stencil; struct wined3d_surface *ds = wined3d_rendertarget_view_get_surface(device->fb.depth_stencil);
RECT current_rect, draw_rect, r; RECT current_rect, draw_rect, r;
if (!context->render_offscreen && ds != device->onscreen_depth_stencil) if (!context->render_offscreen && ds != device->onscreen_depth_stencil)
...@@ -670,7 +670,7 @@ void draw_primitive(struct wined3d_device *device, UINT start_idx, UINT index_co ...@@ -670,7 +670,7 @@ void draw_primitive(struct wined3d_device *device, UINT start_idx, UINT index_co
if (device->fb.depth_stencil && state->render_states[WINED3D_RS_ZWRITEENABLE]) if (device->fb.depth_stencil && state->render_states[WINED3D_RS_ZWRITEENABLE])
{ {
struct wined3d_surface *ds = device->fb.depth_stencil; struct wined3d_surface *ds = wined3d_rendertarget_view_get_surface(device->fb.depth_stencil);
DWORD location = context->render_offscreen ? ds->container->resource.draw_binding : WINED3D_LOCATION_DRAWABLE; DWORD location = context->render_offscreen ? ds->container->resource.draw_binding : WINED3D_LOCATION_DRAWABLE;
surface_modify_ds_location(ds, location, ds->ds_current_size.cx, ds->ds_current_size.cy); surface_modify_ds_location(ds, location, ds->ds_current_size.cx, ds->ds_current_size.cy);
......
...@@ -1765,7 +1765,7 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3 ...@@ -1765,7 +1765,7 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3
if (state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS] if (state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS]
|| state->render_states[WINED3D_RS_DEPTHBIAS]) || state->render_states[WINED3D_RS_DEPTHBIAS])
{ {
const struct wined3d_surface *depth = state->fb->depth_stencil; const struct wined3d_rendertarget_view *depth = state->fb->depth_stencil;
float scale; float scale;
union union
...@@ -1790,7 +1790,7 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3 ...@@ -1790,7 +1790,7 @@ static void state_depthbias(struct wined3d_context *context, const struct wined3
{ {
if (depth) if (depth)
{ {
const struct wined3d_format *fmt = depth->resource.format; const struct wined3d_format *fmt = depth->format;
scale = powf(2, fmt->depth_size) - 1; scale = powf(2, fmt->depth_size) - 1;
TRACE("Depth format %s, using depthbias scale of %.8e.\n", TRACE("Depth format %s, using depthbias scale of %.8e.\n",
debug_d3dformat(fmt->id), scale); debug_d3dformat(fmt->id), scale);
......
...@@ -4923,13 +4923,22 @@ static HRESULT ffp_blit_color_fill(struct wined3d_device *device, struct wined3d ...@@ -4923,13 +4923,22 @@ static HRESULT ffp_blit_color_fill(struct wined3d_device *device, struct wined3d
return WINED3D_OK; return WINED3D_OK;
} }
static HRESULT ffp_blit_depth_fill(struct wined3d_device *device, static HRESULT ffp_blit_depth_fill(struct wined3d_device *device, struct wined3d_surface *dst_surface,
struct wined3d_surface *surface, const RECT *rect, float depth) const RECT *dst_rect, float depth)
{ {
const RECT draw_rect = {0, 0, surface->resource.width, surface->resource.height}; const RECT draw_rect = {0, 0, dst_surface->resource.width, dst_surface->resource.height};
struct wined3d_fb_state fb = {NULL, surface}; struct wined3d_fb_state fb = {NULL, NULL};
HRESULT hr;
if (FAILED(hr = wined3d_rendertarget_view_create_from_surface(dst_surface,
NULL, &wined3d_null_parent_ops, &fb.depth_stencil)))
{
ERR("Failed to create rendertarget view, hr %#x.\n", hr);
return hr;
}
device_clear_render_targets(device, 0, &fb, 1, rect, &draw_rect, WINED3DCLEAR_ZBUFFER, 0, depth, 0); device_clear_render_targets(device, 0, &fb, 1, dst_rect, &draw_rect, WINED3DCLEAR_ZBUFFER, 0, depth, 0);
wined3d_rendertarget_view_decref(fb.depth_stencil);
return WINED3D_OK; return WINED3D_OK;
} }
......
...@@ -597,13 +597,14 @@ static void swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT ...@@ -597,13 +597,14 @@ static void swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT
if (fb->depth_stencil) if (fb->depth_stencil)
{ {
if (swapchain->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL struct wined3d_surface *ds = wined3d_rendertarget_view_get_surface(fb->depth_stencil);
|| fb->depth_stencil->flags & SFLAG_DISCARD)
if (ds && (swapchain->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
|| ds->flags & SFLAG_DISCARD))
{ {
surface_modify_ds_location(fb->depth_stencil, WINED3D_LOCATION_DISCARDED, surface_modify_ds_location(ds, WINED3D_LOCATION_DISCARDED,
fb->depth_stencil->resource.width, fb->depth_stencil->width, fb->depth_stencil->height);
fb->depth_stencil->resource.height); if (ds == swapchain->device->onscreen_depth_stencil)
if (fb->depth_stencil == swapchain->device->onscreen_depth_stencil)
{ {
wined3d_surface_decref(swapchain->device->onscreen_depth_stencil); wined3d_surface_decref(swapchain->device->onscreen_depth_stencil);
swapchain->device->onscreen_depth_stencil = NULL; swapchain->device->onscreen_depth_stencil = NULL;
...@@ -982,15 +983,26 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3 ...@@ -982,15 +983,26 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3
if (desc->enable_auto_depth_stencil && !(device->wined3d->flags & WINED3D_NO3D)) if (desc->enable_auto_depth_stencil && !(device->wined3d->flags & WINED3D_NO3D))
{ {
TRACE("Creating depth/stencil buffer.\n"); TRACE("Creating depth/stencil buffer.\n");
if (!device->auto_depth_stencil) if (!device->auto_depth_stencil_view)
{ {
struct wined3d_surface *ds;
surface_desc.format = swapchain->desc.auto_depth_stencil_format; surface_desc.format = swapchain->desc.auto_depth_stencil_format;
surface_desc.usage = WINED3DUSAGE_DEPTHSTENCIL; surface_desc.usage = WINED3DUSAGE_DEPTHSTENCIL;
if (FAILED(hr = device->device_parent->ops->create_swapchain_surface(device->device_parent, if (FAILED(hr = device->device_parent->ops->create_swapchain_surface(device->device_parent,
device->device_parent, &surface_desc, &device->auto_depth_stencil))) device->device_parent, &surface_desc, &ds)))
{
WARN("Failed to create the auto depth/stencil surface, hr %#x.\n", hr);
goto err;
}
hr = wined3d_rendertarget_view_create_from_surface(ds,
NULL, &wined3d_null_parent_ops, &device->auto_depth_stencil_view);
wined3d_surface_decref(ds);
if (FAILED(hr))
{ {
WARN("Failed to create the auto depth stencil, hr %#x.\n", hr); ERR("Failed to create rendertarget view, hr %#x.\n", hr);
goto err; goto err;
} }
} }
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
@ cdecl wined3d_device_get_clip_plane(ptr long ptr) @ cdecl wined3d_device_get_clip_plane(ptr long ptr)
@ cdecl wined3d_device_get_clip_status(ptr ptr) @ cdecl wined3d_device_get_clip_status(ptr ptr)
@ cdecl wined3d_device_get_creation_parameters(ptr ptr) @ cdecl wined3d_device_get_creation_parameters(ptr ptr)
@ cdecl wined3d_device_get_depth_stencil(ptr) @ cdecl wined3d_device_get_depth_stencil_view(ptr)
@ cdecl wined3d_device_get_device_caps(ptr ptr) @ cdecl wined3d_device_get_device_caps(ptr ptr)
@ cdecl wined3d_device_get_display_mode(ptr long ptr ptr) @ cdecl wined3d_device_get_display_mode(ptr long ptr ptr)
@ cdecl wined3d_device_get_front_buffer_data(ptr long ptr) @ cdecl wined3d_device_get_front_buffer_data(ptr long ptr)
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
@ cdecl wined3d_device_set_clip_status(ptr ptr) @ cdecl wined3d_device_set_clip_status(ptr ptr)
@ cdecl wined3d_device_set_cursor_position(ptr long long long) @ cdecl wined3d_device_set_cursor_position(ptr long long long)
@ cdecl wined3d_device_set_cursor_properties(ptr long long ptr) @ cdecl wined3d_device_set_cursor_properties(ptr long long ptr)
@ cdecl wined3d_device_set_depth_stencil(ptr ptr) @ cdecl wined3d_device_set_depth_stencil_view(ptr ptr)
@ cdecl wined3d_device_set_dialog_box_mode(ptr long) @ cdecl wined3d_device_set_dialog_box_mode(ptr long)
@ cdecl wined3d_device_set_gamma_ramp(ptr long long ptr) @ cdecl wined3d_device_set_gamma_ramp(ptr long long ptr)
@ cdecl wined3d_device_set_geometry_shader(ptr ptr) @ cdecl wined3d_device_set_geometry_shader(ptr ptr)
......
...@@ -1176,7 +1176,7 @@ struct wined3d_context ...@@ -1176,7 +1176,7 @@ struct wined3d_context
struct wined3d_fb_state struct wined3d_fb_state
{ {
struct wined3d_rendertarget_view **render_targets; struct wined3d_rendertarget_view **render_targets;
struct wined3d_surface *depth_stencil; struct wined3d_rendertarget_view *depth_stencil;
}; };
typedef void (*APPLYSTATEFUNC)(struct wined3d_context *ctx, const struct wined3d_state *state, DWORD state_id); typedef void (*APPLYSTATEFUNC)(struct wined3d_context *ctx, const struct wined3d_state *state, DWORD state_id);
...@@ -1955,7 +1955,7 @@ struct wined3d_device ...@@ -1955,7 +1955,7 @@ struct wined3d_device
/* Render Target Support */ /* Render Target Support */
struct wined3d_fb_state fb; struct wined3d_fb_state fb;
struct wined3d_surface *onscreen_depth_stencil; struct wined3d_surface *onscreen_depth_stencil;
struct wined3d_surface *auto_depth_stencil; struct wined3d_rendertarget_view *auto_depth_stencil_view;
/* For rendering to a texture using glCopyTexImage */ /* For rendering to a texture using glCopyTexImage */
GLuint depth_blt_texture; GLuint depth_blt_texture;
...@@ -2506,7 +2506,8 @@ void wined3d_cs_emit_set_clip_plane(struct wined3d_cs *cs, UINT plane_idx, ...@@ -2506,7 +2506,8 @@ void wined3d_cs_emit_set_clip_plane(struct wined3d_cs *cs, UINT plane_idx,
const struct wined3d_vec4 *plane) DECLSPEC_HIDDEN; const struct wined3d_vec4 *plane) DECLSPEC_HIDDEN;
void wined3d_cs_emit_set_constant_buffer(struct wined3d_cs *cs, enum wined3d_shader_type type, void wined3d_cs_emit_set_constant_buffer(struct wined3d_cs *cs, enum wined3d_shader_type type,
UINT cb_idx, struct wined3d_buffer *buffer) DECLSPEC_HIDDEN; UINT cb_idx, struct wined3d_buffer *buffer) DECLSPEC_HIDDEN;
void wined3d_cs_emit_set_depth_stencil(struct wined3d_cs *cs, struct wined3d_surface *depth_stencil) DECLSPEC_HIDDEN; void wined3d_cs_emit_set_depth_stencil_view(struct wined3d_cs *cs,
struct wined3d_rendertarget_view *view) DECLSPEC_HIDDEN;
void wined3d_cs_emit_set_index_buffer(struct wined3d_cs *cs, struct wined3d_buffer *buffer, void wined3d_cs_emit_set_index_buffer(struct wined3d_cs *cs, struct wined3d_buffer *buffer,
enum wined3d_format_id format_id) DECLSPEC_HIDDEN; enum wined3d_format_id format_id) DECLSPEC_HIDDEN;
void wined3d_cs_emit_set_material(struct wined3d_cs *cs, const struct wined3d_material *material) DECLSPEC_HIDDEN; void wined3d_cs_emit_set_material(struct wined3d_cs *cs, const struct wined3d_material *material) DECLSPEC_HIDDEN;
......
...@@ -2122,7 +2122,7 @@ HRESULT __cdecl wined3d_device_get_clip_status(const struct wined3d_device *devi ...@@ -2122,7 +2122,7 @@ HRESULT __cdecl wined3d_device_get_clip_status(const struct wined3d_device *devi
struct wined3d_clip_status *clip_status); struct wined3d_clip_status *clip_status);
void __cdecl wined3d_device_get_creation_parameters(const struct wined3d_device *device, void __cdecl wined3d_device_get_creation_parameters(const struct wined3d_device *device,
struct wined3d_device_creation_parameters *creation_parameters); struct wined3d_device_creation_parameters *creation_parameters);
struct wined3d_surface * __cdecl wined3d_device_get_depth_stencil(const struct wined3d_device *device); struct wined3d_rendertarget_view * __cdecl wined3d_device_get_depth_stencil_view(const struct wined3d_device *device);
HRESULT __cdecl wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps); HRESULT __cdecl wined3d_device_get_device_caps(const struct wined3d_device *device, WINED3DCAPS *caps);
HRESULT __cdecl wined3d_device_get_display_mode(const struct wined3d_device *device, UINT swapchain_idx, HRESULT __cdecl wined3d_device_get_display_mode(const struct wined3d_device *device, UINT swapchain_idx,
struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation); struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation);
...@@ -2210,7 +2210,8 @@ void __cdecl wined3d_device_set_cursor_position(struct wined3d_device *device, ...@@ -2210,7 +2210,8 @@ void __cdecl wined3d_device_set_cursor_position(struct wined3d_device *device,
int x_screen_space, int y_screen_space, DWORD flags); int x_screen_space, int y_screen_space, DWORD flags);
HRESULT __cdecl wined3d_device_set_cursor_properties(struct wined3d_device *device, HRESULT __cdecl wined3d_device_set_cursor_properties(struct wined3d_device *device,
UINT x_hotspot, UINT y_hotspot, struct wined3d_surface *cursor_surface); UINT x_hotspot, UINT y_hotspot, struct wined3d_surface *cursor_surface);
void __cdecl wined3d_device_set_depth_stencil(struct wined3d_device *device, struct wined3d_surface *depth_stencil); void __cdecl wined3d_device_set_depth_stencil_view(struct wined3d_device *device,
struct wined3d_rendertarget_view *view);
HRESULT __cdecl wined3d_device_set_dialog_box_mode(struct wined3d_device *device, BOOL enable_dialogs); HRESULT __cdecl wined3d_device_set_dialog_box_mode(struct wined3d_device *device, BOOL enable_dialogs);
void __cdecl wined3d_device_set_gamma_ramp(const struct wined3d_device *device, void __cdecl wined3d_device_set_gamma_ramp(const struct wined3d_device *device,
UINT swapchain_idx, DWORD flags, const struct wined3d_gamma_ramp *ramp); UINT swapchain_idx, DWORD flags, const struct wined3d_gamma_ramp *ramp);
......
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