2 * Copyright 2021 Nikolay Sivov for CodeWeavers
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/debug.h"
21 #include "wine/heap.h"
27 #include "d3dcompiler.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
32 HRESULT WINAPI
D3DX10CreateEffectFromMemory(const void *data
, SIZE_T datasize
, const char *filename
,
33 const D3D10_SHADER_MACRO
*defines
, ID3D10Include
*include
, const char *profile
,
34 UINT shader_flags
, UINT effect_flags
, ID3D10Device
*device
, ID3D10EffectPool
*effect_pool
,
35 ID3DX10ThreadPump
*pump
, ID3D10Effect
**effect
, ID3D10Blob
**errors
, HRESULT
*hresult
)
40 TRACE("data %p, datasize %Iu, filename %s, defines %p, include %p, profile %s, shader_flags %#x,"
41 "effect_flags %#x, device %p, effect_pool %p, pump %p, effect %p, errors %p, hresult %p.\n",
42 data
, datasize
, debugstr_a(filename
), defines
, include
, debugstr_a(profile
),
43 shader_flags
, effect_flags
, device
, effect_pool
, pump
, effect
, errors
, hresult
);
46 FIXME("Asynchronous mode is not supported.\n");
49 include
= D3D_COMPILE_STANDARD_FILE_INCLUDE
;
51 if (FAILED(hr
= D3DCompile(data
, datasize
, filename
, defines
, include
, "main", profile
,
52 shader_flags
, effect_flags
, &code
, errors
)))
54 WARN("Effect compilation failed, hr %#lx.\n", hr
);
58 hr
= D3D10CreateEffectFromMemory(ID3D10Blob_GetBufferPointer(code
), ID3D10Blob_GetBufferSize(code
),
59 effect_flags
, device
, effect_pool
, effect
);
60 ID3D10Blob_Release(code
);
65 HRESULT WINAPI
D3DX10CreateEffectFromFileW(const WCHAR
*filename
, const D3D10_SHADER_MACRO
*defines
,
66 ID3D10Include
*include
, const char *profile
, UINT shader_flags
, UINT effect_flags
,
67 ID3D10Device
*device
, ID3D10EffectPool
*effect_pool
, ID3DX10ThreadPump
*pump
,
68 ID3D10Effect
**effect
, ID3D10Blob
**errors
, HRESULT
*hresult
)
73 TRACE("filename %s, defines %p, include %p, profile %s, shader_flags %#x, effect_flags %#x, "
74 "device %p, effect_pool %p, pump %p, effect %p, errors %p, hresult %p.\n",
75 debugstr_w(filename
), defines
, include
, debugstr_a(profile
), shader_flags
, effect_flags
,
76 device
, effect_pool
, pump
, effect
, errors
, hresult
);
79 FIXME("Asynchronous mode is not supported.\n");
82 include
= D3D_COMPILE_STANDARD_FILE_INCLUDE
;
84 if (FAILED(hr
= D3DCompileFromFile(filename
, defines
, include
, "main", profile
, shader_flags
,
85 effect_flags
, &code
, errors
)))
87 WARN("Effect compilation failed, hr %#lx.\n", hr
);
91 hr
= D3D10CreateEffectFromMemory(ID3D10Blob_GetBufferPointer(code
), ID3D10Blob_GetBufferSize(code
),
92 effect_flags
, device
, effect_pool
, effect
);
93 ID3D10Blob_Release(code
);
98 HRESULT WINAPI
D3DX10CreateEffectFromFileA(const char *filename
, const D3D10_SHADER_MACRO
*defines
,
99 ID3D10Include
*include
, const char *profile
, UINT shader_flags
, UINT effect_flags
,
100 ID3D10Device
*device
, ID3D10EffectPool
*effect_pool
, ID3DX10ThreadPump
*pump
,
101 ID3D10Effect
**effect
, ID3D10Blob
**errors
, HRESULT
*hresult
)
107 TRACE("filename %s, defines %p, include %p, profile %s, shader_flags %#x, effect_flags %#x, "
108 "device %p, effect_pool %p, pump %p, effect %p, errors %p, hresult %p.\n",
109 debugstr_a(filename
), defines
, include
, debugstr_a(profile
), shader_flags
, effect_flags
,
110 device
, effect_pool
, pump
, effect
, errors
, hresult
);
115 len
= MultiByteToWideChar(CP_ACP
, 0, filename
, -1, NULL
, 0);
116 if (!(filenameW
= heap_alloc(len
* sizeof(*filenameW
))))
117 return E_OUTOFMEMORY
;
118 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filenameW
, len
);
120 hr
= D3DX10CreateEffectFromFileW(filenameW
, defines
, include
, profile
, shader_flags
,
121 effect_flags
, device
, effect_pool
, pump
, effect
, errors
, hresult
);
122 heap_free(filenameW
);
127 static HRESULT
get_resource_data(HMODULE module
, HRSRC resinfo
, void **buffer
, DWORD
*length
)
131 *length
= SizeofResource(module
, resinfo
);
133 return D3DX10_ERR_INVALID_DATA
;
135 resource
= LoadResource(module
, resinfo
);
137 return D3DX10_ERR_INVALID_DATA
;
139 *buffer
= LockResource(resource
);
141 return D3DX10_ERR_INVALID_DATA
;
146 HRESULT WINAPI
D3DX10CreateEffectFromResourceA(HMODULE module
, const char *resource_name
,
147 const char *filename
, const D3D10_SHADER_MACRO
*defines
, ID3D10Include
*include
,
148 const char *profile
, UINT shader_flags
, UINT effect_flags
, ID3D10Device
*device
,
149 ID3D10EffectPool
*effect_pool
, ID3DX10ThreadPump
*pump
, ID3D10Effect
**effect
,
150 ID3D10Blob
**errors
, HRESULT
*hresult
)
157 TRACE("module %p, resource_name %s, filename %s, defines %p, include %p, profile %s, "
158 "shader_flags %#x, effect_flags %#x, device %p, effect_pool %p, pump %p, effect %p, "
159 "errors %p, hresult %p.\n", module
, debugstr_a(resource_name
), debugstr_a(filename
),
160 defines
, include
, debugstr_a(profile
), shader_flags
, effect_flags
,
161 device
, effect_pool
, pump
, effect
, errors
, hresult
);
163 if (!(resinfo
= FindResourceA(module
, resource_name
, (const char *)RT_RCDATA
)))
164 return D3DX10_ERR_INVALID_DATA
;
166 if (FAILED(hr
= get_resource_data(module
, resinfo
, &data
, &size
)))
169 return D3DX10CreateEffectFromMemory(data
, size
, filename
, defines
, include
, profile
,
170 shader_flags
, effect_flags
, device
, effect_pool
, pump
, effect
, errors
, hresult
);
173 HRESULT WINAPI
D3DX10CreateEffectFromResourceW(HMODULE module
, const WCHAR
*resource_name
,
174 const WCHAR
*filenameW
, const D3D10_SHADER_MACRO
*defines
, ID3D10Include
*include
,
175 const char *profile
, UINT shader_flags
, UINT effect_flags
, ID3D10Device
*device
,
176 ID3D10EffectPool
*effect_pool
, ID3DX10ThreadPump
*pump
, ID3D10Effect
**effect
,
177 ID3D10Blob
**errors
, HRESULT
*hresult
)
179 char *filename
= NULL
;
186 TRACE("module %p, resource_name %s, filename %s, defines %p, include %p, profile %s, "
187 "shader_flags %#x, effect_flags %#x, device %p, effect_pool %p, pump %p, effect %p, "
188 "errors %p, hresult %p.\n", module
, debugstr_w(resource_name
), debugstr_w(filenameW
),
189 defines
, include
, debugstr_a(profile
), shader_flags
, effect_flags
,
190 device
, effect_pool
, pump
, effect
, errors
, hresult
);
192 if (!(resinfo
= FindResourceW(module
, resource_name
, (const WCHAR
*)RT_RCDATA
)))
193 return D3DX10_ERR_INVALID_DATA
;
195 if (FAILED(hr
= get_resource_data(module
, resinfo
, &data
, &size
)))
200 len
= WideCharToMultiByte(CP_ACP
, 0, filenameW
, -1, NULL
, 0, NULL
, NULL
);
201 if (!(filename
= heap_alloc(len
)))
202 return E_OUTOFMEMORY
;
203 WideCharToMultiByte(CP_ACP
, 0, filenameW
, -1, filename
, len
, NULL
, NULL
);
206 hr
= D3DX10CreateEffectFromMemory(data
, size
, filename
, defines
, include
, profile
,
207 shader_flags
, effect_flags
, device
, effect_pool
, pump
, effect
, errors
, hresult
);