2 * Copyright 2016 Andrey Gusev
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "d3dcompiler.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
27 struct asyncdataloader
29 ID3DX10DataLoader ID3DX10DataLoader_iface
;
47 static inline struct asyncdataloader
*impl_from_ID3DX10DataLoader(ID3DX10DataLoader
*iface
)
49 return CONTAINING_RECORD(iface
, struct asyncdataloader
, ID3DX10DataLoader_iface
);
52 static HRESULT WINAPI
memorydataloader_Load(ID3DX10DataLoader
*iface
)
54 TRACE("iface %p.\n", iface
);
58 static HRESULT WINAPI
memorydataloader_Decompress(ID3DX10DataLoader
*iface
, void **data
, SIZE_T
*size
)
60 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
62 TRACE("iface %p, data %p, size %p.\n", iface
, data
, size
);
70 static HRESULT WINAPI
memorydataloader_Destroy(ID3DX10DataLoader
*iface
)
72 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
74 TRACE("iface %p.\n", iface
);
76 HeapFree(GetProcessHeap(), 0, loader
);
80 static const ID3DX10DataLoaderVtbl memorydataloadervtbl
=
82 memorydataloader_Load
,
83 memorydataloader_Decompress
,
84 memorydataloader_Destroy
87 static HRESULT WINAPI
filedataloader_Load(ID3DX10DataLoader
*iface
)
89 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
95 TRACE("iface %p.\n", iface
);
97 /* Always buffer file contents, even if Load() was already called. */
98 file
= CreateFileW(loader
->u
.file
.path
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
99 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
100 if (file
== INVALID_HANDLE_VALUE
)
101 return D3D10_ERROR_FILE_NOT_FOUND
;
103 size
= GetFileSize(file
, NULL
);
104 data
= HeapAlloc(GetProcessHeap(), 0, size
);
108 return E_OUTOFMEMORY
;
111 ret
= ReadFile(file
, data
, size
, &read_len
, NULL
);
115 WARN("Failed to read file contents.\n");
116 HeapFree(GetProcessHeap(), 0, data
);
120 HeapFree(GetProcessHeap(), 0, loader
->data
);
127 static HRESULT WINAPI
filedataloader_Decompress(ID3DX10DataLoader
*iface
, void **data
, SIZE_T
*size
)
129 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
131 TRACE("iface %p, data %p, size %p.\n", iface
, data
, size
);
136 *data
= loader
->data
;
137 *size
= loader
->size
;
142 static HRESULT WINAPI
filedataloader_Destroy(ID3DX10DataLoader
*iface
)
144 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
146 TRACE("iface %p.\n", iface
);
148 HeapFree(GetProcessHeap(), 0, loader
->u
.file
.path
);
149 HeapFree(GetProcessHeap(), 0, loader
->data
);
150 HeapFree(GetProcessHeap(), 0, loader
);
155 static const ID3DX10DataLoaderVtbl filedataloadervtbl
=
158 filedataloader_Decompress
,
159 filedataloader_Destroy
162 static HRESULT WINAPI
resourcedataloader_Load(ID3DX10DataLoader
*iface
)
164 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
167 TRACE("iface %p.\n", iface
);
172 hglobal
= LoadResource(loader
->u
.resource
.module
, loader
->u
.resource
.rsrc
);
175 WARN("Failed to load resource.\n");
179 loader
->data
= LockResource(hglobal
);
180 loader
->size
= SizeofResource(loader
->u
.resource
.module
, loader
->u
.resource
.rsrc
);
185 static HRESULT WINAPI
resourcedataloader_Decompress(ID3DX10DataLoader
*iface
, void **data
, SIZE_T
*size
)
187 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
189 TRACE("iface %p, data %p, size %p.\n", iface
, data
, size
);
194 *data
= loader
->data
;
195 *size
= loader
->size
;
200 static HRESULT WINAPI
resourcedataloader_Destroy(ID3DX10DataLoader
*iface
)
202 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
204 TRACE("iface %p.\n", iface
);
206 HeapFree(GetProcessHeap(), 0, loader
);
211 static const ID3DX10DataLoaderVtbl resourcedataloadervtbl
=
213 resourcedataloader_Load
,
214 resourcedataloader_Decompress
,
215 resourcedataloader_Destroy
218 HRESULT WINAPI
D3DX10CompileFromMemory(const char *data
, SIZE_T data_size
, const char *filename
,
219 const D3D10_SHADER_MACRO
*defines
, ID3D10Include
*include
, const char *entry_point
,
220 const char *target
, UINT sflags
, UINT eflags
, ID3DX10ThreadPump
*pump
, ID3D10Blob
**shader
,
221 ID3D10Blob
**error_messages
, HRESULT
*hresult
)
223 TRACE("data %s, data_size %Iu, filename %s, defines %p, include %p, entry_point %s, target %s, "
224 "sflags %#x, eflags %#x, pump %p, shader %p, error_messages %p, hresult %p.\n",
225 debugstr_an(data
, data_size
), data_size
, debugstr_a(filename
), defines
, include
,
226 debugstr_a(entry_point
), debugstr_a(target
), sflags
, eflags
, pump
, shader
,
227 error_messages
, hresult
);
230 FIXME("Unimplemented ID3DX10ThreadPump handling.\n");
232 return D3DCompile(data
, data_size
, filename
, defines
, include
, entry_point
, target
,
233 sflags
, eflags
, shader
, error_messages
);
236 HRESULT WINAPI
D3DX10CreateEffectPoolFromFileA(const char *filename
, const D3D10_SHADER_MACRO
*defines
,
237 ID3D10Include
*include
, const char *profile
, UINT hlslflags
, UINT fxflags
, ID3D10Device
*device
,
238 ID3DX10ThreadPump
*pump
, ID3D10EffectPool
**effectpool
, ID3D10Blob
**errors
, HRESULT
*hresult
)
240 FIXME("filename %s, defines %p, include %p, profile %s, hlslflags %#x, fxflags %#x, device %p, "
241 "pump %p, effectpool %p, errors %p, hresult %p, stub!\n",
242 debugstr_a(filename
), defines
, include
, debugstr_a(profile
), hlslflags
, fxflags
, device
,
243 pump
, effectpool
, errors
, hresult
);
248 HRESULT WINAPI
D3DX10CreateEffectPoolFromFileW(const WCHAR
*filename
, const D3D10_SHADER_MACRO
*defines
,
249 ID3D10Include
*include
, const char *profile
, UINT hlslflags
, UINT fxflags
, ID3D10Device
*device
,
250 ID3DX10ThreadPump
*pump
, ID3D10EffectPool
**effectpool
, ID3D10Blob
**errors
, HRESULT
*hresult
)
252 FIXME("filename %s, defines %p, include %p, profile %s, hlslflags %#x, fxflags %#x, device %p, "
253 "pump %p, effectpool %p, errors %p, hresult %p, stub!\n",
254 debugstr_w(filename
), defines
, include
, debugstr_a(profile
), hlslflags
, fxflags
, device
,
255 pump
, effectpool
, errors
, hresult
);
260 HRESULT WINAPI
D3DX10CreateAsyncMemoryLoader(const void *data
, SIZE_T data_size
, ID3DX10DataLoader
**loader
)
262 struct asyncdataloader
*object
;
264 TRACE("data %p, data_size %Iu, loader %p.\n", data
, data_size
, loader
);
266 if (!data
|| !loader
)
269 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
271 return E_OUTOFMEMORY
;
273 object
->ID3DX10DataLoader_iface
.lpVtbl
= &memorydataloadervtbl
;
274 object
->data
= (void *)data
;
275 object
->size
= data_size
;
277 *loader
= &object
->ID3DX10DataLoader_iface
;
282 HRESULT WINAPI
D3DX10CreateAsyncFileLoaderA(const char *filename
, ID3DX10DataLoader
**loader
)
288 TRACE("filename %s, loader %p.\n", debugstr_a(filename
), loader
);
290 if (!filename
|| !loader
)
293 len
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
294 filename_w
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(*filename_w
));
295 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filename_w
, len
);
297 hr
= D3DX10CreateAsyncFileLoaderW(filename_w
, loader
);
299 HeapFree(GetProcessHeap(), 0, filename_w
);
304 HRESULT WINAPI
D3DX10CreateAsyncFileLoaderW(const WCHAR
*filename
, ID3DX10DataLoader
**loader
)
306 struct asyncdataloader
*object
;
308 TRACE("filename %s, loader %p.\n", debugstr_w(filename
), loader
);
310 if (!filename
|| !loader
)
313 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
315 return E_OUTOFMEMORY
;
317 object
->ID3DX10DataLoader_iface
.lpVtbl
= &filedataloadervtbl
;
318 object
->u
.file
.path
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(filename
) + 1) * sizeof(WCHAR
));
319 if (!object
->u
.file
.path
)
321 HeapFree(GetProcessHeap(), 0, object
);
322 return E_OUTOFMEMORY
;
324 lstrcpyW(object
->u
.file
.path
, filename
);
328 *loader
= &object
->ID3DX10DataLoader_iface
;
333 HRESULT WINAPI
D3DX10CreateAsyncResourceLoaderA(HMODULE module
, const char *resource
, ID3DX10DataLoader
**loader
)
335 struct asyncdataloader
*object
;
338 TRACE("module %p, resource %s, loader %p.\n", module
, debugstr_a(resource
), loader
);
343 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
345 return E_OUTOFMEMORY
;
347 if (!(rsrc
= FindResourceA(module
, resource
, (const char *)RT_RCDATA
)))
348 rsrc
= FindResourceA(module
, resource
, (const char *)RT_BITMAP
);
351 WARN("Failed to find resource.\n");
352 HeapFree(GetProcessHeap(), 0, object
);
353 return D3DX10_ERR_INVALID_DATA
;
356 object
->ID3DX10DataLoader_iface
.lpVtbl
= &resourcedataloadervtbl
;
357 object
->u
.resource
.module
= module
;
358 object
->u
.resource
.rsrc
= rsrc
;
362 *loader
= &object
->ID3DX10DataLoader_iface
;
367 HRESULT WINAPI
D3DX10CreateAsyncResourceLoaderW(HMODULE module
, const WCHAR
*resource
, ID3DX10DataLoader
**loader
)
369 struct asyncdataloader
*object
;
372 TRACE("module %p, resource %s, loader %p.\n", module
, debugstr_w(resource
), loader
);
377 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
379 return E_OUTOFMEMORY
;
381 if (!(rsrc
= FindResourceW(module
, resource
, (const WCHAR
*)RT_RCDATA
)))
382 rsrc
= FindResourceW(module
, resource
, (const WCHAR
*)RT_BITMAP
);
385 WARN("Failed to find resource.\n");
386 HeapFree(GetProcessHeap(), 0, object
);
387 return D3DX10_ERR_INVALID_DATA
;
390 object
->ID3DX10DataLoader_iface
.lpVtbl
= &resourcedataloadervtbl
;
391 object
->u
.resource
.module
= module
;
392 object
->u
.resource
.rsrc
= rsrc
;
396 *loader
= &object
->ID3DX10DataLoader_iface
;
401 HRESULT WINAPI
D3DX10PreprocessShaderFromMemory(const char *data
, SIZE_T data_size
, const char *filename
,
402 const D3D10_SHADER_MACRO
*defines
, ID3DInclude
*include
, ID3DX10ThreadPump
*pump
, ID3D10Blob
**shader_text
,
403 ID3D10Blob
**errors
, HRESULT
*hresult
)
405 FIXME("data %s, data_size %Iu, filename %s, defines %p, include %p, pump %p, shader_text %p, "
406 "errors %p, hresult %p stub!\n",
407 debugstr_an(data
, data_size
), data_size
, debugstr_a(filename
), defines
, include
, pump
,
408 shader_text
, errors
, hresult
);