forked from wine-compholio/wine-staging
-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
0001-ddraw-Create-rendering-targets-in-video-memory-if-po.patch
210 lines (189 loc) · 9.42 KB
/
0001-ddraw-Create-rendering-targets-in-video-memory-if-po.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
From 599d50340aaf37f2eb39a789a4034e677d52e92c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Wed, 29 Jul 2015 17:09:50 +0200
Subject: [PATCH] ddraw: Create rendering targets in video memory if possible.
Based on a patch by Henri Verbeet.
---
dlls/ddraw/ddraw.c | 6 +++---
dlls/ddraw/ddraw_private.h | 3 ++-
dlls/ddraw/device.c | 23 ++++++++++++++---------
dlls/ddraw/surface.c | 36 ++++++++++++++++++++++++++++++++++--
4 files changed, 53 insertions(+), 15 deletions(-)
diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index 6b2abe3..dfd52a0 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -4209,7 +4209,7 @@ static HRESULT WINAPI d3d7_CreateDevice(IDirect3D7 *iface, REFCLSID riid,
TRACE("iface %p, riid %s, surface %p, device %p.\n", iface, debugstr_guid(riid), surface, device);
wined3d_mutex_lock();
- if (SUCCEEDED(hr = d3d_device_create(ddraw, target, (IUnknown *)surface, 7, &object, NULL)))
+ if (SUCCEEDED(hr = d3d_device_create(ddraw, riid, target, (IUnknown *)surface, 7, &object, NULL)))
{
*device = &object->IDirect3DDevice7_iface;
}
@@ -4238,7 +4238,7 @@ static HRESULT WINAPI d3d3_CreateDevice(IDirect3D3 *iface, REFCLSID riid,
return CLASS_E_NOAGGREGATION;
wined3d_mutex_lock();
- if (SUCCEEDED(hr = d3d_device_create(ddraw, surface_impl, (IUnknown *)surface, 3, &device_impl, NULL)))
+ if (SUCCEEDED(hr = d3d_device_create(ddraw, riid, surface_impl, (IUnknown *)surface, 3, &device_impl, NULL)))
{
*device = &device_impl->IDirect3DDevice3_iface;
}
@@ -4264,7 +4264,7 @@ static HRESULT WINAPI d3d2_CreateDevice(IDirect3D2 *iface, REFCLSID riid,
iface, debugstr_guid(riid), surface, device);
wined3d_mutex_lock();
- if (SUCCEEDED(hr = d3d_device_create(ddraw, surface_impl, (IUnknown *)surface, 2, &device_impl, NULL)))
+ if (SUCCEEDED(hr = d3d_device_create(ddraw, riid, surface_impl, (IUnknown *)surface, 2, &device_impl, NULL)))
{
*device = &device_impl->IDirect3DDevice2_iface;
}
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index b035a7e..699f719 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -303,6 +303,7 @@ struct d3d_device
IUnknown IUnknown_inner;
LONG ref;
UINT version;
+ BOOL hw;
IUnknown *outer_unknown;
struct wined3d_device *wined3d_device;
@@ -347,7 +348,7 @@ struct d3d_device
struct wined3d_vec4 user_clip_planes[D3DMAXUSERCLIPPLANES];
};
-HRESULT d3d_device_create(struct ddraw *ddraw, struct ddraw_surface *target, IUnknown *rt_iface,
+HRESULT d3d_device_create(struct ddraw *ddraw, const GUID *guid, struct ddraw_surface *target, IUnknown *rt_iface,
UINT version, struct d3d_device **device, IUnknown *outer_unknown) DECLSPEC_HIDDEN;
enum wined3d_depth_buffer_type d3d_device_update_depth_stencil(struct d3d_device *device) DECLSPEC_HIDDEN;
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index 0d48c7d..2bef17d 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -1854,7 +1854,7 @@ static HRESULT d3d_device7_SetRenderTarget(IDirect3DDevice7 *iface,
return DDERR_INVALIDCAPS;
}
- if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
+ if (device->hw && !(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
{
WARN("Surface %p is not in video memory.\n", target_impl);
wined3d_mutex_unlock();
@@ -1930,7 +1930,7 @@ static HRESULT WINAPI d3d_device3_SetRenderTarget(IDirect3DDevice3 *iface,
return DDERR_INVALIDPIXELFORMAT;
}
- if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
+ if (device->hw && !(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
{
WARN("Surface %p is not in video memory.\n", target_impl);
IDirectDrawSurface4_AddRef(target);
@@ -1979,7 +1979,7 @@ static HRESULT WINAPI d3d_device2_SetRenderTarget(IDirect3DDevice2 *iface,
return DDERR_INVALIDPIXELFORMAT;
}
- if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
+ if (device->hw && !(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
{
WARN("Surface %p is not in video memory.\n", target_impl);
IDirectDrawSurface_AddRef(target);
@@ -6891,7 +6891,7 @@ enum wined3d_depth_buffer_type d3d_device_update_depth_stencil(struct d3d_device
return WINED3D_ZB_TRUE;
}
-static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw,
+static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw, BOOL hw,
struct ddraw_surface *target, IUnknown *rt_iface, UINT version, IUnknown *outer_unknown)
{
static const D3DMATRIX ident =
@@ -6914,6 +6914,7 @@ static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw,
device->IUnknown_inner.lpVtbl = &d3d_device_inner_vtbl;
device->ref = 1;
device->version = version;
+ device->hw = hw;
if (outer_unknown)
device->outer_unknown = outer_unknown;
@@ -6964,14 +6965,18 @@ static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw,
return D3D_OK;
}
-HRESULT d3d_device_create(struct ddraw *ddraw, struct ddraw_surface *target, IUnknown *rt_iface,
+HRESULT d3d_device_create(struct ddraw *ddraw, const GUID *guid, struct ddraw_surface *target, IUnknown *rt_iface,
UINT version, struct d3d_device **device, IUnknown *outer_unknown)
{
struct d3d_device *object;
+ BOOL hw = TRUE;
HRESULT hr;
- TRACE("ddraw %p, target %p, version %u, device %p, outer_unknown %p.\n",
- ddraw, target, version, device, outer_unknown);
+ TRACE("ddraw %p, guid %s, target %p, version %u, device %p, outer_unknown %p.\n",
+ ddraw, debugstr_guid(guid), target, version, device, outer_unknown);
+
+ if (IsEqualGUID(guid, &IID_IDirect3DRGBDevice))
+ hw = FALSE;
if (!(target->surface_desc.ddsCaps.dwCaps & DDSCAPS_3DDEVICE)
|| (target->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
@@ -6994,7 +6999,7 @@ HRESULT d3d_device_create(struct ddraw *ddraw, struct ddraw_surface *target, IUn
return DDERR_OUTOFMEMORY;
}
- if (!(target->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
+ if (hw && !(target->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
{
WARN("Surface %p is not in video memory.\n", target);
return D3DERR_SURFACENOTINVIDMEM;
@@ -7012,7 +7017,7 @@ HRESULT d3d_device_create(struct ddraw *ddraw, struct ddraw_surface *target, IUn
return DDERR_OUTOFMEMORY;
}
- if (FAILED(hr = d3d_device_init(object, ddraw, target, rt_iface, version, outer_unknown)))
+ if (FAILED(hr = d3d_device_init(object, ddraw, hw, target, rt_iface, version, outer_unknown)))
{
WARN("Failed to initialize device, hr %#x.\n", hr);
heap_free(object);
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 8190442..c73981b 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -226,7 +226,7 @@ static HRESULT WINAPI ddraw_surface7_QueryInterface(IDirectDrawSurface7 *iface,
{
HRESULT hr;
- if (FAILED(hr = d3d_device_create(This->ddraw, This, (IUnknown *)&This->IDirectDrawSurface_iface,
+ if (FAILED(hr = d3d_device_create(This->ddraw, riid, This, (IUnknown *)&This->IDirectDrawSurface_iface,
1, &This->device1, (IUnknown *)&This->IDirectDrawSurface_iface)))
{
This->device1 = NULL;
@@ -6162,7 +6162,39 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
if (desc->ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
{
- wined3d_desc.access = WINED3D_RESOURCE_ACCESS_CPU
+ unsigned int bind_flags = 0;
+
+ if (desc->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP)
+ {
+ bind_flags |= WINED3D_BIND_SHADER_RESOURCE;
+ }
+ else if (desc->ddsCaps.dwCaps & DDSCAPS_TEXTURE)
+ {
+ bind_flags |= WINED3D_BIND_SHADER_RESOURCE;
+ }
+
+ if (desc->ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
+ bind_flags |= WINED3D_BIND_DEPTH_STENCIL;
+ else if (desc->ddsCaps.dwCaps & DDSCAPS_3DDEVICE)
+ bind_flags |= WINED3D_BIND_RENDER_TARGET;
+ /*
+ * The ddraw RGB device allows to use system memory surfaces as rendering target.
+ * This does not cause problems because the RGB device does software rasterization
+ * though it will fail with hardware accelerated ddraw. In order to be partially
+ * compatible with games requesting explicitly the RGB device, we ignore the
+ * specified location and try to create rendering targets in video memory if
+ * possible.
+ */
+ if ((desc->ddsCaps.dwCaps & DDSCAPS_3DDEVICE) &&
+ SUCCEEDED(hr = wined3d_check_device_format(ddraw->wined3d, WINED3DADAPTER_DEFAULT,
+ WINED3D_DEVICE_TYPE_HAL, mode.format_id, 0,
+ bind_flags, WINED3D_RTYPE_TEXTURE_2D, wined3d_desc.format)))
+ {
+ FIXME("Application wants to create rendering target in system memory, using video memory instead\n");
+ wined3d_desc.bind_flags = bind_flags;
+ }
+ else
+ wined3d_desc.access = WINED3D_RESOURCE_ACCESS_CPU
| WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
}
else
--
1.9.1