2 * Copyright (C) 2002 Raphael Junqueira
3 * Copyright (C) 2008 David Adam
4 * Copyright (C) 2008 Tony Wasserka
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #ifndef __WINE_D3DX9_PRIVATE_H
23 #define __WINE_D3DX9_PRIVATE_H
26 #include "wine/debug.h"
27 #include "wine/heap.h"
28 #include "wine/rbtree.h"
33 #define ULONG64_MAX (~(ULONG64)0)
47 /* for internal use */
49 FORMAT_ARGB
, /* unsigned */
50 FORMAT_ARGBF16
,/* float 16 */
51 FORMAT_ARGBF
, /* float */
57 struct pixel_format_desc
{
64 UINT block_byte_count
;
65 enum format_type type
;
66 void (*from_rgba
)(const struct vec4
*src
, struct vec4
*dst
);
67 void (*to_rgba
)(const struct vec4
*src
, struct vec4
*dst
, const PALETTEENTRY
*palette
);
70 struct d3dx_include_from_file
72 ID3DXInclude ID3DXInclude_iface
;
75 extern CRITICAL_SECTION from_file_mutex
;
76 extern const struct ID3DXIncludeVtbl d3dx_include_from_file_vtbl
;
78 static inline BOOL
is_conversion_from_supported(const struct pixel_format_desc
*format
)
80 if (format
->type
== FORMAT_ARGB
|| format
->type
== FORMAT_ARGBF16
81 || format
->type
== FORMAT_ARGBF
|| format
->type
== FORMAT_DXT
)
83 return !!format
->to_rgba
;
86 static inline BOOL
is_conversion_to_supported(const struct pixel_format_desc
*format
)
88 if (format
->type
== FORMAT_ARGB
|| format
->type
== FORMAT_ARGBF16
89 || format
->type
== FORMAT_ARGBF
|| format
->type
== FORMAT_DXT
)
91 return !!format
->from_rgba
;
94 HRESULT
map_view_of_file(const WCHAR
*filename
, void **buffer
, DWORD
*length
);
95 HRESULT
load_resource_into_memory(HMODULE module
, HRSRC resinfo
, void **buffer
, DWORD
*length
);
97 HRESULT
write_buffer_to_file(const WCHAR
*filename
, ID3DXBuffer
*buffer
);
99 const struct pixel_format_desc
*get_format_info(D3DFORMAT format
);
100 const struct pixel_format_desc
*get_format_info_idx(int idx
);
102 void format_to_vec4(const struct pixel_format_desc
*format
, const BYTE
*src
, struct vec4
*dst
);
104 void copy_pixels(const BYTE
*src
, UINT src_row_pitch
, UINT src_slice_pitch
,
105 BYTE
*dst
, UINT dst_row_pitch
, UINT dst_slice_pitch
, const struct volume
*size
,
106 const struct pixel_format_desc
*format
);
107 void convert_argb_pixels(const BYTE
*src
, UINT src_row_pitch
, UINT src_slice_pitch
,
108 const struct volume
*src_size
, const struct pixel_format_desc
*src_format
,
109 BYTE
*dst
, UINT dst_row_pitch
, UINT dst_slice_pitch
, const struct volume
*dst_size
,
110 const struct pixel_format_desc
*dst_format
, D3DCOLOR color_key
, const PALETTEENTRY
*palette
);
111 void point_filter_argb_pixels(const BYTE
*src
, UINT src_row_pitch
, UINT src_slice_pitch
,
112 const struct volume
*src_size
, const struct pixel_format_desc
*src_format
,
113 BYTE
*dst
, UINT dst_row_pitch
, UINT dst_slice_pitch
, const struct volume
*dst_size
,
114 const struct pixel_format_desc
*dst_format
, D3DCOLOR color_key
, const PALETTEENTRY
*palette
);
116 HRESULT
load_texture_from_dds(IDirect3DTexture9
*texture
, const void *src_data
, const PALETTEENTRY
*palette
,
117 DWORD filter
, D3DCOLOR color_key
, const D3DXIMAGE_INFO
*src_info
, unsigned int skip_levels
,
118 unsigned int *loaded_miplevels
);
119 HRESULT
load_cube_texture_from_dds(IDirect3DCubeTexture9
*cube_texture
, const void *src_data
,
120 const PALETTEENTRY
*palette
, DWORD filter
, D3DCOLOR color_key
, const D3DXIMAGE_INFO
*src_info
);
121 HRESULT
load_volume_from_dds(IDirect3DVolume9
*dst_volume
, const PALETTEENTRY
*dst_palette
,
122 const D3DBOX
*dst_box
, const void *src_data
, const D3DBOX
*src_box
, DWORD filter
, D3DCOLOR color_key
,
123 const D3DXIMAGE_INFO
*src_info
);
124 HRESULT
load_volume_texture_from_dds(IDirect3DVolumeTexture9
*volume_texture
, const void *src_data
,
125 const PALETTEENTRY
*palette
, DWORD filter
, DWORD color_key
, const D3DXIMAGE_INFO
*src_info
);
126 HRESULT
lock_surface(IDirect3DSurface9
*surface
, const RECT
*surface_rect
, D3DLOCKED_RECT
*lock
,
127 IDirect3DSurface9
**temp_surface
, BOOL write
);
128 HRESULT
unlock_surface(IDirect3DSurface9
*surface
, const RECT
*surface_rect
,
129 IDirect3DSurface9
*temp_surface
, BOOL update
);
131 unsigned short float_32_to_16(const float in
);
132 float float_16_to_32(const unsigned short in
);
135 const char *debug_d3dxparameter_class(D3DXPARAMETER_CLASS c
);
136 const char *debug_d3dxparameter_type(D3DXPARAMETER_TYPE t
);
137 const char *debug_d3dxparameter_registerset(D3DXREGISTER_SET r
);
139 /* parameter type conversion helpers */
140 static inline BOOL
get_bool(D3DXPARAMETER_TYPE type
, const void *data
)
147 return !!*(DWORD
*)data
;
150 return *(BOOL
*)data
;
157 static inline int get_int(D3DXPARAMETER_TYPE type
, const void *data
)
162 return (int)(*(float *)data
);
169 return get_bool(type
, data
);
176 static inline float get_float(D3DXPARAMETER_TYPE type
, const void *data
)
182 return *(float *)data
;
185 return (float)(*(int *)data
);
188 return (float)get_bool(type
, data
);
195 static inline void set_number(void *outdata
, D3DXPARAMETER_TYPE outtype
, const void *indata
, D3DXPARAMETER_TYPE intype
)
197 if (outtype
== intype
)
199 *(DWORD
*)outdata
= *(DWORD
*)indata
;
206 *(float *)outdata
= get_float(intype
, indata
);
210 *(BOOL
*)outdata
= get_bool(intype
, indata
);
214 *(int *)outdata
= get_int(intype
, indata
);
218 *(DWORD
*)outdata
= 0;
223 static inline BOOL
is_param_type_sampler(D3DXPARAMETER_TYPE type
)
225 return type
== D3DXPT_SAMPLER
226 || type
== D3DXPT_SAMPLER1D
|| type
== D3DXPT_SAMPLER2D
227 || type
== D3DXPT_SAMPLER3D
|| type
== D3DXPT_SAMPLERCUBE
;
230 /* Returns the smallest power of 2 which is greater than or equal to num */
231 static inline uint32_t make_pow2(uint32_t num
)
235 return BitScanReverse(&index
, num
- 1) ? 1u << (index
+ 1) : 1;
238 struct d3dx_parameter
;
250 PRES_REGTAB_FIRST_SHADER
= PRES_REGTAB_CONST
,
253 struct d3dx_const_param_eval_output
255 struct d3dx_parameter
*param
;
256 enum pres_reg_tables table
;
257 enum D3DXPARAMETER_CLASS constant_class
;
258 unsigned int register_index
;
259 unsigned int register_count
;
261 unsigned int element_count
;
264 struct d3dx_const_tab
266 unsigned int input_count
;
267 D3DXCONSTANT_DESC
*inputs
;
268 struct d3dx_parameter
**inputs_param
;
269 unsigned int const_set_count
;
270 unsigned int const_set_size
;
271 struct d3dx_const_param_eval_output
*const_set
;
272 const enum pres_reg_tables
*regset2table
;
273 ULONG64 update_version
;
278 void *tables
[PRES_REGTAB_COUNT
];
279 unsigned int table_sizes
[PRES_REGTAB_COUNT
]; /* registers count */
282 struct d3dx_pres_ins
;
284 struct d3dx_preshader
286 struct d3dx_regstore regs
;
288 unsigned int ins_count
;
289 struct d3dx_pres_ins
*ins
;
291 struct d3dx_const_tab inputs
;
294 struct d3dx_param_eval
296 D3DXPARAMETER_TYPE param_type
;
298 struct d3dx_preshader pres
;
299 struct d3dx_const_tab shader_inputs
;
301 ULONG64
*version_counter
;
304 struct param_rb_entry
306 struct wine_rb_entry entry
;
308 struct d3dx_parameter
*param
;
311 struct d3dx_shared_data
;
312 struct d3dx_top_level_parameter
;
314 struct d3dx_parameter
316 char magic_string
[4];
317 struct d3dx_top_level_parameter
*top_level_param
;
318 struct d3dx_param_eval
*param_eval
;
321 D3DXPARAMETER_CLASS
class;
322 D3DXPARAMETER_TYPE type
;
324 unsigned int columns
;
325 unsigned int element_count
;
326 unsigned int member_count
;
329 unsigned int object_id
;
331 struct d3dx_parameter
*members
;
335 struct wine_rb_entry rb_entry
;
338 struct d3dx_top_level_parameter
340 struct d3dx_parameter param
;
341 unsigned int annotation_count
;
342 struct d3dx_parameter
*annotations
;
343 ULONG64 update_version
;
344 ULONG64
*version_counter
;
345 struct d3dx_shared_data
*shared_data
;
348 struct d3dx_shared_data
351 struct d3dx_top_level_parameter
**parameters
;
352 unsigned int size
, count
;
353 ULONG64 update_version
;
358 static inline BOOL
is_top_level_parameter(struct d3dx_parameter
*param
)
360 return ¶m
->top_level_param
->param
== param
;
363 static inline struct d3dx_top_level_parameter
364 *top_level_parameter_from_parameter(struct d3dx_parameter
*param
)
366 return CONTAINING_RECORD(param
, struct d3dx_top_level_parameter
, param
);
369 static inline ULONG64
next_update_version(ULONG64
*version_counter
)
371 return ++*version_counter
;
374 static inline BOOL
is_top_level_param_dirty(struct d3dx_top_level_parameter
*param
, ULONG64 update_version
)
376 struct d3dx_shared_data
*shared_data
;
378 if ((shared_data
= param
->shared_data
))
379 return update_version
< shared_data
->update_version
;
381 return update_version
< param
->update_version
;
384 static inline BOOL
is_param_dirty(struct d3dx_parameter
*param
, ULONG64 update_version
)
386 return is_top_level_param_dirty(param
->top_level_param
, update_version
);
389 struct d3dx_parameters_store
391 struct wine_rb_tree tree
;
392 struct d3dx_top_level_parameter
*parameters
;
396 unsigned int full_name_tmp_size
;
399 HRESULT
d3dx_init_parameters_store(struct d3dx_parameters_store
*store
, unsigned int count
);
400 void d3dx_parameters_store_cleanup(struct d3dx_parameters_store
*store
);
401 struct d3dx_parameter
*get_parameter_by_name(struct d3dx_parameters_store
*store
,
402 struct d3dx_parameter
*parameter
, const char *name
);
404 #define SET_D3D_STATE_(manager, device, method, ...) (manager ? manager->lpVtbl->method(manager, __VA_ARGS__) \
405 : device->lpVtbl->method(device, __VA_ARGS__))
406 #define SET_D3D_STATE(base_effect, ...) SET_D3D_STATE_(base_effect->manager, base_effect->device, __VA_ARGS__)
408 HRESULT
d3dx_create_param_eval(struct d3dx_parameters_store
*parameters
, void *byte_code
,
409 unsigned int byte_code_size
, D3DXPARAMETER_TYPE type
,
410 struct d3dx_param_eval
**peval
, ULONG64
*version_counter
,
411 const char **skip_constants
, unsigned int skip_constants_count
);
412 void d3dx_free_param_eval(struct d3dx_param_eval
*peval
);
413 HRESULT
d3dx_evaluate_parameter(struct d3dx_param_eval
*peval
,
414 const struct d3dx_parameter
*param
, void *param_value
);
415 HRESULT
d3dx_param_eval_set_shader_constants(ID3DXEffectStateManager
*manager
, struct IDirect3DDevice9
*device
,
416 struct d3dx_param_eval
*peval
, BOOL update_all
);
417 BOOL
is_param_eval_input_dirty(struct d3dx_param_eval
*peval
, ULONG64 update_version
);
419 struct ctab_constant
{
420 D3DXCONSTANT_DESC desc
;
421 WORD constantinfo_reserved
;
422 struct ctab_constant
*constants
;
425 const struct ctab_constant
*d3dx_shader_get_ctab_constant(ID3DXConstantTable
*iface
,
426 D3DXHANDLE constant
);
428 #endif /* __WINE_D3DX9_PRIVATE_H */