From: Andrew Eikum aeikum@codeweavers.com
--- dlls/d3dx10_43/compiler.c | 41 +++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-)
diff --git a/dlls/d3dx10_43/compiler.c b/dlls/d3dx10_43/compiler.c index c66eb679a8f..a561cc0357f 100644 --- a/dlls/d3dx10_43/compiler.c +++ b/dlls/d3dx10_43/compiler.c @@ -25,6 +25,7 @@ #include "d3dx10.h" #include "d3dcompiler.h" #include "dxhelpers.h" +#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
@@ -67,7 +68,9 @@ HRESULT WINAPI D3DX10CreateEffectFromFileW(const WCHAR *filename, const D3D10_SH ID3D10Device *device, ID3D10EffectPool *effect_pool, ID3DX10ThreadPump *pump, ID3D10Effect **effect, ID3D10Blob **errors, HRESULT *hresult) { - ID3D10Blob *code; + char filename_a[MAX_PATH], *source = NULL; + DWORD source_size, read_size; + HANDLE file; HRESULT hr;
TRACE("filename %s, defines %p, include %p, profile %s, shader_flags %#x, effect_flags %#x, " @@ -78,20 +81,38 @@ HRESULT WINAPI D3DX10CreateEffectFromFileW(const WCHAR *filename, const D3D10_SH if (pump) FIXME("Asynchronous mode is not supported.\n");
- if (!include) - include = D3D_COMPILE_STANDARD_FILE_INCLUDE; + file = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (file == INVALID_HANDLE_VALUE) + return HRESULT_FROM_WIN32(GetLastError());
- if (FAILED(hr = D3DCompileFromFile(filename, defines, include, "main", profile, shader_flags, - effect_flags, &code, errors))) + source_size = GetFileSize(file, NULL); + if (source_size == INVALID_FILE_SIZE) { - WARN("Effect compilation failed, hr %#lx.\n", hr); - return hr; + hr = HRESULT_FROM_WIN32(GetLastError()); + goto end; }
- hr = D3D10CreateEffectFromMemory(ID3D10Blob_GetBufferPointer(code), ID3D10Blob_GetBufferSize(code), - effect_flags, device, effect_pool, effect); - ID3D10Blob_Release(code); + if (!(source = heap_alloc(source_size))) + { + hr = E_OUTOFMEMORY; + goto end; + } + + if (!ReadFile(file, source, source_size, &read_size, NULL) || read_size != source_size) + { + WARN("Failed to read file contents.\n"); + hr = E_FAIL; + goto end; + } + + WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, sizeof(filename_a), NULL, NULL); + + hr = D3DX10CreateEffectFromMemory(source, source_size, filename_a, defines, include, profile, + shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult);
+end: + heap_free(source); + CloseHandle(file); return hr; }