34#define INT_FLOAT_MULTI 255.0f
35#define INT_FLOAT_MULTI_INVERSE (1/INT_FLOAT_MULTI)
40#define PARAMETER_FLAG_SHARED 1
42#define INITIAL_POOL_SIZE 16
43#define INITIAL_PARAM_BLOCK_SIZE 1024
208#define INITIAL_SHARED_DATA_SIZE 4
447 WARN(
"Skipping %u unknown DWORDs:\n",
count);
451 WARN(
"\t0x%08x\n",
d);
607 if (!
param->element_count)
618 TRACE(
"Free parameter %p, name %s, type %s, element %#x, child %#x.\n",
param,
param->name,
621 if (
param->param_eval)
646 if (
param->annotations)
650 for (
i = 0;
i <
param->annotation_count; ++
i)
667 if (
pass->annotations)
669 for (
i = 0;
i <
pass->annotation_count; ++
i)
677 for (
i = 0;
i <
pass->state_count; ++
i)
691 TRACE(
"Free technique %p\n", technique);
724 return sizeof(*record) +
record->bytes;
749 ID3DXEffectPool *
pool;
765 for (
i = 0;
i <
effect->parameter_count; ++
i)
772 for (
i = 0;
i <
effect->technique_count; ++
i)
779 for (
i = 0;
i <
effect->object_count; ++
i)
791 IUnknown_Release(
effect->manager);
801 for (
i = 0;
i < 4; ++
i)
803 if (i < param->columns)
814 for (
i = 0;
i <
param->columns; ++
i)
822 for (
i = 0;
i < 4; ++
i)
824 for (
k = 0;
k < 4; ++
k)
828 if ((i < param->rows) && (
k <
param->columns))
842 if (
param->columns == 4)
856 for (
k = 0;
k <
param->columns; ++
k)
868 for (
k = 0;
k <
param->columns; ++
k)
882 ERR(
"Out of memory.\n");
885 strcpy(*param_data,
string);
909 if (new_texture == old_texture)
913 IUnknown_AddRef(new_texture);
915 IUnknown_Release(old_texture);
969 TRACE(
"Returning parameter %p\n", temp_parameter);
970 return temp_parameter;
973 FIXME(
"Unhandled case \"%c\"\n", *--part);
978 TRACE(
"Parameter not found\n");
998 temp_parameter = &annotations[
i];
1002 TRACE(
"Returning annotation %p\n", temp_parameter);
1003 return temp_parameter;
1016 FIXME(
"Unhandled case \"%c\"\n", *--part);
1022 TRACE(
"Annotation not found\n");
1030 unsigned int name_len, param_name_len;
1033 unsigned int full_name_size;
1052 full_name_size = name_len + param_name_len + 2;
1057 ERR(
"Out of memory.\n");
1068 full_name[param_name_len] =
'.';
1069 memcpy(full_name + param_name_len + 1,
name, name_len);
1070 full_name[param_name_len + 1 + name_len] = 0;
1086 temp_parameter = ¶meter->
members[
i];
1090 TRACE(
"Returning parameter %p\n", temp_parameter);
1091 return temp_parameter;
1104 FIXME(
"Unhandled case \"%c\"\n", *--part);
1110 TRACE(
"Parameter not found\n");
1116 return (0xfeff0000 | ((
major) << 8) | (
minor));
1121 BOOL update_all,
BOOL *param_dirty)
1125 *param_value =
NULL;
1127 *param_dirty =
FALSE;
1129 switch (
state->type)
1137 *param_value =
param->data;
1141 unsigned int array_idx;
1143 {
"",
NULL,
NULL,
NULL,
NULL,
D3DXPC_SCALAR,
D3DXPT_INT, 1, 1, 0, 0, 0,
sizeof(array_idx)};
1147 if (!
param->param_eval)
1149 FIXME(
"Preshader structure is null.\n");
1161 array_idx =
state->index;
1163 ref_param =
state->referenced_param;
1164 TRACE(
"Array index %u, stored array index %u, element_count %u.\n", array_idx,
state->index,
1168 if (array_idx == ~0
u)
1170 WARN(
"Array index is -1, setting to 0.\n");
1176 WARN(
"Computed array index %u is larger than array size %u.\n",
1180 selected_param = &ref_param->
members[array_idx];
1182 state->index = array_idx;
1184 *param_value = selected_param->
data;
1185 *out_param = selected_param;
1189 if (
param->param_eval)
1192 *param_value =
param->data;
1198 *param_dirty =
TRUE;
1206 FIXME(
"No preshader for FXLC parameter.\n");
1223 return pass->annotation_count;
1248 FIXME(
"Functions are not handled, yet!\n");
1257 unsigned int member_count;
1262 member_count =
param->element_count ?
param->element_count :
param->member_count;
1263 for (
i = 0;
i < member_count; ++
i)
1285 unsigned int new_size, alloc_size;
1291 if (new_size >
block->size)
1303 ERR(
"Out of memory.\n");
1309 block->size = alloc_size;
1310 block->buffer = new_alloc;
1314 block->offset = new_size;
1376 TRACE(
"%s (%.8e %.8e %.8e %.8e).\n", light_tbl[
op].
name,
c.r,
c.g,
c.b,
c.a);
1385 TRACE(
"%s (%.8e %.8e %.8e).\n", light_tbl[
op].
name,
v.x,
v.y,
v.z);
1397 float v = *(
float *)
value;
1403 WARN(
"Unknown light parameter %u.\n",
op);
1428 float v = *(
float *)
value;
1441 TRACE(
"%s, value (%.8e %.8e %.8e %.8e).\n", material_tbl[
op].
name,
c.r,
c.g,
c.b,
c.a);
1446 WARN(
"Unknown material parameter %u.\n",
op);
1471 unsigned int element_count;
1472 void *
buffer = value_ptr;
1477 element_count =
param->bytes / const_tbl[
op].elem_size;
1478 TRACE(
"%s, index %u, element_count %u.\n", const_tbl[
op].
name,
index, element_count);
1479 if (
param->type != const_tbl[
op].type)
1481 FIXME(
"Unexpected param type %u.\n",
param->type);
1485 if (
param->bytes % const_tbl[
op].elem_size || element_count > 1)
1487 unsigned int param_data_size;
1491 if (
param->bytes % const_tbl[
op].elem_size)
1493 if (element_count > 1)
1495 WARN(
"Setting %u elements.\n", element_count);
1499 ERR(
"Out of memory.\n");
1502 is_heap_buffer =
TRUE;
1509 param_data_size =
min(
param->bytes, const_tbl[
op].elem_size);
1512 const_tbl[
op].elem_size * element_count - param_data_size);
1555 unsigned int parameters_count;
1558 if (!
param->param_eval)
1560 FIXME(
"param_eval structure is null.\n");
1564 param->param_eval, update_all)))
1566 params =
param->param_eval->shader_inputs.inputs_param;
1567 cdesc =
param->param_eval->shader_inputs.inputs;
1568 parameters_count =
param->param_eval->shader_inputs.input_count;
1570 for (
i = 0;
i < parameters_count; ++
i)
1575 unsigned int sampler_idx;
1577 for (sampler_idx = 0; sampler_idx < cdesc[
i].
RegisterCount; ++sampler_idx)
1581 cdesc[
i].RegisterIndex,
sampler->state_count);
1606 update_all, ¶m_dirty)))
1613 WARN(
"Returning D3D_OK on out of bounds array access.\n");
1619 if (!(update_all || param_dirty
1638 unit = parent_index == ~0
u ?
state->index : parent_index;
1640 *(IDirect3DBaseTexture9 **)param_value);
1641 return SET_D3D_STATE(effect, SetTexture,
unit, *(IDirect3DBaseTexture9 **)param_value);
1668 sampler = parent_index == ~0
u ?
state->index : parent_index;
1671 *(
DWORD *)param_value);
1674 TRACE(
"%s, shader %p.\n",
state_table[
state->operation].name, *(IDirect3DVertexShader9 **)param_value);
1675 if ((update_all || param_dirty)
1677 *(IDirect3DVertexShader9 **)param_value)))
1678 ERR(
"Could not set vertex shader, hr %#x.\n",
hr);
1679 else if (*(IDirect3DVertexShader9 **)param_value)
1683 TRACE(
"%s, shader %p.\n",
state_table[
state->operation].name, *(IDirect3DPixelShader9 **)param_value);
1684 if ((update_all || param_dirty)
1686 *(IDirect3DPixelShader9 **)param_value)))
1687 ERR(
"Could not set pixel shader, hr %#x.\n",
hr);
1688 else if (*(IDirect3DPixelShader9 **)param_value)
1718 return SET_D3D_STATE(effect, SetNPatchMode, *(
float *)param_value);
1723 param, param_value);
1738 TRACE(
"effect %p, pass %p, state_count %u.\n", effect,
pass,
pass->state_count);
1741 for (
i = 0;
i <
pass->state_count; ++
i)
1745 WARN(
"Error applying state, hr %#x.\n",
hr);
1757 WARN(
"Error setting light, hr %#x.\n",
hr);
1767 WARN(
"Error setting material, hr %#x.\n",
hr);
1772 pass->update_version = new_update_version;
1778 unsigned char *member_data =
data;
1786 member_data +=
param->members[
i].bytes;
1819 unsigned int i, free_entry_index;
1820 unsigned int new_size, new_count;
1825 free_entry_index =
pool->size;
1826 for (
i = 0;
i <
pool->size; ++
i)
1828 if (!
pool->shared_data[
i].count)
1829 free_entry_index =
i;
1833 if (
i ==
pool->size)
1835 i = free_entry_index;
1836 if (
i ==
pool->size)
1844 sizeof(*
pool->shared_data) * new_size);
1847 ERR(
"Out of memory.\n");
1853 new_size =
pool->size * 2;
1855 sizeof(*
pool->shared_data) * new_size);
1858 ERR(
"Out of memory.\n");
1861 if (new_alloc !=
pool->shared_data)
1865 for (
j = 0;
j <
pool->size; ++
j)
1866 for (
k = 0;
k < new_alloc[
j].
count; ++
k)
1870 pool->shared_data = new_alloc;
1871 pool->size = new_size;
1873 pool->shared_data[
i].data =
param->param.data;
1879 new_count = ++
pool->shared_data[
i].count;
1880 if (new_count >=
pool->shared_data[
i].size)
1882 if (!
pool->shared_data[
i].size)
1890 new_size =
pool->shared_data[
i].size * 2;
1892 pool->shared_data[
i].parameters,
1893 sizeof(*
pool->shared_data[
i].parameters) * new_size);
1895 pool->shared_data[
i].size = new_size;
1899 pool->shared_data[
i].parameters[new_count - 1] =
param;
1915 unsigned int new_count;
1919 new_count = --
param->shared_data->count;
1921 TRACE(
"param %p, param->shared_data %p, new_count %d.\n",
param,
param->shared_data, new_count);
1927 for (
i = 0;
i < new_count; ++
i)
1932 &
param->shared_data->parameters[
i + 1],
1933 sizeof(
param->shared_data->parameters[
i]) * (new_count -
i));
1943 param->shared_data->size = 0;
1968 iface->lpVtbl->AddRef(iface);
1992 TRACE(
"%p decreasing refcount to %u.\n", effect, refcount);
2005 FIXME(
"iface %p, desc %p partial stub.\n", iface,
desc);
2009 WARN(
"Invalid argument specified.\n");
2015 desc->Functions = 0;
2028 TRACE(
"iface %p, parameter %p, desc %p.\n", iface, parameter,
desc);
2032 WARN(
"Invalid argument specified.\n");
2045 desc->StructMembers =
param->member_count;
2058 TRACE(
"iface %p, technique %p, desc %p.\n", iface, technique,
desc);
2062 WARN(
"Invalid argument specified.\n");
2083 WARN(
"Invalid argument specified.\n");
2088 desc->Annotations =
pass->annotation_count;
2090 desc->pVertexShaderFunction =
NULL;
2096 for (
i = 0;
i <
pass->state_count; ++
i)
2110 FALSE, ¶m_dirty)))
2115 desc->pVertexShaderFunction =
data;
2137 TRACE(
"iface %p, parameter %p, index %u.\n", iface, parameter,
index);
2141 if (index < effect->parameter_count)
2156 WARN(
"Parameter not found.\n");
2203 TRACE(
"Returning parameter %p\n", temp_param);
2211 TRACE(
"Returning parameter %p\n", temp_param);
2218 for (
i = 0;
i <
param->member_count; ++
i)
2226 TRACE(
"Returning parameter %p\n", temp_param);
2234 TRACE(
"Returning parameter %p\n", temp_param);
2240 WARN(
"Parameter not found.\n");
2250 TRACE(
"iface %p, parameter %p, index %u.\n", iface, parameter,
index);
2254 if (index < effect->parameter_count)
2269 WARN(
"Parameter not found.\n");
2278 TRACE(
"iface %p, index %u.\n", iface,
index);
2282 WARN(
"Invalid argument specified.\n");
2301 TRACE(
"Returning technique %p\n",
t);
2305 WARN(
"Technique not found.\n");
2315 TRACE(
"iface %p, technique %p, index %u.\n", iface, technique,
index);
2323 WARN(
"Pass not found.\n");
2351 WARN(
"Pass not found.\n");
2358 FIXME(
"iface %p, index %u stub.\n", iface,
index);
2374 unsigned int annotation_count;
2376 TRACE(
"iface %p, object %p, index %u.\n", iface,
object,
index);
2380 if (
index < annotation_count)
2382 TRACE(
"Returning parameter %p\n", &annotations[
index]);
2386 WARN(
"Annotation not found.\n");
2397 unsigned int annotation_count;
2403 WARN(
"Invalid argument specified\n");
2416 WARN(
"Annotation not found.\n");
2427 TRACE(
"iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter,
data,
bytes);
2431 WARN(
"Invalid parameter %p specified.\n", parameter);
2436 WARN(
"Parameter is a sampler, returning E_FAIL.\n");
2443 WARN(
"Invalid argument specified.\n");
2453 TRACE(
"iface %p, parameter %p, data %p, bytes %u.\n", iface, parameter,
data,
bytes);
2457 WARN(
"Invalid parameter %p specified.\n", parameter);
2462 WARN(
"Parameter is a sampler, returning E_FAIL.\n");
2470 switch (
param->type)
2489 for (
i = 0;
i < (
param->element_count ?
param->element_count : 1); ++
i)
2493 IUnknown_AddRef(unk);
2508 WARN(
"Parameter not found.\n");
2518 TRACE(
"iface %p, parameter %p, b %#x.\n", iface, parameter,
b);
2527 WARN(
"Parameter not found.\n");
2537 TRACE(
"iface %p, parameter %p, b %p.\n", iface, parameter,
b);
2542 TRACE(
"Returning %s\n", *
b ?
"TRUE" :
"FALSE");
2546 WARN(
"Parameter not found.\n");
2557 TRACE(
"iface %p, parameter %p, b %p, count %u.\n", iface, parameter,
b,
count);
2565 switch (
param->class)
2588 WARN(
"Parameter not found.\n");
2598 TRACE(
"iface %p, parameter %p, b %p, count %u.\n", iface, parameter,
b,
count);
2614 WARN(
"Parameter not found.\n");
2624 TRACE(
"iface %p, parameter %p, n %d.\n", iface, parameter,
n);
2645 TRACE(
"Vector fixup.\n");
2660 WARN(
"Parameter not found.\n");
2670 TRACE(
"iface %p, parameter %p, n %p.\n", iface, parameter,
n);
2677 TRACE(
"Returning %d.\n", *
n);
2685 TRACE(
"Vector fixup.\n");
2693 TRACE(
"Returning %d.\n", *
n);
2698 WARN(
"Parameter not found.\n");
2709 TRACE(
"iface %p, parameter %p, n %p, count %u.\n", iface, parameter,
n,
count);
2717 switch (
param->class)
2737 WARN(
"Parameter not found.\n");
2747 TRACE(
"iface %p, parameter %p, n %p, count %u.\n", iface, parameter,
n,
count);
2761 WARN(
"Parameter not found.\n");
2771 TRACE(
"iface %p, parameter %p, f %.8e.\n", iface, parameter,
f);
2783 WARN(
"Parameter not found.\n");
2793 TRACE(
"iface %p, parameter %p, f %p.\n", iface, parameter,
f);
2798 TRACE(
"Returning %f.\n", *
f);
2802 WARN(
"Parameter not found.\n");
2814 TRACE(
"iface %p, parameter %p, f %p, count %u.\n", iface, parameter,
f,
count);
2822 switch (
param->class)
2842 WARN(
"Parameter not found.\n");
2852 TRACE(
"iface %p, parameter %p, f %p, count %u.\n", iface, parameter,
f,
count);
2866 WARN(
"Parameter not found.\n");
2876 TRACE(
"iface %p, parameter %p, vector %p.\n", iface, parameter,
vector);
2882 switch (
param->class)
2890 TRACE(
"INT fixup.\n");
2920 WARN(
"Parameter not found.\n");
2930 TRACE(
"iface %p, parameter %p, vector %p.\n", iface, parameter,
vector);
2936 switch (
param->class)
2942 TRACE(
"INT fixup.\n");
2963 WARN(
"Parameter not found.\n");
2974 TRACE(
"iface %p, parameter %p, vector %p, count %u.\n", iface, parameter,
vector,
count);
2983 switch (
param->class)
2990 if (
param->columns == 4)
2998 param->columns *
sizeof(
float));
3020 WARN(
"Parameter not found.\n");
3031 TRACE(
"iface %p, parameter %p, vector %p, count %u.\n", iface, parameter,
vector,
count);
3042 switch (
param->class)
3061 WARN(
"Parameter not found.\n");
3071 TRACE(
"iface %p, parameter %p, matrix %p.\n", iface, parameter,
matrix);
3077 switch (
param->class)
3096 WARN(
"Parameter not found.\n");
3106 TRACE(
"iface %p, parameter %p, matrix %p.\n", iface, parameter,
matrix);
3112 switch (
param->class)
3130 WARN(
"Parameter not found.\n");
3141 TRACE(
"iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter,
matrix,
count);
3150 switch (
param->class)
3154 *
param->columns *
sizeof(
float),
TRUE);
3174 WARN(
"Parameter not found.\n");
3185 TRACE(
"iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter,
matrix,
count);
3196 switch (
param->class)
3215 WARN(
"Parameter not found.\n");
3226 TRACE(
"iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter,
matrix,
count);
3233 switch (
param->class)
3237 *
param->columns *
sizeof(
float),
TRUE);
3241 *
param->columns *
sizeof(
float));
3256 WARN(
"Parameter not found.\n");
3267 TRACE(
"iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter,
matrix,
count);
3278 switch (
param->class)
3296 WARN(
"Parameter not found.\n");
3307 TRACE(
"iface %p, parameter %p, matrix %p.\n", iface, parameter,
matrix);
3313 switch (
param->class)
3332 WARN(
"Parameter not found.\n");
3343 TRACE(
"iface %p, parameter %p, matrix %p.\n", iface, parameter,
matrix);
3349 switch (
param->class)
3370 WARN(
"Parameter not found.\n");
3381 TRACE(
"iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter,
matrix,
count);
3390 switch (
param->class)
3394 *
param->columns *
sizeof(
float),
TRUE);
3398 +
i *
param->rows *
param->columns *
sizeof(
float));
3414 WARN(
"Parameter not found.\n");
3425 TRACE(
"iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter,
matrix,
count);
3436 switch (
param->class)
3455 WARN(
"Parameter not found.\n");
3466 TRACE(
"iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter,
matrix,
count);
3473 switch (
param->class)
3477 *
param->columns *
sizeof(
float),
TRUE);
3481 +
i *
param->rows *
param->columns *
sizeof(
float));
3496 WARN(
"Parameter not found.\n");
3507 TRACE(
"iface %p, parameter %p, matrix %p, count %u.\n", iface, parameter,
matrix,
count);
3518 switch (
param->class)
3536 WARN(
"Parameter not found.\n");
3546 TRACE(
"iface %p, parameter %p, string %s.\n", iface, parameter,
debugstr_a(
string));
3551 WARN(
"Parameter not found.\n");
3561 TRACE(
"iface %p, parameter %p, string %p.\n", iface, parameter,
string);