2 * IDirect3DDevice8 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2004 Christian Costa
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
35 #include "d3d8_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
39 D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format)
41 BYTE *c = (BYTE *)&format;
43 /* Don't translate FOURCC formats */
44 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
48 case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
49 case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
50 case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
51 case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
52 case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
53 case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
54 case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
55 case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
56 case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
57 case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
58 case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
59 case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
60 case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
61 case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
62 case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
63 case WINED3DFMT_P8_UINT: return D3DFMT_P8;
64 case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
65 case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
66 case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
67 case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
68 case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
69 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
70 case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
71 case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
72 case WINED3DFMT_R10G11B11_SNORM: return D3DFMT_W11V11U10;
73 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
74 case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
75 case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
76 case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
77 case WINED3DFMT_D24_UNORM_S8_UINT: return D3DFMT_D24S8;
78 case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
79 case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
80 case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
81 case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
82 case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
83 case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
85 FIXME("Unhandled wined3d format %#x.\n", format);
86 return D3DFMT_UNKNOWN;
90 enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format)
92 BYTE *c = (BYTE *)&format;
94 /* Don't translate FOURCC formats */
95 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
99 case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
100 case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
101 case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
102 case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
103 case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
104 case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
105 case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
106 case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
107 case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
108 case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
109 case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
110 case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
111 case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
112 case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
113 case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
114 case D3DFMT_P8: return WINED3DFMT_P8_UINT;
115 case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
116 case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
117 case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
118 case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
119 case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
120 case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
121 case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
122 case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
123 case D3DFMT_W11V11U10: return WINED3DFMT_R10G11B11_SNORM;
124 case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
125 case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
126 case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
127 case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
128 case D3DFMT_D24S8: return WINED3DFMT_D24_UNORM_S8_UINT;
129 case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
130 case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
131 case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
132 case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
133 case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
134 case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
136 FIXME("Unhandled D3DFORMAT %#x\n", format);
137 return WINED3DFMT_UNKNOWN;
141 static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
143 switch(primitive_type)
145 case D3DPT_POINTLIST:
146 return primitive_count;
149 return primitive_count * 2;
151 case D3DPT_LINESTRIP:
152 return primitive_count + 1;
154 case D3DPT_TRIANGLELIST:
155 return primitive_count * 3;
157 case D3DPT_TRIANGLESTRIP:
158 case D3DPT_TRIANGLEFAN:
159 return primitive_count + 2;
162 FIXME("Unhandled primitive type %#x\n", primitive_type);
167 /* Handle table functions */
168 static DWORD d3d8_allocate_handle(struct d3d8_handle_table *t, void *object, enum d3d8_handle_type type)
170 struct d3d8_handle_entry *entry;
174 DWORD index = t->free_entries - t->entries;
175 /* Use a free handle */
176 entry = t->free_entries;
177 if (entry->type != D3D8_HANDLE_FREE)
179 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", index, entry, entry->type);
180 return D3D8_INVALID_HANDLE;
182 t->free_entries = entry->object;
183 entry->object = object;
189 if (!(t->entry_count < t->table_size))
192 UINT new_size = t->table_size + (t->table_size >> 1);
193 struct d3d8_handle_entry *new_entries = HeapReAlloc(GetProcessHeap(),
194 0, t->entries, new_size * sizeof(*t->entries));
197 ERR("Failed to grow the handle table.\n");
198 return D3D8_INVALID_HANDLE;
200 t->entries = new_entries;
201 t->table_size = new_size;
204 entry = &t->entries[t->entry_count];
205 entry->object = object;
208 return t->entry_count++;
211 static void *d3d8_free_handle(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
213 struct d3d8_handle_entry *entry;
216 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
218 WARN("Invalid handle %u passed.\n", handle);
222 entry = &t->entries[handle];
223 if (entry->type != type)
225 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
229 object = entry->object;
230 entry->object = t->free_entries;
231 entry->type = D3D8_HANDLE_FREE;
232 t->free_entries = entry;
237 static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
239 struct d3d8_handle_entry *entry;
241 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
243 WARN("Invalid handle %u passed.\n", handle);
247 entry = &t->entries[handle];
248 if (entry->type != type)
250 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
254 return entry->object;
257 static inline struct d3d8_device *impl_from_IDirect3DDevice8(IDirect3DDevice8 *iface)
259 return CONTAINING_RECORD(iface, struct d3d8_device, IDirect3DDevice8_iface);
262 static HRESULT WINAPI d3d8_device_QueryInterface(IDirect3DDevice8 *iface, REFIID riid, void **out)
264 TRACE("iface %p, riid %s, out %p.\n",
265 iface, debugstr_guid(riid), out);
267 if (IsEqualGUID(riid, &IID_IDirect3DDevice8)
268 || IsEqualGUID(riid, &IID_IUnknown))
270 IUnknown_AddRef(iface);
275 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
278 return E_NOINTERFACE;
281 static ULONG WINAPI d3d8_device_AddRef(IDirect3DDevice8 *iface)
283 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
284 ULONG ref = InterlockedIncrement(&device->ref);
286 TRACE("%p increasing refcount to %u.\n", iface, ref);
291 static ULONG WINAPI d3d8_device_Release(IDirect3DDevice8 *iface)
293 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
296 if (device->inDestruction)
299 ref = InterlockedDecrement(&device->ref);
301 TRACE("%p decreasing refcount to %u.\n", iface, ref);
305 IDirect3D8 *parent = device->d3d_parent;
308 TRACE("Releasing wined3d device %p.\n", device->wined3d_device);
310 wined3d_mutex_lock();
312 device->inDestruction = TRUE;
314 for (i = 0; i < device->numConvertedDecls; ++i)
316 d3d8_vertex_declaration_destroy(device->decls[i].declaration);
318 HeapFree(GetProcessHeap(), 0, device->decls);
320 wined3d_device_uninit_3d(device->wined3d_device);
321 wined3d_device_release_focus_window(device->wined3d_device);
322 wined3d_device_decref(device->wined3d_device);
323 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
324 HeapFree(GetProcessHeap(), 0, device);
326 wined3d_mutex_unlock();
328 IDirect3D8_Release(parent);
333 static HRESULT WINAPI d3d8_device_TestCooperativeLevel(IDirect3DDevice8 *iface)
335 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
337 TRACE("iface %p.\n", iface);
341 TRACE("Device is lost.\n");
342 return D3DERR_DEVICENOTRESET;
348 static UINT WINAPI d3d8_device_GetAvailableTextureMem(IDirect3DDevice8 *iface)
350 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
353 TRACE("iface %p.\n", iface);
355 wined3d_mutex_lock();
356 hr = wined3d_device_get_available_texture_mem(device->wined3d_device);
357 wined3d_mutex_unlock();
362 static HRESULT WINAPI d3d8_device_ResourceManagerDiscardBytes(IDirect3DDevice8 *iface, DWORD byte_count)
364 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
366 TRACE("iface %p, byte_count %u.\n", iface, byte_count);
369 FIXME("Byte count ignored.\n");
371 wined3d_mutex_lock();
372 wined3d_device_evict_managed_resources(device->wined3d_device);
373 wined3d_mutex_unlock();
378 static HRESULT WINAPI d3d8_device_GetDirect3D(IDirect3DDevice8 *iface, IDirect3D8 **d3d8)
380 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
382 TRACE("iface %p, d3d8 %p.\n", iface, d3d8);
385 return D3DERR_INVALIDCALL;
387 return IDirect3D8_QueryInterface(device->d3d_parent, &IID_IDirect3D8, (void **)d3d8);
390 static HRESULT WINAPI d3d8_device_GetDeviceCaps(IDirect3DDevice8 *iface, D3DCAPS8 *caps)
392 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
393 WINED3DCAPS *wined3d_caps;
396 TRACE("iface %p, caps %p.\n", iface, caps);
399 return D3DERR_INVALIDCALL;
401 if (!(wined3d_caps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wined3d_caps))))
402 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
404 wined3d_mutex_lock();
405 hr = wined3d_device_get_device_caps(device->wined3d_device, wined3d_caps);
406 wined3d_mutex_unlock();
408 fixup_caps(wined3d_caps);
409 WINECAPSTOD3D8CAPS(caps, wined3d_caps)
410 HeapFree(GetProcessHeap(), 0, wined3d_caps);
415 static HRESULT WINAPI d3d8_device_GetDisplayMode(IDirect3DDevice8 *iface, D3DDISPLAYMODE *mode)
417 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
420 TRACE("iface %p, mode %p.\n", iface, mode);
422 wined3d_mutex_lock();
423 hr = wined3d_device_get_display_mode(device->wined3d_device, 0, (struct wined3d_display_mode *)mode);
424 wined3d_mutex_unlock();
427 mode->Format = d3dformat_from_wined3dformat(mode->Format);
432 static HRESULT WINAPI d3d8_device_GetCreationParameters(IDirect3DDevice8 *iface,
433 D3DDEVICE_CREATION_PARAMETERS *parameters)
435 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
438 TRACE("iface %p, parameters %p.\n", iface, parameters);
440 wined3d_mutex_lock();
441 hr = wined3d_device_get_creation_parameters(device->wined3d_device,
442 (struct wined3d_device_creation_parameters *)parameters);
443 wined3d_mutex_unlock();
448 static HRESULT WINAPI d3d8_device_SetCursorProperties(IDirect3DDevice8 *iface,
449 UINT hotspot_x, UINT hotspot_y, IDirect3DSurface8 *bitmap)
451 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
452 IDirect3DSurface8Impl *bitmap_impl = unsafe_impl_from_IDirect3DSurface8(bitmap);
455 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
456 iface, hotspot_x, hotspot_y, bitmap);
460 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
461 return D3DERR_INVALIDCALL;
464 wined3d_mutex_lock();
465 hr = wined3d_device_set_cursor_properties(device->wined3d_device,
466 hotspot_x, hotspot_y, bitmap_impl->wined3d_surface);
467 wined3d_mutex_unlock();
472 static void WINAPI d3d8_device_SetCursorPosition(IDirect3DDevice8 *iface, UINT x, UINT y, DWORD flags)
474 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
476 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface, x, y, flags);
478 wined3d_mutex_lock();
479 wined3d_device_set_cursor_position(device->wined3d_device, x, y, flags);
480 wined3d_mutex_unlock();
483 static BOOL WINAPI d3d8_device_ShowCursor(IDirect3DDevice8 *iface, BOOL show)
485 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
488 TRACE("iface %p, show %#x.\n", iface, show);
490 wined3d_mutex_lock();
491 ret = wined3d_device_show_cursor(device->wined3d_device, show);
492 wined3d_mutex_unlock();
497 static HRESULT WINAPI d3d8_device_CreateAdditionalSwapChain(IDirect3DDevice8 *iface,
498 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain8 **swapchain)
500 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
501 IDirect3DSwapChain8Impl *object;
504 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
505 iface, present_parameters, swapchain);
507 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
510 ERR("Failed to allocate swapchain memory.\n");
511 return E_OUTOFMEMORY;
514 hr = swapchain_init(object, device, present_parameters);
517 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
518 HeapFree(GetProcessHeap(), 0, object);
522 TRACE("Created swapchain %p.\n", object);
523 *swapchain = &object->IDirect3DSwapChain8_iface;
528 static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource)
530 struct wined3d_resource_desc desc;
532 wined3d_resource_get_desc(resource, &desc);
533 if (desc.pool == WINED3D_POOL_DEFAULT)
535 IDirect3DSurface8Impl *surface;
537 if (desc.resource_type != WINED3D_RTYPE_SURFACE)
539 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
540 return D3DERR_DEVICELOST;
543 surface = wined3d_resource_get_parent(resource);
546 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
547 return D3DERR_DEVICELOST;
550 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource);
556 static HRESULT WINAPI d3d8_device_Reset(IDirect3DDevice8 *iface,
557 D3DPRESENT_PARAMETERS *present_parameters)
559 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
560 struct wined3d_swapchain_desc swapchain_desc;
563 TRACE("iface %p, present_parameters %p.\n", iface, present_parameters);
565 wined3d_mutex_lock();
567 swapchain_desc.backbuffer_width = present_parameters->BackBufferWidth;
568 swapchain_desc.backbuffer_height = present_parameters->BackBufferHeight;
569 swapchain_desc.backbuffer_format = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
570 swapchain_desc.backbuffer_count = present_parameters->BackBufferCount;
571 swapchain_desc.multisample_type = present_parameters->MultiSampleType;
572 swapchain_desc.multisample_quality = 0; /* d3d9 only */
573 swapchain_desc.swap_effect = present_parameters->SwapEffect;
574 swapchain_desc.device_window = present_parameters->hDeviceWindow;
575 swapchain_desc.windowed = present_parameters->Windowed;
576 swapchain_desc.enable_auto_depth_stencil = present_parameters->EnableAutoDepthStencil;
577 swapchain_desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
578 swapchain_desc.flags = present_parameters->Flags;
579 swapchain_desc.refresh_rate = present_parameters->FullScreen_RefreshRateInHz;
580 swapchain_desc.swap_interval = present_parameters->FullScreen_PresentationInterval;
581 swapchain_desc.auto_restore_display_mode = TRUE;
583 if (SUCCEEDED(hr = wined3d_device_reset(device->wined3d_device, &swapchain_desc, reset_enum_callback)))
585 hr = wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0);
586 device->lost = FALSE;
592 wined3d_mutex_unlock();
597 static HRESULT WINAPI d3d8_device_Present(IDirect3DDevice8 *iface, const RECT *src_rect,
598 const RECT *dst_rect, HWND dst_window_override, const RGNDATA *dirty_region)
600 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
603 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
604 iface, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect), dst_window_override, dirty_region);
606 wined3d_mutex_lock();
607 hr = wined3d_device_present(device->wined3d_device, src_rect, dst_rect, dst_window_override, dirty_region);
608 wined3d_mutex_unlock();
613 static HRESULT WINAPI d3d8_device_GetBackBuffer(IDirect3DDevice8 *iface,
614 UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface8 **backbuffer)
616 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
617 struct wined3d_surface *wined3d_surface = NULL;
618 IDirect3DSurface8Impl *surface_impl;
621 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
622 iface, backbuffer_idx, backbuffer_type, backbuffer);
624 wined3d_mutex_lock();
625 hr = wined3d_device_get_back_buffer(device->wined3d_device, 0, backbuffer_idx,
626 (enum wined3d_backbuffer_type)backbuffer_type, &wined3d_surface);
627 if (SUCCEEDED(hr) && wined3d_surface && backbuffer)
629 surface_impl = wined3d_surface_get_parent(wined3d_surface);
630 *backbuffer = &surface_impl->IDirect3DSurface8_iface;
631 IDirect3DSurface8_AddRef(*backbuffer);
632 wined3d_surface_decref(wined3d_surface);
634 wined3d_mutex_unlock();
639 static HRESULT WINAPI d3d8_device_GetRasterStatus(IDirect3DDevice8 *iface, D3DRASTER_STATUS *raster_status)
641 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
644 TRACE("iface %p, raster_status %p.\n", iface, raster_status);
646 wined3d_mutex_lock();
647 hr = wined3d_device_get_raster_status(device->wined3d_device, 0, (struct wined3d_raster_status *)raster_status);
648 wined3d_mutex_unlock();
653 static void WINAPI d3d8_device_SetGammaRamp(IDirect3DDevice8 *iface, DWORD flags, const D3DGAMMARAMP *ramp)
655 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
657 TRACE("iface %p, flags %#x, ramp %p.\n", iface, flags, ramp);
659 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
660 wined3d_mutex_lock();
661 wined3d_device_set_gamma_ramp(device->wined3d_device, 0, flags, (const struct wined3d_gamma_ramp *)ramp);
662 wined3d_mutex_unlock();
665 static void WINAPI d3d8_device_GetGammaRamp(IDirect3DDevice8 *iface, D3DGAMMARAMP *ramp)
667 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
669 TRACE("iface %p, ramp %p.\n", iface, ramp);
671 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
672 wined3d_mutex_lock();
673 wined3d_device_get_gamma_ramp(device->wined3d_device, 0, (struct wined3d_gamma_ramp *)ramp);
674 wined3d_mutex_unlock();
677 static HRESULT WINAPI d3d8_device_CreateTexture(IDirect3DDevice8 *iface,
678 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
679 D3DPOOL pool, IDirect3DTexture8 **texture)
681 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
682 struct d3d8_texture *object;
685 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
686 iface, width, height, levels, usage, format, pool, texture);
688 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
691 ERR("Failed to allocate texture memory.\n");
692 return D3DERR_OUTOFVIDEOMEMORY;
695 hr = texture_init(object, device, width, height, levels, usage, format, pool);
698 WARN("Failed to initialize texture, hr %#x.\n", hr);
699 HeapFree(GetProcessHeap(), 0, object);
703 TRACE("Created texture %p.\n", object);
704 *texture = (IDirect3DTexture8 *)&object->IDirect3DBaseTexture8_iface;
709 static HRESULT WINAPI d3d8_device_CreateVolumeTexture(IDirect3DDevice8 *iface,
710 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
711 D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
713 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
714 struct d3d8_texture *object;
717 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
718 iface, width, height, depth, levels, usage, format, pool, texture);
720 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
723 ERR("Failed to allocate volume texture memory.\n");
724 return D3DERR_OUTOFVIDEOMEMORY;
727 hr = volumetexture_init(object, device, width, height, depth, levels, usage, format, pool);
730 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
731 HeapFree(GetProcessHeap(), 0, object);
735 TRACE("Created volume texture %p.\n", object);
736 *texture = (IDirect3DVolumeTexture8 *)&object->IDirect3DBaseTexture8_iface;
741 static HRESULT WINAPI d3d8_device_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
742 UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
744 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
745 struct d3d8_texture *object;
748 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
749 iface, edge_length, levels, usage, format, pool, texture);
751 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
754 ERR("Failed to allocate cube texture memory.\n");
755 return D3DERR_OUTOFVIDEOMEMORY;
758 hr = cubetexture_init(object, device, edge_length, levels, usage, format, pool);
761 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
762 HeapFree(GetProcessHeap(), 0, object);
766 TRACE("Created cube texture %p.\n", object);
767 *texture = (IDirect3DCubeTexture8 *)&object->IDirect3DBaseTexture8_iface;
772 static HRESULT WINAPI d3d8_device_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size,
773 DWORD usage, DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
775 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
776 IDirect3DVertexBuffer8Impl *object;
779 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
780 iface, size, usage, fvf, pool, buffer);
782 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
785 ERR("Failed to allocate buffer memory.\n");
786 return D3DERR_OUTOFVIDEOMEMORY;
789 hr = vertexbuffer_init(object, device, size, usage, fvf, pool);
792 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
793 HeapFree(GetProcessHeap(), 0, object);
797 TRACE("Created vertex buffer %p.\n", object);
798 *buffer = &object->IDirect3DVertexBuffer8_iface;
803 static HRESULT WINAPI d3d8_device_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size,
804 DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
806 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
807 struct d3d8_indexbuffer *object;
810 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
811 iface, size, usage, format, pool, buffer);
813 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
816 ERR("Failed to allocate buffer memory.\n");
817 return D3DERR_OUTOFVIDEOMEMORY;
820 hr = indexbuffer_init(object, device, size, usage, format, pool);
823 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
824 HeapFree(GetProcessHeap(), 0, object);
828 TRACE("Created index buffer %p.\n", object);
829 *buffer = &object->IDirect3DIndexBuffer8_iface;
834 static HRESULT d3d8_device_CreateSurface(struct d3d8_device *device, UINT width,
835 UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
836 IDirect3DSurface8 **surface, UINT usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type,
837 DWORD multisample_quality)
839 IDirect3DSurface8Impl *object;
842 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
843 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
844 device, width, height, format, lockable, discard, level, surface,
845 usage, pool, multisample_type, multisample_quality);
847 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
850 FIXME("Failed to allocate surface memory.\n");
851 return D3DERR_OUTOFVIDEOMEMORY;
854 hr = surface_init(object, device, width, height, format, lockable, discard, level, usage,
855 pool, multisample_type, multisample_quality);
858 WARN("Failed to initialize surface, hr %#x.\n", hr);
859 HeapFree(GetProcessHeap(), 0, object);
863 TRACE("Created surface %p.\n", object);
864 *surface = &object->IDirect3DSurface8_iface;
869 static HRESULT WINAPI d3d8_device_CreateRenderTarget(IDirect3DDevice8 *iface, UINT width,
870 UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, BOOL lockable,
871 IDirect3DSurface8 **surface)
873 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
876 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
877 iface, width, height, format, multisample_type, lockable, surface);
879 hr = d3d8_device_CreateSurface(device, width, height, format, lockable,
880 FALSE, 0, surface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT,
881 multisample_type, 0);
886 static HRESULT WINAPI d3d8_device_CreateDepthStencilSurface(IDirect3DDevice8 *iface,
887 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type,
888 IDirect3DSurface8 **surface)
890 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
893 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
894 iface, width, height, format, multisample_type, surface);
896 /* TODO: Verify that Discard is false */
897 hr = d3d8_device_CreateSurface(device, width, height, format, TRUE, FALSE,
898 0, surface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, multisample_type, 0);
903 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
904 static HRESULT WINAPI d3d8_device_CreateImageSurface(IDirect3DDevice8 *iface, UINT width,
905 UINT height, D3DFORMAT format, IDirect3DSurface8 **surface)
907 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
910 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
911 iface, width, height, format, surface);
913 hr = d3d8_device_CreateSurface(device, width, height, format, TRUE, FALSE,
914 0, surface, 0, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE, 0);
919 static HRESULT WINAPI d3d8_device_CopyRects(IDirect3DDevice8 *iface,
920 IDirect3DSurface8 *src_surface, const RECT *src_rects, UINT rect_count,
921 IDirect3DSurface8 *dst_surface, const POINT *dst_points)
923 IDirect3DSurface8Impl *src = unsafe_impl_from_IDirect3DSurface8(src_surface);
924 IDirect3DSurface8Impl *dst = unsafe_impl_from_IDirect3DSurface8(dst_surface);
925 enum wined3d_format_id src_format, dst_format;
926 struct wined3d_resource_desc wined3d_desc;
927 struct wined3d_resource *wined3d_resource;
931 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
932 iface, src_surface, src_rects, rect_count, dst_surface, dst_points);
934 /* Check that the source texture is in WINED3D_POOL_SYSTEM_MEM and the
935 * destination texture is in WINED3D_POOL_DEFAULT. */
937 wined3d_mutex_lock();
938 wined3d_resource = wined3d_surface_get_resource(src->wined3d_surface);
939 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
940 if (wined3d_desc.usage & WINED3DUSAGE_DEPTHSTENCIL)
942 WARN("Source %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", src_surface);
943 wined3d_mutex_unlock();
944 return D3DERR_INVALIDCALL;
946 src_format = wined3d_desc.format;
947 src_w = wined3d_desc.width;
948 src_h = wined3d_desc.height;
950 wined3d_resource = wined3d_surface_get_resource(dst->wined3d_surface);
951 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
952 if (wined3d_desc.usage & WINED3DUSAGE_DEPTHSTENCIL)
954 WARN("Destination %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", dst_surface);
955 wined3d_mutex_unlock();
956 return D3DERR_INVALIDCALL;
958 dst_format = wined3d_desc.format;
960 /* Check that the source and destination formats match */
961 if (src_format != dst_format && WINED3DFMT_UNKNOWN != dst_format)
963 WARN("Source %p format must match the destination %p format, returning D3DERR_INVALIDCALL.\n",
964 src_surface, dst_surface);
965 wined3d_mutex_unlock();
966 return D3DERR_INVALIDCALL;
968 else if (WINED3DFMT_UNKNOWN == dst_format)
970 TRACE("Converting destination surface from WINED3DFMT_UNKNOWN to the source format.\n");
971 if (FAILED(hr = wined3d_surface_update_desc(dst->wined3d_surface, wined3d_desc.width, wined3d_desc.height,
972 src_format, wined3d_desc.multisample_type, wined3d_desc.multisample_quality)))
974 WARN("Failed to update surface desc, hr %#x.\n", hr);
975 wined3d_mutex_unlock();
980 /* Quick if complete copy ... */
981 if (!rect_count && !src_rects && !dst_points)
983 RECT rect = {0, 0, src_w, src_h};
984 wined3d_surface_blt(dst->wined3d_surface, &rect,
985 src->wined3d_surface, &rect, 0, NULL, WINED3D_TEXF_POINT);
990 /* Copy rect by rect */
991 if (src_rects && dst_points)
993 for (i = 0; i < rect_count; ++i)
995 UINT w = src_rects[i].right - src_rects[i].left;
996 UINT h = src_rects[i].bottom - src_rects[i].top;
997 RECT dst_rect = {dst_points[i].x, dst_points[i].y,
998 dst_points[i].x + w, dst_points[i].y + h};
1000 wined3d_surface_blt(dst->wined3d_surface, &dst_rect,
1001 src->wined3d_surface, &src_rects[i], 0, NULL, WINED3D_TEXF_POINT);
1006 for (i = 0; i < rect_count; ++i)
1008 UINT w = src_rects[i].right - src_rects[i].left;
1009 UINT h = src_rects[i].bottom - src_rects[i].top;
1010 RECT dst_rect = {0, 0, w, h};
1012 wined3d_surface_blt(dst->wined3d_surface, &dst_rect,
1013 src->wined3d_surface, &src_rects[i], 0, NULL, WINED3D_TEXF_POINT);
1017 wined3d_mutex_unlock();
1022 static HRESULT WINAPI d3d8_device_UpdateTexture(IDirect3DDevice8 *iface,
1023 IDirect3DBaseTexture8 *src_texture, IDirect3DBaseTexture8 *dst_texture)
1025 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1026 struct d3d8_texture *src_impl, *dst_impl;
1029 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, src_texture, dst_texture);
1031 src_impl = unsafe_impl_from_IDirect3DBaseTexture8(src_texture);
1032 dst_impl = unsafe_impl_from_IDirect3DBaseTexture8(dst_texture);
1034 wined3d_mutex_lock();
1035 hr = wined3d_device_update_texture(device->wined3d_device,
1036 src_impl->wined3d_texture, dst_impl->wined3d_texture);
1037 wined3d_mutex_unlock();
1042 static HRESULT WINAPI d3d8_device_GetFrontBuffer(IDirect3DDevice8 *iface, IDirect3DSurface8 *dst_surface)
1044 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1045 IDirect3DSurface8Impl *dst_impl = unsafe_impl_from_IDirect3DSurface8(dst_surface);
1048 TRACE("iface %p, dst_surface %p.\n", iface, dst_surface);
1052 WARN("Invalid destination surface passed.\n");
1053 return D3DERR_INVALIDCALL;
1056 wined3d_mutex_lock();
1057 hr = wined3d_device_get_front_buffer_data(device->wined3d_device, 0, dst_impl->wined3d_surface);
1058 wined3d_mutex_unlock();
1063 static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface,
1064 IDirect3DSurface8 *render_target, IDirect3DSurface8 *depth_stencil)
1066 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1067 IDirect3DSurface8Impl *rt_impl = unsafe_impl_from_IDirect3DSurface8(render_target);
1068 IDirect3DSurface8Impl *ds_impl = unsafe_impl_from_IDirect3DSurface8(depth_stencil);
1069 struct wined3d_surface *original_ds = NULL;
1072 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, render_target, depth_stencil);
1074 wined3d_mutex_lock();
1078 struct wined3d_resource_desc ds_desc, rt_desc;
1079 struct wined3d_resource *wined3d_resource;
1080 struct wined3d_surface *original_rt = NULL;
1082 /* If no render target is passed in check the size against the current RT */
1085 hr = wined3d_device_get_render_target(device->wined3d_device, 0, &original_rt);
1086 if (FAILED(hr) || !original_rt)
1088 wined3d_mutex_unlock();
1091 wined3d_resource = wined3d_surface_get_resource(original_rt);
1092 wined3d_surface_decref(original_rt);
1095 wined3d_resource = wined3d_surface_get_resource(rt_impl->wined3d_surface);
1096 wined3d_resource_get_desc(wined3d_resource, &rt_desc);
1098 wined3d_resource = wined3d_surface_get_resource(ds_impl->wined3d_surface);
1099 wined3d_resource_get_desc(wined3d_resource, &ds_desc);
1101 if (ds_desc.width < rt_desc.width || ds_desc.height < rt_desc.height)
1103 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1104 wined3d_mutex_unlock();
1105 return D3DERR_INVALIDCALL;
1109 hr = wined3d_device_get_depth_stencil(device->wined3d_device, &original_ds);
1110 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
1112 hr = wined3d_device_set_depth_stencil(device->wined3d_device, ds_impl ? ds_impl->wined3d_surface : NULL);
1113 if (SUCCEEDED(hr) && render_target)
1115 hr = wined3d_device_set_render_target(device->wined3d_device, 0, rt_impl->wined3d_surface, TRUE);
1117 wined3d_device_set_depth_stencil(device->wined3d_device, original_ds);
1121 wined3d_surface_decref(original_ds);
1123 wined3d_mutex_unlock();
1128 static HRESULT WINAPI d3d8_device_GetRenderTarget(IDirect3DDevice8 *iface, IDirect3DSurface8 **render_target)
1130 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1131 struct wined3d_surface *wined3d_surface;
1132 IDirect3DSurface8Impl *surface_impl;
1135 TRACE("iface %p, render_target %p.\n", iface, render_target);
1138 return D3DERR_INVALIDCALL;
1140 wined3d_mutex_lock();
1141 hr = wined3d_device_get_render_target(device->wined3d_device, 0, &wined3d_surface);
1142 if (SUCCEEDED(hr) && wined3d_surface)
1144 surface_impl = wined3d_surface_get_parent(wined3d_surface);
1145 *render_target = &surface_impl->IDirect3DSurface8_iface;
1146 IDirect3DSurface8_AddRef(*render_target);
1147 wined3d_surface_decref(wined3d_surface);
1151 ERR("Failed to get wined3d render target, hr %#x.\n", hr);
1152 *render_target = NULL;
1154 wined3d_mutex_unlock();
1159 static HRESULT WINAPI d3d8_device_GetDepthStencilSurface(IDirect3DDevice8 *iface, IDirect3DSurface8 **depth_stencil)
1161 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1162 struct wined3d_surface *wined3d_surface;
1163 IDirect3DSurface8Impl *surface_impl;
1166 TRACE("iface %p, depth_stencil %p.\n", iface, depth_stencil);
1169 return D3DERR_INVALIDCALL;
1171 wined3d_mutex_lock();
1172 hr = wined3d_device_get_depth_stencil(device->wined3d_device, &wined3d_surface);
1175 surface_impl = wined3d_surface_get_parent(wined3d_surface);
1176 *depth_stencil = &surface_impl->IDirect3DSurface8_iface;
1177 IDirect3DSurface8_AddRef(*depth_stencil);
1178 wined3d_surface_decref(wined3d_surface);
1182 if (hr != WINED3DERR_NOTFOUND)
1183 ERR("Failed to get wined3d depth stencil, hr %#x.\n", hr);
1184 *depth_stencil = NULL;
1186 wined3d_mutex_unlock();
1191 static HRESULT WINAPI d3d8_device_BeginScene(IDirect3DDevice8 *iface)
1193 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1196 TRACE("iface %p.\n", iface);
1198 wined3d_mutex_lock();
1199 hr = wined3d_device_begin_scene(device->wined3d_device);
1200 wined3d_mutex_unlock();
1205 static HRESULT WINAPI DECLSPEC_HOTPATCH d3d8_device_EndScene(IDirect3DDevice8 *iface)
1207 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1210 TRACE("iface %p.\n", iface);
1212 wined3d_mutex_lock();
1213 hr = wined3d_device_end_scene(device->wined3d_device);
1214 wined3d_mutex_unlock();
1219 static HRESULT WINAPI d3d8_device_Clear(IDirect3DDevice8 *iface, DWORD rect_count,
1220 const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil)
1222 const struct wined3d_color c =
1224 ((color >> 16) & 0xff) / 255.0f,
1225 ((color >> 8) & 0xff) / 255.0f,
1226 (color & 0xff) / 255.0f,
1227 ((color >> 24) & 0xff) / 255.0f,
1229 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1232 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1233 iface, rect_count, rects, flags, color, z, stencil);
1235 wined3d_mutex_lock();
1236 hr = wined3d_device_clear(device->wined3d_device, rect_count, (const RECT *)rects, flags, &c, z, stencil);
1237 wined3d_mutex_unlock();
1242 static HRESULT WINAPI d3d8_device_SetTransform(IDirect3DDevice8 *iface,
1243 D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
1245 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1248 TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
1250 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1251 wined3d_mutex_lock();
1252 hr = wined3d_device_set_transform(device->wined3d_device, state, (const struct wined3d_matrix *)matrix);
1253 wined3d_mutex_unlock();
1258 static HRESULT WINAPI d3d8_device_GetTransform(IDirect3DDevice8 *iface,
1259 D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
1261 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1264 TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
1266 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1267 wined3d_mutex_lock();
1268 hr = wined3d_device_get_transform(device->wined3d_device, state, (struct wined3d_matrix *)matrix);
1269 wined3d_mutex_unlock();
1274 static HRESULT WINAPI d3d8_device_MultiplyTransform(IDirect3DDevice8 *iface,
1275 D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
1277 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1280 TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
1282 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1283 wined3d_mutex_lock();
1284 hr = wined3d_device_multiply_transform(device->wined3d_device, state, (const struct wined3d_matrix *)matrix);
1285 wined3d_mutex_unlock();
1290 static HRESULT WINAPI d3d8_device_SetViewport(IDirect3DDevice8 *iface, const D3DVIEWPORT8 *viewport)
1292 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1295 TRACE("iface %p, viewport %p.\n", iface, viewport);
1297 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1298 wined3d_mutex_lock();
1299 hr = wined3d_device_set_viewport(device->wined3d_device, (const struct wined3d_viewport *)viewport);
1300 wined3d_mutex_unlock();
1305 static HRESULT WINAPI d3d8_device_GetViewport(IDirect3DDevice8 *iface, D3DVIEWPORT8 *viewport)
1307 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1310 TRACE("iface %p, viewport %p.\n", iface, viewport);
1312 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1313 wined3d_mutex_lock();
1314 hr = wined3d_device_get_viewport(device->wined3d_device, (struct wined3d_viewport *)viewport);
1315 wined3d_mutex_unlock();
1320 static HRESULT WINAPI d3d8_device_SetMaterial(IDirect3DDevice8 *iface, const D3DMATERIAL8 *material)
1322 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1325 TRACE("iface %p, material %p.\n", iface, material);
1327 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1328 wined3d_mutex_lock();
1329 hr = wined3d_device_set_material(device->wined3d_device, (const struct wined3d_material *)material);
1330 wined3d_mutex_unlock();
1335 static HRESULT WINAPI d3d8_device_GetMaterial(IDirect3DDevice8 *iface, D3DMATERIAL8 *material)
1337 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1340 TRACE("iface %p, material %p.\n", iface, material);
1342 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1343 wined3d_mutex_lock();
1344 hr = wined3d_device_get_material(device->wined3d_device, (struct wined3d_material *)material);
1345 wined3d_mutex_unlock();
1350 static HRESULT WINAPI d3d8_device_SetLight(IDirect3DDevice8 *iface, DWORD index, const D3DLIGHT8 *light)
1352 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1355 TRACE("iface %p, index %u, light %p.\n", iface, index, light);
1357 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1358 wined3d_mutex_lock();
1359 hr = wined3d_device_set_light(device->wined3d_device, index, (const struct wined3d_light *)light);
1360 wined3d_mutex_unlock();
1365 static HRESULT WINAPI d3d8_device_GetLight(IDirect3DDevice8 *iface, DWORD index, D3DLIGHT8 *light)
1367 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1370 TRACE("iface %p, index %u, light %p.\n", iface, index, light);
1372 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1373 wined3d_mutex_lock();
1374 hr = wined3d_device_get_light(device->wined3d_device, index, (struct wined3d_light *)light);
1375 wined3d_mutex_unlock();
1380 static HRESULT WINAPI d3d8_device_LightEnable(IDirect3DDevice8 *iface, DWORD index, BOOL enable)
1382 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1385 TRACE("iface %p, index %u, enable %#x.\n", iface, index, enable);
1387 wined3d_mutex_lock();
1388 hr = wined3d_device_set_light_enable(device->wined3d_device, index, enable);
1389 wined3d_mutex_unlock();
1394 static HRESULT WINAPI d3d8_device_GetLightEnable(IDirect3DDevice8 *iface, DWORD index, BOOL *enable)
1396 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1399 TRACE("iface %p, index %u, enable %p.\n", iface, index, enable);
1401 wined3d_mutex_lock();
1402 hr = wined3d_device_get_light_enable(device->wined3d_device, index, enable);
1403 wined3d_mutex_unlock();
1408 static HRESULT WINAPI d3d8_device_SetClipPlane(IDirect3DDevice8 *iface, DWORD index, const float *plane)
1410 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1413 TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
1415 wined3d_mutex_lock();
1416 hr = wined3d_device_set_clip_plane(device->wined3d_device, index, plane);
1417 wined3d_mutex_unlock();
1422 static HRESULT WINAPI d3d8_device_GetClipPlane(IDirect3DDevice8 *iface, DWORD index, float *plane)
1424 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1427 TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
1429 wined3d_mutex_lock();
1430 hr = wined3d_device_get_clip_plane(device->wined3d_device, index, plane);
1431 wined3d_mutex_unlock();
1436 static HRESULT WINAPI d3d8_device_SetRenderState(IDirect3DDevice8 *iface,
1437 D3DRENDERSTATETYPE state, DWORD value)
1439 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1442 TRACE("iface %p, state %#x, value %#x.\n", iface, state, value);
1444 wined3d_mutex_lock();
1448 hr = wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DEPTHBIAS, value);
1452 hr = wined3d_device_set_render_state(device->wined3d_device, state, value);
1454 wined3d_mutex_unlock();
1459 static HRESULT WINAPI d3d8_device_GetRenderState(IDirect3DDevice8 *iface,
1460 D3DRENDERSTATETYPE state, DWORD *value)
1462 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1465 TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
1467 wined3d_mutex_lock();
1471 hr = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_DEPTHBIAS, value);
1475 hr = wined3d_device_get_render_state(device->wined3d_device, state, value);
1477 wined3d_mutex_unlock();
1482 static HRESULT WINAPI d3d8_device_BeginStateBlock(IDirect3DDevice8 *iface)
1484 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1487 TRACE("iface %p.\n", iface);
1489 wined3d_mutex_lock();
1490 hr = wined3d_device_begin_stateblock(device->wined3d_device);
1491 wined3d_mutex_unlock();
1496 static HRESULT WINAPI d3d8_device_EndStateBlock(IDirect3DDevice8 *iface, DWORD *token)
1498 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1499 struct wined3d_stateblock *stateblock;
1502 TRACE("iface %p, token %p.\n", iface, token);
1504 /* Tell wineD3D to endstateblock before anything else (in case we run out
1505 * of memory later and cause locking problems)
1507 wined3d_mutex_lock();
1508 hr = wined3d_device_end_stateblock(device->wined3d_device, &stateblock);
1511 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1512 wined3d_mutex_unlock();
1516 *token = d3d8_allocate_handle(&device->handle_table, stateblock, D3D8_HANDLE_SB);
1517 wined3d_mutex_unlock();
1519 if (*token == D3D8_INVALID_HANDLE)
1521 ERR("Failed to create a handle\n");
1522 wined3d_mutex_lock();
1523 wined3d_stateblock_decref(stateblock);
1524 wined3d_mutex_unlock();
1529 TRACE("Returning %#x (%p).\n", *token, stateblock);
1534 static HRESULT WINAPI d3d8_device_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD token)
1536 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1537 struct wined3d_stateblock *stateblock;
1540 TRACE("iface %p, token %#x.\n", iface, token);
1545 wined3d_mutex_lock();
1546 stateblock = d3d8_get_object(&device->handle_table, token - 1, D3D8_HANDLE_SB);
1549 WARN("Invalid handle (%#x) passed.\n", token);
1550 wined3d_mutex_unlock();
1551 return D3DERR_INVALIDCALL;
1553 hr = wined3d_stateblock_apply(stateblock);
1554 wined3d_mutex_unlock();
1559 static HRESULT WINAPI d3d8_device_CaptureStateBlock(IDirect3DDevice8 *iface, DWORD token)
1561 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1562 struct wined3d_stateblock *stateblock;
1565 TRACE("iface %p, token %#x.\n", iface, token);
1567 wined3d_mutex_lock();
1568 stateblock = d3d8_get_object(&device->handle_table, token - 1, D3D8_HANDLE_SB);
1571 WARN("Invalid handle (%#x) passed.\n", token);
1572 wined3d_mutex_unlock();
1573 return D3DERR_INVALIDCALL;
1575 hr = wined3d_stateblock_capture(stateblock);
1576 wined3d_mutex_unlock();
1581 static HRESULT WINAPI d3d8_device_DeleteStateBlock(IDirect3DDevice8 *iface, DWORD token)
1583 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1584 struct wined3d_stateblock *stateblock;
1586 TRACE("iface %p, token %#x.\n", iface, token);
1588 wined3d_mutex_lock();
1589 stateblock = d3d8_free_handle(&device->handle_table, token - 1, D3D8_HANDLE_SB);
1593 WARN("Invalid handle (%#x) passed.\n", token);
1594 wined3d_mutex_unlock();
1595 return D3DERR_INVALIDCALL;
1598 if (wined3d_stateblock_decref(stateblock))
1600 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
1602 wined3d_mutex_unlock();
1607 static HRESULT WINAPI d3d8_device_CreateStateBlock(IDirect3DDevice8 *iface,
1608 D3DSTATEBLOCKTYPE type, DWORD *handle)
1610 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1611 struct wined3d_stateblock *stateblock;
1614 TRACE("iface %p, type %#x, handle %p.\n", iface, type, handle);
1616 if (type != D3DSBT_ALL
1617 && type != D3DSBT_PIXELSTATE
1618 && type != D3DSBT_VERTEXSTATE)
1620 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1621 return D3DERR_INVALIDCALL;
1624 wined3d_mutex_lock();
1625 hr = wined3d_stateblock_create(device->wined3d_device, (enum wined3d_stateblock_type)type, &stateblock);
1628 wined3d_mutex_unlock();
1629 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1633 *handle = d3d8_allocate_handle(&device->handle_table, stateblock, D3D8_HANDLE_SB);
1634 wined3d_mutex_unlock();
1636 if (*handle == D3D8_INVALID_HANDLE)
1638 ERR("Failed to allocate a handle.\n");
1639 wined3d_mutex_lock();
1640 wined3d_stateblock_decref(stateblock);
1641 wined3d_mutex_unlock();
1646 TRACE("Returning %#x (%p).\n", *handle, stateblock);
1651 static HRESULT WINAPI d3d8_device_SetClipStatus(IDirect3DDevice8 *iface, const D3DCLIPSTATUS8 *clip_status)
1653 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1656 TRACE("iface %p, clip_status %p.\n", iface, clip_status);
1657 /* FIXME: Verify that D3DCLIPSTATUS8 ~= struct wined3d_clip_status. */
1659 wined3d_mutex_lock();
1660 hr = wined3d_device_set_clip_status(device->wined3d_device, (const struct wined3d_clip_status *)clip_status);
1661 wined3d_mutex_unlock();
1666 static HRESULT WINAPI d3d8_device_GetClipStatus(IDirect3DDevice8 *iface, D3DCLIPSTATUS8 *clip_status)
1668 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1671 TRACE("iface %p, clip_status %p.\n", iface, clip_status);
1673 wined3d_mutex_lock();
1674 hr = wined3d_device_get_clip_status(device->wined3d_device, (struct wined3d_clip_status *)clip_status);
1675 wined3d_mutex_unlock();
1680 static HRESULT WINAPI d3d8_device_GetTexture(IDirect3DDevice8 *iface, DWORD stage, IDirect3DBaseTexture8 **texture)
1682 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1683 struct wined3d_texture *wined3d_texture;
1684 struct d3d8_texture *texture_impl;
1687 TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
1690 return D3DERR_INVALIDCALL;
1692 wined3d_mutex_lock();
1693 hr = wined3d_device_get_texture(device->wined3d_device, stage, &wined3d_texture);
1696 WARN("Failed to get texture for stage %u, hr %#x.\n", stage, hr);
1697 wined3d_mutex_unlock();
1702 if (wined3d_texture)
1704 texture_impl = wined3d_texture_get_parent(wined3d_texture);
1705 *texture = &texture_impl->IDirect3DBaseTexture8_iface;
1706 IDirect3DBaseTexture8_AddRef(*texture);
1707 wined3d_texture_decref(wined3d_texture);
1713 wined3d_mutex_unlock();
1718 static HRESULT WINAPI d3d8_device_SetTexture(IDirect3DDevice8 *iface, DWORD stage, IDirect3DBaseTexture8 *texture)
1720 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1721 struct d3d8_texture *texture_impl;
1724 TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
1726 texture_impl = unsafe_impl_from_IDirect3DBaseTexture8(texture);
1728 wined3d_mutex_lock();
1729 hr = wined3d_device_set_texture(device->wined3d_device, stage,
1730 texture_impl ? texture_impl->wined3d_texture : NULL);
1731 wined3d_mutex_unlock();
1736 static const struct tss_lookup
1739 enum wined3d_texture_stage_state state;
1743 {FALSE, WINED3D_TSS_INVALID}, /* 0, unused */
1744 {FALSE, WINED3D_TSS_COLOR_OP}, /* 1, D3DTSS_COLOROP */
1745 {FALSE, WINED3D_TSS_COLOR_ARG1}, /* 2, D3DTSS_COLORARG1 */
1746 {FALSE, WINED3D_TSS_COLOR_ARG2}, /* 3, D3DTSS_COLORARG2 */
1747 {FALSE, WINED3D_TSS_ALPHA_OP}, /* 4, D3DTSS_ALPHAOP */
1748 {FALSE, WINED3D_TSS_ALPHA_ARG1}, /* 5, D3DTSS_ALPHAARG1 */
1749 {FALSE, WINED3D_TSS_ALPHA_ARG2}, /* 6, D3DTSS_ALPHAARG2 */
1750 {FALSE, WINED3D_TSS_BUMPENV_MAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1751 {FALSE, WINED3D_TSS_BUMPENV_MAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1752 {FALSE, WINED3D_TSS_BUMPENV_MAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1753 {FALSE, WINED3D_TSS_BUMPENV_MAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1754 {FALSE, WINED3D_TSS_TEXCOORD_INDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1755 {FALSE, WINED3D_TSS_INVALID}, /* 12, unused */
1756 {TRUE, WINED3D_SAMP_ADDRESS_U}, /* 13, D3DTSS_ADDRESSU */
1757 {TRUE, WINED3D_SAMP_ADDRESS_V}, /* 14, D3DTSS_ADDRESSV */
1758 {TRUE, WINED3D_SAMP_BORDER_COLOR}, /* 15, D3DTSS_BORDERCOLOR */
1759 {TRUE, WINED3D_SAMP_MAG_FILTER}, /* 16, D3DTSS_MAGFILTER */
1760 {TRUE, WINED3D_SAMP_MIN_FILTER}, /* 17, D3DTSS_MINFILTER */
1761 {TRUE, WINED3D_SAMP_MIP_FILTER}, /* 18, D3DTSS_MIPFILTER */
1762 {TRUE, WINED3D_SAMP_MIPMAP_LOD_BIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1763 {TRUE, WINED3D_SAMP_MAX_MIP_LEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1764 {TRUE, WINED3D_SAMP_MAX_ANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1765 {FALSE, WINED3D_TSS_BUMPENV_LSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1766 {FALSE, WINED3D_TSS_BUMPENV_LOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1767 {FALSE, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1768 {TRUE, WINED3D_SAMP_ADDRESS_W}, /* 25, D3DTSS_ADDRESSW */
1769 {FALSE, WINED3D_TSS_COLOR_ARG0}, /* 26, D3DTSS_COLORARG0 */
1770 {FALSE, WINED3D_TSS_ALPHA_ARG0}, /* 27, D3DTSS_ALPHAARG0 */
1771 {FALSE, WINED3D_TSS_RESULT_ARG}, /* 28, D3DTSS_RESULTARG */
1774 static HRESULT WINAPI d3d8_device_GetTextureStageState(IDirect3DDevice8 *iface,
1775 DWORD stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *value)
1777 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1778 const struct tss_lookup *l;
1781 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, stage, Type, value);
1783 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1785 WARN("Invalid Type %#x passed.\n", Type);
1789 l = &tss_lookup[Type];
1791 wined3d_mutex_lock();
1792 if (l->sampler_state)
1793 hr = wined3d_device_get_sampler_state(device->wined3d_device, stage, l->state, value);
1795 hr = wined3d_device_get_texture_stage_state(device->wined3d_device, stage, l->state, value);
1796 wined3d_mutex_unlock();
1801 static HRESULT WINAPI d3d8_device_SetTextureStageState(IDirect3DDevice8 *iface,
1802 DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value)
1804 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1805 const struct tss_lookup *l;
1808 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, stage, type, value);
1810 if (type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1812 WARN("Invalid type %#x passed.\n", type);
1816 l = &tss_lookup[type];
1818 wined3d_mutex_lock();
1819 if (l->sampler_state)
1820 hr = wined3d_device_set_sampler_state(device->wined3d_device, stage, l->state, value);
1822 hr = wined3d_device_set_texture_stage_state(device->wined3d_device, stage, l->state, value);
1823 wined3d_mutex_unlock();
1828 static HRESULT WINAPI d3d8_device_ValidateDevice(IDirect3DDevice8 *iface, DWORD *pass_count)
1830 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1833 TRACE("iface %p, pass_count %p.\n", iface, pass_count);
1835 wined3d_mutex_lock();
1836 hr = wined3d_device_validate_device(device->wined3d_device, pass_count);
1837 wined3d_mutex_unlock();
1842 static HRESULT WINAPI d3d8_device_GetInfo(IDirect3DDevice8 *iface,
1843 DWORD info_id, void *info, DWORD info_size)
1845 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
1850 static HRESULT WINAPI d3d8_device_SetPaletteEntries(IDirect3DDevice8 *iface,
1851 UINT palette_idx, const PALETTEENTRY *entries)
1853 FIXME("iface %p, palette_idx %u, entries %p unimplemented\n", iface, palette_idx, entries);
1855 /* GPUs stopped supporting palettized textures with the Shader Model 1 generation. Wined3d
1856 * does not have a d3d8/9-style palette API */
1858 return D3DERR_INVALIDCALL;
1861 static HRESULT WINAPI d3d8_device_GetPaletteEntries(IDirect3DDevice8 *iface,
1862 UINT palette_idx, PALETTEENTRY *entries)
1864 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, palette_idx, entries);
1866 return D3DERR_INVALIDCALL;
1869 static HRESULT WINAPI d3d8_device_SetCurrentTexturePalette(IDirect3DDevice8 *iface, UINT palette_idx)
1871 FIXME("iface %p, palette_idx %u unimplemented.\n", iface, palette_idx);
1873 return D3DERR_INVALIDCALL;
1876 static HRESULT WINAPI d3d8_device_GetCurrentTexturePalette(IDirect3DDevice8 *iface, UINT *palette_idx)
1878 FIXME("iface %p, palette_idx %p unimplemented.\n", iface, palette_idx);
1880 return D3DERR_INVALIDCALL;
1883 static HRESULT WINAPI d3d8_device_DrawPrimitive(IDirect3DDevice8 *iface,
1884 D3DPRIMITIVETYPE primitive_type, UINT start_vertex, UINT primitive_count)
1886 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1889 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1890 iface, primitive_type, start_vertex, primitive_count);
1892 wined3d_mutex_lock();
1893 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
1894 hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex,
1895 vertex_count_from_primitive_count(primitive_type, primitive_count));
1896 wined3d_mutex_unlock();
1901 static HRESULT WINAPI d3d8_device_DrawIndexedPrimitive(IDirect3DDevice8 *iface,
1902 D3DPRIMITIVETYPE primitive_type, UINT min_vertex_idx, UINT vertex_count,
1903 UINT start_idx, UINT primitive_count)
1905 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1908 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1909 iface, primitive_type, min_vertex_idx, vertex_count, start_idx, primitive_count);
1911 wined3d_mutex_lock();
1912 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
1913 hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, start_idx,
1914 vertex_count_from_primitive_count(primitive_type, primitive_count));
1915 wined3d_mutex_unlock();
1920 static HRESULT WINAPI d3d8_device_DrawPrimitiveUP(IDirect3DDevice8 *iface,
1921 D3DPRIMITIVETYPE primitive_type, UINT primitive_count, const void *data,
1924 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1927 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1928 iface, primitive_type, primitive_count, data, stride);
1930 wined3d_mutex_lock();
1931 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
1932 hr = wined3d_device_draw_primitive_up(device->wined3d_device,
1933 vertex_count_from_primitive_count(primitive_type, primitive_count),
1935 wined3d_mutex_unlock();
1940 static HRESULT WINAPI d3d8_device_DrawIndexedPrimitiveUP(IDirect3DDevice8 *iface,
1941 D3DPRIMITIVETYPE primitive_type, UINT min_vertex_idx, UINT index_count,
1942 UINT primitive_count, const void *index_data, D3DFORMAT index_format,
1943 const void *vertex_data, UINT vertex_stride)
1945 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1948 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1949 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1950 iface, primitive_type, min_vertex_idx, index_count, primitive_count,
1951 index_data, index_format, vertex_data, vertex_stride);
1953 wined3d_mutex_lock();
1954 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
1955 hr = wined3d_device_draw_indexed_primitive_up(device->wined3d_device,
1956 vertex_count_from_primitive_count(primitive_type, primitive_count), index_data,
1957 wined3dformat_from_d3dformat(index_format), vertex_data, vertex_stride);
1958 wined3d_mutex_unlock();
1963 static HRESULT WINAPI d3d8_device_ProcessVertices(IDirect3DDevice8 *iface, UINT src_start_idx,
1964 UINT dst_idx, UINT vertex_count, IDirect3DVertexBuffer8 *dst_buffer, DWORD flags)
1966 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1967 IDirect3DVertexBuffer8Impl *dst = unsafe_impl_from_IDirect3DVertexBuffer8(dst_buffer);
1970 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1971 iface, src_start_idx, dst_idx, vertex_count, dst_buffer, flags);
1973 wined3d_mutex_lock();
1974 hr = wined3d_device_process_vertices(device->wined3d_device, src_start_idx, dst_idx,
1975 vertex_count, dst->wineD3DVertexBuffer, NULL, flags, dst->fvf);
1976 wined3d_mutex_unlock();
1981 static HRESULT WINAPI d3d8_device_CreateVertexShader(IDirect3DDevice8 *iface,
1982 const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
1984 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1985 struct d3d8_vertex_shader *object;
1986 DWORD shader_handle;
1990 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1991 iface, declaration, byte_code, shader, usage);
1993 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1996 ERR("Failed to allocate vertex shader memory.\n");
1998 return E_OUTOFMEMORY;
2001 wined3d_mutex_lock();
2002 handle = d3d8_allocate_handle(&device->handle_table, object, D3D8_HANDLE_VS);
2003 wined3d_mutex_unlock();
2004 if (handle == D3D8_INVALID_HANDLE)
2006 ERR("Failed to allocate vertex shader handle.\n");
2007 HeapFree(GetProcessHeap(), 0, object);
2009 return E_OUTOFMEMORY;
2012 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2014 hr = d3d8_vertex_shader_init(object, device, declaration, byte_code, shader_handle, usage);
2017 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2018 wined3d_mutex_lock();
2019 d3d8_free_handle(&device->handle_table, handle, D3D8_HANDLE_VS);
2020 wined3d_mutex_unlock();
2021 HeapFree(GetProcessHeap(), 0, object);
2026 TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
2027 *shader = shader_handle;
2032 static struct d3d8_vertex_declaration *d3d8_device_get_fvf_declaration(struct d3d8_device *device, DWORD fvf)
2034 struct d3d8_vertex_declaration *d3d8_declaration;
2035 struct FvfToDecl *convertedDecls = device->decls;
2036 int p, low, high; /* deliberately signed */
2039 TRACE("Searching for declaration for fvf %08x... ", fvf);
2042 high = device->numConvertedDecls - 1;
2045 p = (low + high) >> 1;
2048 if (convertedDecls[p].fvf == fvf)
2050 TRACE("found %p\n", convertedDecls[p].declaration);
2051 return convertedDecls[p].declaration;
2054 if (convertedDecls[p].fvf < fvf)
2059 TRACE("not found. Creating and inserting at position %d.\n", low);
2061 if (!(d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration))))
2063 ERR("Memory allocation failed.\n");
2067 if (FAILED(hr = d3d8_vertex_declaration_init_fvf(d3d8_declaration, device, fvf)))
2069 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2070 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
2074 if (device->declArraySize == device->numConvertedDecls)
2076 UINT grow = device->declArraySize / 2;
2078 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2079 sizeof(*convertedDecls) * (device->numConvertedDecls + grow));
2080 if (!convertedDecls)
2082 d3d8_vertex_declaration_destroy(d3d8_declaration);
2085 device->decls = convertedDecls;
2086 device->declArraySize += grow;
2089 memmove(convertedDecls + low + 1, convertedDecls + low,
2090 sizeof(*convertedDecls) * (device->numConvertedDecls - low));
2091 convertedDecls[low].declaration = d3d8_declaration;
2092 convertedDecls[low].fvf = fvf;
2093 ++device->numConvertedDecls;
2095 TRACE("Returning %p. %u decls in array.\n", d3d8_declaration, device->numConvertedDecls);
2097 return d3d8_declaration;
2100 static HRESULT WINAPI d3d8_device_SetVertexShader(IDirect3DDevice8 *iface, DWORD shader)
2102 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2103 struct d3d8_vertex_shader *shader_impl;
2106 TRACE("iface %p, shader %#x.\n", iface, shader);
2108 if (VS_HIGHESTFIXEDFXF >= shader)
2110 TRACE("Setting FVF, %#x\n", shader);
2112 wined3d_mutex_lock();
2113 wined3d_device_set_vertex_declaration(device->wined3d_device,
2114 d3d8_device_get_fvf_declaration(device, shader)->wined3d_vertex_declaration);
2115 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
2116 wined3d_mutex_unlock();
2121 TRACE("Setting shader\n");
2123 wined3d_mutex_lock();
2124 if (!(shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS)))
2126 WARN("Invalid handle (%#x) passed.\n", shader);
2127 wined3d_mutex_unlock();
2129 return D3DERR_INVALIDCALL;
2132 hr = wined3d_device_set_vertex_declaration(device->wined3d_device,
2133 shader_impl->vertex_declaration->wined3d_vertex_declaration);
2135 hr = wined3d_device_set_vertex_shader(device->wined3d_device, shader_impl->wined3d_shader);
2136 wined3d_mutex_unlock();
2138 TRACE("Returning hr %#x\n", hr);
2143 static HRESULT WINAPI d3d8_device_GetVertexShader(IDirect3DDevice8 *iface, DWORD *shader)
2145 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2146 struct wined3d_vertex_declaration *wined3d_declaration;
2147 struct d3d8_vertex_declaration *d3d8_declaration;
2150 TRACE("iface %p, shader %p.\n", iface, shader);
2152 wined3d_mutex_lock();
2153 if (FAILED(hr = wined3d_device_get_vertex_declaration(device->wined3d_device, &wined3d_declaration)))
2155 wined3d_mutex_unlock();
2156 WARN("Failed to get wined3d vertex declaration, hr %#x.\n", hr);
2160 if (!wined3d_declaration)
2162 wined3d_mutex_unlock();
2167 d3d8_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2168 wined3d_vertex_declaration_decref(wined3d_declaration);
2169 wined3d_mutex_unlock();
2170 *shader = d3d8_declaration->shader_handle;
2172 TRACE("Returning %#x.\n", *shader);
2177 static HRESULT WINAPI d3d8_device_DeleteVertexShader(IDirect3DDevice8 *iface, DWORD shader)
2179 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2180 struct d3d8_vertex_shader *shader_impl;
2181 struct wined3d_shader *cur;
2183 TRACE("iface %p, shader %#x.\n", iface, shader);
2185 wined3d_mutex_lock();
2186 if (!(shader_impl = d3d8_free_handle(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS)))
2188 WARN("Invalid handle (%#x) passed.\n", shader);
2189 wined3d_mutex_unlock();
2191 return D3DERR_INVALIDCALL;
2194 if ((cur = wined3d_device_get_vertex_shader(device->wined3d_device)))
2196 if (cur == shader_impl->wined3d_shader)
2197 IDirect3DDevice8_SetVertexShader(iface, 0);
2198 wined3d_shader_decref(cur);
2201 wined3d_mutex_unlock();
2203 d3d8_vertex_shader_destroy(shader_impl);
2208 static HRESULT WINAPI d3d8_device_SetVertexShaderConstant(IDirect3DDevice8 *iface,
2209 DWORD start_register, const void *data, DWORD count)
2211 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2214 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2215 iface, start_register, data, count);
2217 if (start_register + count > D3D8_MAX_VERTEX_SHADER_CONSTANTF)
2219 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2220 start_register + count, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2221 return D3DERR_INVALIDCALL;
2224 wined3d_mutex_lock();
2225 hr = wined3d_device_set_vs_consts_f(device->wined3d_device, start_register, data, count);
2226 wined3d_mutex_unlock();
2231 static HRESULT WINAPI d3d8_device_GetVertexShaderConstant(IDirect3DDevice8 *iface,
2232 DWORD start_register, void *data, DWORD count)
2234 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2237 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2238 iface, start_register, data, count);
2240 if (start_register + count > D3D8_MAX_VERTEX_SHADER_CONSTANTF)
2242 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2243 start_register + count, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2244 return D3DERR_INVALIDCALL;
2247 wined3d_mutex_lock();
2248 hr = wined3d_device_get_vs_consts_f(device->wined3d_device, start_register, data, count);
2249 wined3d_mutex_unlock();
2254 static HRESULT WINAPI d3d8_device_GetVertexShaderDeclaration(IDirect3DDevice8 *iface,
2255 DWORD shader, void *data, DWORD *data_size)
2257 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2258 struct d3d8_vertex_declaration *declaration;
2259 struct d3d8_vertex_shader *shader_impl;
2261 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2262 iface, shader, data, data_size);
2264 wined3d_mutex_lock();
2265 shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2266 wined3d_mutex_unlock();
2270 WARN("Invalid handle (%#x) passed.\n", shader);
2271 return D3DERR_INVALIDCALL;
2273 declaration = shader_impl->vertex_declaration;
2277 *data_size = declaration->elements_size;
2281 /* MSDN claims that if *data_size is smaller than the required size
2282 * we should write the required size and return D3DERR_MOREDATA.
2283 * That's not actually true. */
2284 if (*data_size < declaration->elements_size)
2285 return D3DERR_INVALIDCALL;
2287 memcpy(data, declaration->elements, declaration->elements_size);
2292 static HRESULT WINAPI d3d8_device_GetVertexShaderFunction(IDirect3DDevice8 *iface,
2293 DWORD shader, void *data, DWORD *data_size)
2295 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2296 struct d3d8_vertex_shader *shader_impl = NULL;
2299 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2300 iface, shader, data, data_size);
2302 wined3d_mutex_lock();
2303 if (!(shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS)))
2305 WARN("Invalid handle (%#x) passed.\n", shader);
2306 wined3d_mutex_unlock();
2308 return D3DERR_INVALIDCALL;
2311 if (!shader_impl->wined3d_shader)
2313 wined3d_mutex_unlock();
2318 hr = wined3d_shader_get_byte_code(shader_impl->wined3d_shader, data, data_size);
2319 wined3d_mutex_unlock();
2324 static HRESULT WINAPI d3d8_device_SetIndices(IDirect3DDevice8 *iface,
2325 IDirect3DIndexBuffer8 *buffer, UINT base_vertex_idx)
2327 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2328 struct d3d8_indexbuffer *ib = unsafe_impl_from_IDirect3DIndexBuffer8(buffer);
2331 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, buffer, base_vertex_idx);
2333 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2334 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2335 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2336 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2339 wined3d_mutex_lock();
2340 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_idx);
2341 hr = wined3d_device_set_index_buffer(device->wined3d_device,
2342 ib ? ib->wined3d_buffer : NULL,
2343 ib ? ib->format : WINED3DFMT_UNKNOWN);
2344 wined3d_mutex_unlock();
2349 static HRESULT WINAPI d3d8_device_GetIndices(IDirect3DDevice8 *iface,
2350 IDirect3DIndexBuffer8 **buffer, UINT *base_vertex_index)
2352 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2353 struct wined3d_buffer *wined3d_buffer = NULL;
2354 struct d3d8_indexbuffer *buffer_impl;
2357 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, buffer, base_vertex_index);
2360 return D3DERR_INVALIDCALL;
2362 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2363 wined3d_mutex_lock();
2364 *base_vertex_index = wined3d_device_get_base_vertex_index(device->wined3d_device);
2365 hr = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_buffer);
2366 if (SUCCEEDED(hr) && wined3d_buffer)
2368 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2369 *buffer = &buffer_impl->IDirect3DIndexBuffer8_iface;
2370 IDirect3DIndexBuffer8_AddRef(*buffer);
2371 wined3d_buffer_decref(wined3d_buffer);
2376 ERR("Failed to get wined3d index buffer, hr %#x.", hr);
2379 wined3d_mutex_unlock();
2384 static HRESULT WINAPI d3d8_device_CreatePixelShader(IDirect3DDevice8 *iface,
2385 const DWORD *byte_code, DWORD *shader)
2387 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2388 struct d3d8_pixel_shader *object;
2389 DWORD shader_handle;
2393 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2396 return D3DERR_INVALIDCALL;
2398 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2401 ERR("Failed to allocate pixel shader memmory.\n");
2402 return E_OUTOFMEMORY;
2405 wined3d_mutex_lock();
2406 handle = d3d8_allocate_handle(&device->handle_table, object, D3D8_HANDLE_PS);
2407 wined3d_mutex_unlock();
2408 if (handle == D3D8_INVALID_HANDLE)
2410 ERR("Failed to allocate pixel shader handle.\n");
2411 HeapFree(GetProcessHeap(), 0, object);
2412 return E_OUTOFMEMORY;
2415 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2417 hr = d3d8_pixel_shader_init(object, device, byte_code, shader_handle);
2420 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2421 wined3d_mutex_lock();
2422 d3d8_free_handle(&device->handle_table, handle, D3D8_HANDLE_PS);
2423 wined3d_mutex_unlock();
2424 HeapFree(GetProcessHeap(), 0, object);
2429 TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
2430 *shader = shader_handle;
2435 static HRESULT WINAPI d3d8_device_SetPixelShader(IDirect3DDevice8 *iface, DWORD shader)
2437 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2438 struct d3d8_pixel_shader *shader_impl;
2441 TRACE("iface %p, shader %#x.\n", iface, shader);
2443 wined3d_mutex_lock();
2447 hr = wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
2448 wined3d_mutex_unlock();
2452 if (!(shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS)))
2454 WARN("Invalid handle (%#x) passed.\n", shader);
2455 wined3d_mutex_unlock();
2456 return D3DERR_INVALIDCALL;
2459 TRACE("Setting shader %p.\n", shader_impl);
2460 hr = wined3d_device_set_pixel_shader(device->wined3d_device, shader_impl->wined3d_shader);
2461 wined3d_mutex_unlock();
2466 static HRESULT WINAPI d3d8_device_GetPixelShader(IDirect3DDevice8 *iface, DWORD *shader)
2468 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2469 struct wined3d_shader *object;
2471 TRACE("iface %p, shader %p.\n", iface, shader);
2474 return D3DERR_INVALIDCALL;
2476 wined3d_mutex_lock();
2477 if ((object = wined3d_device_get_pixel_shader(device->wined3d_device)))
2479 struct d3d8_pixel_shader *d3d8_shader;
2480 d3d8_shader = wined3d_shader_get_parent(object);
2481 wined3d_shader_decref(object);
2482 *shader = d3d8_shader->handle;
2488 wined3d_mutex_unlock();
2490 TRACE("Returning %#x.\n", *shader);
2495 static HRESULT WINAPI d3d8_device_DeletePixelShader(IDirect3DDevice8 *iface, DWORD shader)
2497 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2498 struct d3d8_pixel_shader *shader_impl;
2499 struct wined3d_shader *cur;
2501 TRACE("iface %p, shader %#x.\n", iface, shader);
2503 wined3d_mutex_lock();
2505 if (!(shader_impl = d3d8_free_handle(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS)))
2507 WARN("Invalid handle (%#x) passed.\n", shader);
2508 wined3d_mutex_unlock();
2509 return D3DERR_INVALIDCALL;
2512 if ((cur = wined3d_device_get_pixel_shader(device->wined3d_device)))
2514 if (cur == shader_impl->wined3d_shader)
2515 IDirect3DDevice8_SetPixelShader(iface, 0);
2516 wined3d_shader_decref(cur);
2519 wined3d_mutex_unlock();
2521 d3d8_pixel_shader_destroy(shader_impl);
2526 static HRESULT WINAPI d3d8_device_SetPixelShaderConstant(IDirect3DDevice8 *iface,
2527 DWORD start_register, const void *data, DWORD count)
2529 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2532 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2533 iface, start_register, data, count);
2535 wined3d_mutex_lock();
2536 hr = wined3d_device_set_ps_consts_f(device->wined3d_device, start_register, data, count);
2537 wined3d_mutex_unlock();
2542 static HRESULT WINAPI d3d8_device_GetPixelShaderConstant(IDirect3DDevice8 *iface,
2543 DWORD start_register, void *data, DWORD count)
2545 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2548 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2549 iface, start_register, data, count);
2551 wined3d_mutex_lock();
2552 hr = wined3d_device_get_ps_consts_f(device->wined3d_device, start_register, data, count);
2553 wined3d_mutex_unlock();
2558 static HRESULT WINAPI d3d8_device_GetPixelShaderFunction(IDirect3DDevice8 *iface,
2559 DWORD shader, void *data, DWORD *data_size)
2561 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2562 struct d3d8_pixel_shader *shader_impl = NULL;
2565 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2566 iface, shader, data, data_size);
2568 wined3d_mutex_lock();
2569 if (!(shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS)))
2571 WARN("Invalid handle (%#x) passed.\n", shader);
2572 wined3d_mutex_unlock();
2574 return D3DERR_INVALIDCALL;
2577 hr = wined3d_shader_get_byte_code(shader_impl->wined3d_shader, data, data_size);
2578 wined3d_mutex_unlock();
2583 static HRESULT WINAPI d3d8_device_DrawRectPatch(IDirect3DDevice8 *iface, UINT handle,
2584 const float *segment_count, const D3DRECTPATCH_INFO *patch_info)
2586 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2589 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2590 iface, handle, segment_count, patch_info);
2592 wined3d_mutex_lock();
2593 hr = wined3d_device_draw_rect_patch(device->wined3d_device, handle,
2594 segment_count, (const struct wined3d_rect_patch_info *)patch_info);
2595 wined3d_mutex_unlock();
2600 static HRESULT WINAPI d3d8_device_DrawTriPatch(IDirect3DDevice8 *iface, UINT handle,
2601 const float *segment_count, const D3DTRIPATCH_INFO *patch_info)
2603 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2606 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2607 iface, handle, segment_count, patch_info);
2609 wined3d_mutex_lock();
2610 hr = wined3d_device_draw_tri_patch(device->wined3d_device, handle,
2611 segment_count, (const struct wined3d_tri_patch_info *)patch_info);
2612 wined3d_mutex_unlock();
2617 static HRESULT WINAPI d3d8_device_DeletePatch(IDirect3DDevice8 *iface, UINT handle)
2619 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2622 TRACE("iface %p, handle %#x.\n", iface, handle);
2624 wined3d_mutex_lock();
2625 hr = wined3d_device_delete_patch(device->wined3d_device, handle);
2626 wined3d_mutex_unlock();
2631 static HRESULT WINAPI d3d8_device_SetStreamSource(IDirect3DDevice8 *iface,
2632 UINT stream_idx, IDirect3DVertexBuffer8 *buffer, UINT stride)
2634 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2635 IDirect3DVertexBuffer8Impl *buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer8(buffer);
2638 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2639 iface, stream_idx, buffer, stride);
2641 wined3d_mutex_lock();
2642 hr = wined3d_device_set_stream_source(device->wined3d_device, stream_idx,
2643 buffer_impl ? buffer_impl->wineD3DVertexBuffer : NULL, 0, stride);
2644 wined3d_mutex_unlock();
2649 static HRESULT WINAPI d3d8_device_GetStreamSource(IDirect3DDevice8 *iface,
2650 UINT stream_idx, IDirect3DVertexBuffer8 **buffer, UINT *stride)
2652 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2653 IDirect3DVertexBuffer8Impl *buffer_impl;
2654 struct wined3d_buffer *wined3d_buffer = NULL;
2657 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2658 iface, stream_idx, buffer, stride);
2661 return D3DERR_INVALIDCALL;
2663 wined3d_mutex_lock();
2664 hr = wined3d_device_get_stream_source(device->wined3d_device, stream_idx, &wined3d_buffer, 0, stride);
2665 if (SUCCEEDED(hr) && wined3d_buffer)
2667 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2668 *buffer = &buffer_impl->IDirect3DVertexBuffer8_iface;
2669 IDirect3DVertexBuffer8_AddRef(*buffer);
2670 wined3d_buffer_decref(wined3d_buffer);
2675 ERR("Failed to get wined3d stream source, hr %#x.\n", hr);
2678 wined3d_mutex_unlock();
2683 static const struct IDirect3DDevice8Vtbl d3d8_device_vtbl =
2685 d3d8_device_QueryInterface,
2687 d3d8_device_Release,
2688 d3d8_device_TestCooperativeLevel,
2689 d3d8_device_GetAvailableTextureMem,
2690 d3d8_device_ResourceManagerDiscardBytes,
2691 d3d8_device_GetDirect3D,
2692 d3d8_device_GetDeviceCaps,
2693 d3d8_device_GetDisplayMode,
2694 d3d8_device_GetCreationParameters,
2695 d3d8_device_SetCursorProperties,
2696 d3d8_device_SetCursorPosition,
2697 d3d8_device_ShowCursor,
2698 d3d8_device_CreateAdditionalSwapChain,
2700 d3d8_device_Present,
2701 d3d8_device_GetBackBuffer,
2702 d3d8_device_GetRasterStatus,
2703 d3d8_device_SetGammaRamp,
2704 d3d8_device_GetGammaRamp,
2705 d3d8_device_CreateTexture,
2706 d3d8_device_CreateVolumeTexture,
2707 d3d8_device_CreateCubeTexture,
2708 d3d8_device_CreateVertexBuffer,
2709 d3d8_device_CreateIndexBuffer,
2710 d3d8_device_CreateRenderTarget,
2711 d3d8_device_CreateDepthStencilSurface,
2712 d3d8_device_CreateImageSurface,
2713 d3d8_device_CopyRects,
2714 d3d8_device_UpdateTexture,
2715 d3d8_device_GetFrontBuffer,
2716 d3d8_device_SetRenderTarget,
2717 d3d8_device_GetRenderTarget,
2718 d3d8_device_GetDepthStencilSurface,
2719 d3d8_device_BeginScene,
2720 d3d8_device_EndScene,
2722 d3d8_device_SetTransform,
2723 d3d8_device_GetTransform,
2724 d3d8_device_MultiplyTransform,
2725 d3d8_device_SetViewport,
2726 d3d8_device_GetViewport,
2727 d3d8_device_SetMaterial,
2728 d3d8_device_GetMaterial,
2729 d3d8_device_SetLight,
2730 d3d8_device_GetLight,
2731 d3d8_device_LightEnable,
2732 d3d8_device_GetLightEnable,
2733 d3d8_device_SetClipPlane,
2734 d3d8_device_GetClipPlane,
2735 d3d8_device_SetRenderState,
2736 d3d8_device_GetRenderState,
2737 d3d8_device_BeginStateBlock,
2738 d3d8_device_EndStateBlock,
2739 d3d8_device_ApplyStateBlock,
2740 d3d8_device_CaptureStateBlock,
2741 d3d8_device_DeleteStateBlock,
2742 d3d8_device_CreateStateBlock,
2743 d3d8_device_SetClipStatus,
2744 d3d8_device_GetClipStatus,
2745 d3d8_device_GetTexture,
2746 d3d8_device_SetTexture,
2747 d3d8_device_GetTextureStageState,
2748 d3d8_device_SetTextureStageState,
2749 d3d8_device_ValidateDevice,
2750 d3d8_device_GetInfo,
2751 d3d8_device_SetPaletteEntries,
2752 d3d8_device_GetPaletteEntries,
2753 d3d8_device_SetCurrentTexturePalette,
2754 d3d8_device_GetCurrentTexturePalette,
2755 d3d8_device_DrawPrimitive,
2756 d3d8_device_DrawIndexedPrimitive,
2757 d3d8_device_DrawPrimitiveUP,
2758 d3d8_device_DrawIndexedPrimitiveUP,
2759 d3d8_device_ProcessVertices,
2760 d3d8_device_CreateVertexShader,
2761 d3d8_device_SetVertexShader,
2762 d3d8_device_GetVertexShader,
2763 d3d8_device_DeleteVertexShader,
2764 d3d8_device_SetVertexShaderConstant,
2765 d3d8_device_GetVertexShaderConstant,
2766 d3d8_device_GetVertexShaderDeclaration,
2767 d3d8_device_GetVertexShaderFunction,
2768 d3d8_device_SetStreamSource,
2769 d3d8_device_GetStreamSource,
2770 d3d8_device_SetIndices,
2771 d3d8_device_GetIndices,
2772 d3d8_device_CreatePixelShader,
2773 d3d8_device_SetPixelShader,
2774 d3d8_device_GetPixelShader,
2775 d3d8_device_DeletePixelShader,
2776 d3d8_device_SetPixelShaderConstant,
2777 d3d8_device_GetPixelShaderConstant,
2778 d3d8_device_GetPixelShaderFunction,
2779 d3d8_device_DrawRectPatch,
2780 d3d8_device_DrawTriPatch,
2781 d3d8_device_DeletePatch,
2784 static inline struct d3d8_device *device_from_device_parent(struct wined3d_device_parent *device_parent)
2786 return CONTAINING_RECORD(device_parent, struct d3d8_device, device_parent);
2789 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
2790 struct wined3d_device *device)
2792 TRACE("device_parent %p, device %p\n", device_parent, device);
2795 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
2797 TRACE("device_parent %p.\n", device_parent);
2800 static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *device_parent,
2801 void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
2802 enum wined3d_pool pool, UINT level, enum wined3d_cubemap_face face, struct wined3d_surface **surface)
2804 struct d3d8_device *device = device_from_device_parent(device_parent);
2805 IDirect3DSurface8Impl *d3d_surface;
2806 BOOL lockable = TRUE;
2809 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2810 "\tpool %#x, level %u, face %u, surface %p.\n",
2811 device_parent, container_parent, width, height, format, usage, pool, level, face, surface);
2814 if (pool == WINED3D_POOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC))
2817 hr = d3d8_device_CreateSurface(device, width, height,
2818 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2819 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2822 WARN("Failed to create surface, hr %#x.\n", hr);
2826 *surface = d3d_surface->wined3d_surface;
2827 wined3d_surface_incref(*surface);
2829 d3d_surface->container = container_parent;
2830 IUnknown_Release(d3d_surface->parentDevice);
2831 d3d_surface->parentDevice = NULL;
2833 IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface);
2834 d3d_surface->forwardReference = container_parent;
2839 static HRESULT CDECL device_parent_create_rendertarget(struct wined3d_device_parent *device_parent,
2840 void *container_parent, UINT width, UINT height, enum wined3d_format_id format,
2841 enum wined3d_multisample_type multisample_type, DWORD multisample_quality, BOOL lockable,
2842 struct wined3d_surface **surface)
2844 struct d3d8_device *device = device_from_device_parent(device_parent);
2845 IDirect3DSurface8Impl *d3d_surface;
2848 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2849 "\tmultisample_quality %u, lockable %u, surface %p.\n",
2850 device_parent, container_parent, width, height, format,
2851 multisample_type, multisample_quality, lockable, surface);
2853 hr = IDirect3DDevice8_CreateRenderTarget(&device->IDirect3DDevice8_iface, width, height,
2854 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2857 WARN("Failed to create rendertarget, hr %#x.\n", hr);
2861 *surface = d3d_surface->wined3d_surface;
2862 wined3d_surface_incref(*surface);
2864 d3d_surface->container = (IUnknown *)&device->IDirect3DDevice8_iface;
2865 /* Implicit surfaces are created with an refcount of 0 */
2866 IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface);
2871 static HRESULT CDECL device_parent_create_depth_stencil(struct wined3d_device_parent *device_parent,
2872 UINT width, UINT height, enum wined3d_format_id format, enum wined3d_multisample_type multisample_type,
2873 DWORD multisample_quality, BOOL discard, struct wined3d_surface **surface)
2875 struct d3d8_device *device = device_from_device_parent(device_parent);
2876 IDirect3DSurface8Impl *d3d_surface;
2879 TRACE("device_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2880 "\tmultisample_quality %u, discard %u, surface %p.\n",
2881 device_parent, width, height, format, multisample_type, multisample_quality, discard, surface);
2883 hr = IDirect3DDevice8_CreateDepthStencilSurface(&device->IDirect3DDevice8_iface, width, height,
2884 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2887 WARN("Failed to create depth/stencil surface, hr %#x.\n", hr);
2891 *surface = d3d_surface->wined3d_surface;
2892 wined3d_surface_incref(*surface);
2894 d3d_surface->container = (IUnknown *)&device->IDirect3DDevice8_iface;
2895 /* Implicit surfaces are created with an refcount of 0 */
2896 IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface);
2901 static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *device_parent,
2902 void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
2903 enum wined3d_pool pool, DWORD usage, struct wined3d_volume **volume)
2905 struct d3d8_device *device = device_from_device_parent(device_parent);
2906 IDirect3DVolume8Impl *object;
2909 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
2910 "format %#x, pool %#x, usage %#x, volume %p.\n",
2911 device_parent, container_parent, width, height, depth,
2912 format, pool, usage, volume);
2914 /* Allocate the storage for the device */
2915 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2918 FIXME("Allocation of memory failed\n");
2920 return D3DERR_OUTOFVIDEOMEMORY;
2923 hr = volume_init(object, device, width, height, depth, usage, format, pool);
2926 WARN("Failed to initialize volume, hr %#x.\n", hr);
2927 HeapFree(GetProcessHeap(), 0, object);
2931 *volume = object->wined3d_volume;
2932 wined3d_volume_incref(*volume);
2933 IDirect3DVolume8_Release(&object->IDirect3DVolume8_iface);
2935 object->container = container_parent;
2936 object->forwardReference = container_parent;
2938 TRACE("Created volume %p.\n", object);
2943 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
2944 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
2946 struct d3d8_device *device = device_from_device_parent(device_parent);
2947 D3DPRESENT_PARAMETERS local_parameters;
2948 IDirect3DSwapChain8 *d3d_swapchain;
2951 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
2953 /* Copy the presentation parameters */
2954 local_parameters.BackBufferWidth = desc->backbuffer_width;
2955 local_parameters.BackBufferHeight = desc->backbuffer_height;
2956 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(desc->backbuffer_format);
2957 local_parameters.BackBufferCount = desc->backbuffer_count;
2958 local_parameters.MultiSampleType = desc->multisample_type;
2959 local_parameters.SwapEffect = desc->swap_effect;
2960 local_parameters.hDeviceWindow = desc->device_window;
2961 local_parameters.Windowed = desc->windowed;
2962 local_parameters.EnableAutoDepthStencil = desc->enable_auto_depth_stencil;
2963 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc->auto_depth_stencil_format);
2964 local_parameters.Flags = desc->flags;
2965 local_parameters.FullScreen_RefreshRateInHz = desc->refresh_rate;
2966 local_parameters.FullScreen_PresentationInterval = desc->swap_interval;
2968 hr = IDirect3DDevice8_CreateAdditionalSwapChain(&device->IDirect3DDevice8_iface,
2969 &local_parameters, &d3d_swapchain);
2972 WARN("Failed to create swapchain, hr %#x.\n", hr);
2977 *swapchain = ((IDirect3DSwapChain8Impl *)d3d_swapchain)->wined3d_swapchain;
2978 wined3d_swapchain_incref(*swapchain);
2979 IDirect3DSwapChain8_Release(d3d_swapchain);
2981 /* Copy back the presentation parameters */
2982 desc->backbuffer_width = local_parameters.BackBufferWidth;
2983 desc->backbuffer_height = local_parameters.BackBufferHeight;
2984 desc->backbuffer_format = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2985 desc->backbuffer_count = local_parameters.BackBufferCount;
2986 desc->multisample_type = local_parameters.MultiSampleType;
2987 desc->swap_effect = local_parameters.SwapEffect;
2988 desc->device_window = local_parameters.hDeviceWindow;
2989 desc->windowed = local_parameters.Windowed;
2990 desc->enable_auto_depth_stencil = local_parameters.EnableAutoDepthStencil;
2991 desc->auto_depth_stencil_format = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2992 desc->flags = local_parameters.Flags;
2993 desc->refresh_rate = local_parameters.FullScreen_RefreshRateInHz;
2994 desc->swap_interval = local_parameters.FullScreen_PresentationInterval;
2999 static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops =
3001 device_parent_wined3d_device_created,
3002 device_parent_mode_changed,
3003 device_parent_create_surface,
3004 device_parent_create_rendertarget,
3005 device_parent_create_depth_stencil,
3006 device_parent_create_volume,
3007 device_parent_create_swapchain,
3010 static void setup_fpu(void)
3012 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3014 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3015 cw = (cw & ~0xf3f) | 0x3f;
3016 __asm__ volatile ("fldcw %0" : : "m" (cw));
3017 #elif defined(__i386__) && defined(_MSC_VER)
3020 cw = (cw & ~0xf3f) | 0x3f;
3023 FIXME("FPU setup not implemented for this platform.\n");
3027 HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wined3d *wined3d, UINT adapter,
3028 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
3030 struct wined3d_swapchain_desc swapchain_desc;
3033 device->IDirect3DDevice8_iface.lpVtbl = &d3d8_device_vtbl;
3034 device->device_parent.ops = &d3d8_wined3d_device_parent_ops;
3036 device->handle_table.entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
3037 D3D8_INITIAL_HANDLE_TABLE_SIZE * sizeof(*device->handle_table.entries));
3038 if (!device->handle_table.entries)
3040 ERR("Failed to allocate handle table memory.\n");
3041 return E_OUTOFMEMORY;
3043 device->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
3045 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3047 wined3d_mutex_lock();
3048 hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4,
3049 &device->device_parent, &device->wined3d_device);
3052 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3053 wined3d_mutex_unlock();
3054 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3058 if (!parameters->Windowed)
3060 HWND device_window = parameters->hDeviceWindow;
3063 focus_window = device_window;
3064 if (FAILED(hr = wined3d_device_acquire_focus_window(device->wined3d_device, focus_window)))
3066 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3067 wined3d_device_decref(device->wined3d_device);
3068 wined3d_mutex_unlock();
3069 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3074 device_window = focus_window;
3075 wined3d_device_setup_fullscreen_window(device->wined3d_device, device_window,
3076 parameters->BackBufferWidth,
3077 parameters->BackBufferHeight);
3080 if (flags & D3DCREATE_MULTITHREADED)
3081 wined3d_device_set_multithreaded(device->wined3d_device);
3083 swapchain_desc.backbuffer_width = parameters->BackBufferWidth;
3084 swapchain_desc.backbuffer_height = parameters->BackBufferHeight;
3085 swapchain_desc.backbuffer_format = wined3dformat_from_d3dformat(parameters->BackBufferFormat);
3086 swapchain_desc.backbuffer_count = parameters->BackBufferCount;
3087 swapchain_desc.multisample_type = parameters->MultiSampleType;
3088 swapchain_desc.multisample_quality = 0; /* d3d9 only */
3089 swapchain_desc.swap_effect = parameters->SwapEffect;
3090 swapchain_desc.device_window = parameters->hDeviceWindow;
3091 swapchain_desc.windowed = parameters->Windowed;
3092 swapchain_desc.enable_auto_depth_stencil = parameters->EnableAutoDepthStencil;
3093 swapchain_desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat);
3094 swapchain_desc.flags = parameters->Flags;
3095 swapchain_desc.refresh_rate = parameters->FullScreen_RefreshRateInHz;
3096 swapchain_desc.swap_interval = parameters->FullScreen_PresentationInterval;
3097 swapchain_desc.auto_restore_display_mode = TRUE;
3099 hr = wined3d_device_init_3d(device->wined3d_device, &swapchain_desc);
3102 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3103 wined3d_device_release_focus_window(device->wined3d_device);
3104 wined3d_device_decref(device->wined3d_device);
3105 wined3d_mutex_unlock();
3106 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3110 hr = wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0);
3111 wined3d_mutex_unlock();
3114 ERR("Failed to set minimum pointsize, hr %#x.\n", hr);
3118 parameters->BackBufferWidth = swapchain_desc.backbuffer_width;
3119 parameters->BackBufferHeight = swapchain_desc.backbuffer_height;
3120 parameters->BackBufferFormat = d3dformat_from_wined3dformat(swapchain_desc.backbuffer_format);
3121 parameters->BackBufferCount = swapchain_desc.backbuffer_count;
3122 parameters->MultiSampleType = swapchain_desc.multisample_type;
3123 parameters->SwapEffect = swapchain_desc.swap_effect;
3124 parameters->hDeviceWindow = swapchain_desc.device_window;
3125 parameters->Windowed = swapchain_desc.windowed;
3126 parameters->EnableAutoDepthStencil = swapchain_desc.enable_auto_depth_stencil;
3127 parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(swapchain_desc.auto_depth_stencil_format);
3128 parameters->Flags = swapchain_desc.flags;
3129 parameters->FullScreen_RefreshRateInHz = swapchain_desc.refresh_rate;
3130 parameters->FullScreen_PresentationInterval = swapchain_desc.swap_interval;
3132 device->declArraySize = 16;
3133 device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls));
3136 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3141 device->d3d_parent = &parent->IDirect3D8_iface;
3142 IDirect3D8_AddRef(device->d3d_parent);
3147 wined3d_mutex_lock();
3148 wined3d_device_uninit_3d(device->wined3d_device);
3149 wined3d_device_release_focus_window(device->wined3d_device);
3150 wined3d_device_decref(device->wined3d_device);
3151 wined3d_mutex_unlock();
3152 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);