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
20 #include "wine/port.h"
23 #include "d3dcompiler.h"
25 #include "wine/debug.h"
26 #include "wine/unicode.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
30 struct asyncdataloader
32 ID3DX10DataLoader ID3DX10DataLoader_iface
;
50 static inline struct asyncdataloader
*impl_from_ID3DX10DataLoader(ID3DX10DataLoader
*iface
)
52 return CONTAINING_RECORD(iface
, struct asyncdataloader
, ID3DX10DataLoader_iface
);
55 static HRESULT WINAPI
memorydataloader_Load(ID3DX10DataLoader
*iface
)
57 TRACE("iface %p.\n", iface
);
61 static HRESULT WINAPI
memorydataloader_Decompress(ID3DX10DataLoader
*iface
, void **data
, SIZE_T
*size
)
63 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
65 TRACE("iface %p, data %p, size %p.\n", iface
, data
, size
);
73 static HRESULT WINAPI
memorydataloader_Destroy(ID3DX10DataLoader
*iface
)
75 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
77 TRACE("iface %p.\n", iface
);
79 HeapFree(GetProcessHeap(), 0, loader
);
83 static const ID3DX10DataLoaderVtbl memorydataloadervtbl
=
85 memorydataloader_Load
,
86 memorydataloader_Decompress
,
87 memorydataloader_Destroy
90 static HRESULT WINAPI
filedataloader_Load(ID3DX10DataLoader
*iface
)
92 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
98 TRACE("iface %p.\n", iface
);
100 /* Always buffer file contents, even if Load() was already called. */
101 file
= CreateFileW(loader
->u
.file
.path
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
102 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
103 if (file
== INVALID_HANDLE_VALUE
)
104 return D3D10_ERROR_FILE_NOT_FOUND
;
106 size
= GetFileSize(file
, NULL
);
107 data
= HeapAlloc(GetProcessHeap(), 0, size
);
111 return E_OUTOFMEMORY
;
114 ret
= ReadFile(file
, data
, size
, &read_len
, NULL
);
118 WARN("Failed to read file contents.\n");
119 HeapFree(GetProcessHeap(), 0, data
);
123 HeapFree(GetProcessHeap(), 0, loader
->data
);
130 static HRESULT WINAPI
filedataloader_Decompress(ID3DX10DataLoader
*iface
, void **data
, SIZE_T
*size
)
132 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
134 TRACE("iface %p, data %p, size %p.\n", iface
, data
, size
);
139 *data
= loader
->data
;
140 *size
= loader
->size
;
145 static HRESULT WINAPI
filedataloader_Destroy(ID3DX10DataLoader
*iface
)
147 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
149 TRACE("iface %p.\n", iface
);
151 HeapFree(GetProcessHeap(), 0, loader
->u
.file
.path
);
152 HeapFree(GetProcessHeap(), 0, loader
->data
);
153 HeapFree(GetProcessHeap(), 0, loader
);
158 static const ID3DX10DataLoaderVtbl filedataloadervtbl
=
161 filedataloader_Decompress
,
162 filedataloader_Destroy
165 static HRESULT WINAPI
resourcedataloader_Load(ID3DX10DataLoader
*iface
)
167 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
170 TRACE("iface %p.\n", iface
);
175 hglobal
= LoadResource(loader
->u
.resource
.module
, loader
->u
.resource
.rsrc
);
178 WARN("Failed to load resource.\n");
182 loader
->data
= LockResource(hglobal
);
183 loader
->size
= SizeofResource(loader
->u
.resource
.module
, loader
->u
.resource
.rsrc
);
188 static HRESULT WINAPI
resourcedataloader_Decompress(ID3DX10DataLoader
*iface
, void **data
, SIZE_T
*size
)
190 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
192 TRACE("iface %p, data %p, size %p.\n", iface
, data
, size
);
197 *data
= loader
->data
;
198 *size
= loader
->size
;
203 static HRESULT WINAPI
resourcedataloader_Destroy(ID3DX10DataLoader
*iface
)
205 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
207 TRACE("iface %p.\n", iface
);
209 HeapFree(GetProcessHeap(), 0, loader
);
214 static const ID3DX10DataLoaderVtbl resourcedataloadervtbl
=
216 resourcedataloader_Load
,
217 resourcedataloader_Decompress
,
218 resourcedataloader_Destroy
221 HRESULT WINAPI
D3DX10CompileFromMemory(const char *data
, SIZE_T data_size
, const char *filename
,
222 const D3D10_SHADER_MACRO
*defines
, ID3D10Include
*include
, const char *entry_point
,
223 const char *target
, UINT sflags
, UINT eflags
, ID3DX10ThreadPump
*pump
, ID3D10Blob
**shader
,
224 ID3D10Blob
**error_messages
, HRESULT
*hresult
)
226 TRACE("data %s, data_size %lu, filename %s, defines %p, include %p, entry_point %s, target %s, "
227 "sflags %#x, eflags %#x, pump %p, shader %p, error_messages %p, hresult %p.\n",
228 debugstr_an(data
, data_size
), data_size
, debugstr_a(filename
), defines
, include
,
229 debugstr_a(entry_point
), debugstr_a(target
), sflags
, eflags
, pump
, shader
,
230 error_messages
, hresult
);
233 FIXME("Unimplemented ID3DX10ThreadPump handling.\n");
235 return D3DCompile(data
, data_size
, filename
, defines
, include
, entry_point
, target
,
236 sflags
, eflags
, shader
, error_messages
);
239 HRESULT WINAPI
D3DX10CreateEffectPoolFromFileA(const char *filename
, const D3D10_SHADER_MACRO
*defines
,
240 ID3D10Include
*include
, const char *profile
, UINT hlslflags
, UINT fxflags
, ID3D10Device
*device
,
241 ID3DX10ThreadPump
*pump
, ID3D10EffectPool
**effectpool
, ID3D10Blob
**errors
, HRESULT
*hresult
)
243 FIXME("filename %s, defines %p, include %p, profile %s, hlslflags %#x, fxflags %#x, device %p, "
244 "pump %p, effectpool %p, errors %p, hresult %p, stub!\n",
245 debugstr_a(filename
), defines
, include
, debugstr_a(profile
), hlslflags
, fxflags
, device
,
246 pump
, effectpool
, errors
, hresult
);
251 HRESULT WINAPI
D3DX10CreateEffectPoolFromFileW(const WCHAR
*filename
, const D3D10_SHADER_MACRO
*defines
,
252 ID3D10Include
*include
, const char *profile
, UINT hlslflags
, UINT fxflags
, ID3D10Device
*device
,
253 ID3DX10ThreadPump
*pump
, ID3D10EffectPool
**effectpool
, ID3D10Blob
**errors
, HRESULT
*hresult
)
255 FIXME("filename %s, defines %p, include %p, profile %s, hlslflags %#x, fxflags %#x, device %p, "
256 "pump %p, effectpool %p, errors %p, hresult %p, stub!\n",
257 debugstr_w(filename
), defines
, include
, debugstr_a(profile
), hlslflags
, fxflags
, device
,
258 pump
, effectpool
, errors
, hresult
);
263 HRESULT WINAPI
D3DX10CreateAsyncMemoryLoader(const void *data
, SIZE_T data_size
, ID3DX10DataLoader
**loader
)
265 struct asyncdataloader
*object
;
267 TRACE("data %p, data_size %lu, loader %p.\n", data
, data_size
, loader
);
269 if (!data
|| !loader
)
272 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
274 return E_OUTOFMEMORY
;
276 object
->ID3DX10DataLoader_iface
.lpVtbl
= &memorydataloadervtbl
;
277 object
->data
= (void *)data
;
278 object
->size
= data_size
;
280 *loader
= &object
->ID3DX10DataLoader_iface
;
285 HRESULT WINAPI
D3DX10CreateAsyncFileLoaderA(const char *filename
, ID3DX10DataLoader
**loader
)
291 TRACE("filename %s, loader %p.\n", debugstr_a(filename
), loader
);
293 if (!filename
|| !loader
)
296 len
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
297 filename_w
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(*filename_w
));
298 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filename_w
, len
);
300 hr
= D3DX10CreateAsyncFileLoaderW(filename_w
, loader
);
302 HeapFree(GetProcessHeap(), 0, filename_w
);
307 HRESULT WINAPI
D3DX10CreateAsyncFileLoaderW(const WCHAR
*filename
, ID3DX10DataLoader
**loader
)
309 struct asyncdataloader
*object
;
311 TRACE("filename %s, loader %p.\n", debugstr_w(filename
), loader
);
313 if (!filename
|| !loader
)
316 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
318 return E_OUTOFMEMORY
;
320 object
->ID3DX10DataLoader_iface
.lpVtbl
= &filedataloadervtbl
;
321 object
->u
.file
.path
= HeapAlloc(GetProcessHeap(), 0, (strlenW(filename
) + 1) * sizeof(WCHAR
));
322 if (!object
->u
.file
.path
)
324 HeapFree(GetProcessHeap(), 0, object
);
325 return E_OUTOFMEMORY
;
327 strcpyW(object
->u
.file
.path
, filename
);
331 *loader
= &object
->ID3DX10DataLoader_iface
;
336 HRESULT WINAPI
D3DX10CreateAsyncResourceLoaderA(HMODULE module
, const char *resource
, ID3DX10DataLoader
**loader
)
338 struct asyncdataloader
*object
;
341 TRACE("module %p, resource %s, loader %p.\n", module
, debugstr_a(resource
), loader
);
346 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
348 return E_OUTOFMEMORY
;
350 if (!(rsrc
= FindResourceA(module
, resource
, (const char *)RT_RCDATA
)))
352 WARN("Failed to find resource.\n");
353 HeapFree(GetProcessHeap(), 0, object
);
354 return D3DX10_ERR_INVALID_DATA
;
357 object
->ID3DX10DataLoader_iface
.lpVtbl
= &resourcedataloadervtbl
;
358 object
->u
.resource
.module
= module
;
359 object
->u
.resource
.rsrc
= rsrc
;
363 *loader
= &object
->ID3DX10DataLoader_iface
;
368 HRESULT WINAPI
D3DX10CreateAsyncResourceLoaderW(HMODULE module
, const WCHAR
*resource
, ID3DX10DataLoader
**loader
)
370 struct asyncdataloader
*object
;
373 TRACE("module %p, resource %s, loader %p.\n", module
, debugstr_w(resource
), loader
);
378 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
380 return E_OUTOFMEMORY
;
382 if (!(rsrc
= FindResourceW(module
, resource
, (const WCHAR
*)RT_RCDATA
)))
384 WARN("Failed to find resource.\n");
385 HeapFree(GetProcessHeap(), 0, object
);
386 return D3DX10_ERR_INVALID_DATA
;
389 object
->ID3DX10DataLoader_iface
.lpVtbl
= &resourcedataloadervtbl
;
390 object
->u
.resource
.module
= module
;
391 object
->u
.resource
.rsrc
= rsrc
;
395 *loader
= &object
->ID3DX10DataLoader_iface
;
400 HRESULT WINAPI
D3DX10PreprocessShaderFromMemory(const char *data
, SIZE_T data_size
, const char *filename
,
401 const D3D10_SHADER_MACRO
*defines
, ID3DInclude
*include
, ID3DX10ThreadPump
*pump
, ID3D10Blob
**shader_text
,
402 ID3D10Blob
**errors
, HRESULT
*hresult
)
404 FIXME("data %s, data_size %lu, filename %s, defines %p, include %p, pump %p, shader_text %p, "
405 "errors %p, hresult %p stub!\n",
406 debugstr_an(data
, data_size
), data_size
, debugstr_a(filename
), defines
, include
, pump
,
407 shader_text
, errors
, hresult
);